add client ID for plugin service

This commit is contained in:
ginuerzh
2023-09-19 22:31:37 +08:00
parent 95da26cf49
commit 674a70cd23
26 changed files with 306 additions and 320 deletions

22
internal/util/auth/key.go Normal file
View File

@ -0,0 +1,22 @@
package auth
import (
"context"
)
type idKey struct{}
type ID string
var (
clientIDKey = &idKey{}
)
func ContextWithID(ctx context.Context, id ID) context.Context {
return context.WithValue(ctx, clientIDKey, id)
}
func IDFromContext(ctx context.Context) ID {
v, _ := ctx.Value(clientIDKey).(ID)
return v
}