feat: build vehicle data platform and production pipeline
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
package platform
|
||||
|
||||
import "context"
|
||||
|
||||
type Principal struct {
|
||||
Name string `json:"name"`
|
||||
Role string `json:"role"`
|
||||
}
|
||||
|
||||
type principalContextKey struct{}
|
||||
|
||||
func WithPrincipal(ctx context.Context, principal Principal) context.Context {
|
||||
return context.WithValue(ctx, principalContextKey{}, principal)
|
||||
}
|
||||
|
||||
func PrincipalFromContext(ctx context.Context) (Principal, bool) {
|
||||
principal, ok := ctx.Value(principalContextKey{}).(Principal)
|
||||
return principal, ok
|
||||
}
|
||||
|
||||
func ActorFromContext(ctx context.Context) string {
|
||||
if principal, ok := PrincipalFromContext(ctx); ok && principal.Name != "" {
|
||||
return principal.Name
|
||||
}
|
||||
return "system"
|
||||
}
|
||||
Reference in New Issue
Block a user