Clean public release with: - Go/Gin/PostgreSQL/Redis architecture - Multi-tenant support - JWT authentication - Docker Compose deployment - Environment-based configuration
22 lines
444 B
Go
22 lines
444 B
Go
package tenant
|
|
|
|
import "context"
|
|
|
|
type ctxKey string
|
|
|
|
const tenantIDKey ctxKey = "tenant_id"
|
|
|
|
func WithTenantID(ctx context.Context, tenantID string) context.Context {
|
|
return context.WithValue(ctx, tenantIDKey, tenantID)
|
|
}
|
|
|
|
func FromContext(ctx context.Context) (string, bool) {
|
|
id, ok := ctx.Value(tenantIDKey).(string)
|
|
return id, ok && id != ""
|
|
}
|
|
|
|
func MustFromContext(ctx context.Context) string {
|
|
id, _ := FromContext(ctx)
|
|
return id
|
|
}
|