1package request 2 3import ( 4 "context" 5 6 "github.com/navidrome/navidrome/model" 7) 8 9type contextKey string 10 11const ( 12 User = contextKey("user") 13 Username = contextKey("username") 14 Client = contextKey("client") 15 Version = contextKey("version") 16 Player = contextKey("player") 17 Transcoding = contextKey("transcoding") 18) 19 20func WithUser(ctx context.Context, u model.User) context.Context { 21 return context.WithValue(ctx, User, u) 22} 23 24func WithUsername(ctx context.Context, username string) context.Context { 25 return context.WithValue(ctx, Username, username) 26} 27 28func WithClient(ctx context.Context, client string) context.Context { 29 return context.WithValue(ctx, Client, client) 30} 31 32func WithVersion(ctx context.Context, version string) context.Context { 33 return context.WithValue(ctx, Version, version) 34} 35 36func WithPlayer(ctx context.Context, player model.Player) context.Context { 37 return context.WithValue(ctx, Player, player) 38} 39 40func WithTranscoding(ctx context.Context, t model.Transcoding) context.Context { 41 return context.WithValue(ctx, Transcoding, t) 42} 43 44func UserFrom(ctx context.Context) (model.User, bool) { 45 v, ok := ctx.Value(User).(model.User) 46 return v, ok 47} 48 49func UsernameFrom(ctx context.Context) (string, bool) { 50 v, ok := ctx.Value(Username).(string) 51 return v, ok 52} 53 54func ClientFrom(ctx context.Context) (string, bool) { 55 v, ok := ctx.Value(Client).(string) 56 return v, ok 57} 58 59func VersionFrom(ctx context.Context) (string, bool) { 60 v, ok := ctx.Value(Version).(string) 61 return v, ok 62} 63 64func PlayerFrom(ctx context.Context) (model.Player, bool) { 65 v, ok := ctx.Value(Player).(model.Player) 66 return v, ok 67} 68 69func TranscodingFrom(ctx context.Context) (model.Transcoding, bool) { 70 v, ok := ctx.Value(Transcoding).(model.Transcoding) 71 return v, ok 72} 73