Add authentication server, dev CLI, Docker multi-service setup, and cross-platform improvements

This commit is contained in:
Ilya Groshev
2026-04-21 16:49:44 +03:00
parent 43d6527b42
commit a3fbb1aeba
121 changed files with 4523 additions and 2888 deletions
+77
View File
@@ -0,0 +1,77 @@
package model
import (
"context"
"strconv"
"google.golang.org/grpc/metadata"
)
type ClientPlatform struct {
OsType int32 // 1=iOS, 2=Android
PlatformType int32 // 1=AppStore, 2=GooglePlay, 8=Amazon
}
const (
OsTypeIOS int32 = 1
OsTypeAndroid int32 = 2
PlatformTypeAppStore int32 = 1
PlatformTypeGooglePlayStore int32 = 2
PlatformTypeAmazonAppStore int32 = 8
)
var DefaultPlatform = ClientPlatform{OsType: OsTypeAndroid, PlatformType: PlatformTypeGooglePlayStore}
type platformKey struct{}
func (p ClientPlatform) String() string {
os := "unknown"
switch p.OsType {
case OsTypeIOS:
os = "iOS"
case OsTypeAndroid:
os = "Android"
}
plat := "unknown"
switch p.PlatformType {
case PlatformTypeAppStore:
plat = "AppStore"
case PlatformTypeGooglePlayStore:
plat = "GooglePlay"
case PlatformTypeAmazonAppStore:
plat = "Amazon"
}
return os + "/" + plat
}
func ClientPlatformFromHeaders(ctx context.Context) ClientPlatform {
md, ok := metadata.FromIncomingContext(ctx)
if !ok {
return DefaultPlatform
}
p := DefaultPlatform
if vals := md.Get("x-apb-os-type"); len(vals) > 0 {
if v, err := strconv.ParseInt(vals[0], 10, 32); err == nil {
p.OsType = int32(v)
}
}
if vals := md.Get("x-apb-platform-type"); len(vals) > 0 {
if v, err := strconv.ParseInt(vals[0], 10, 32); err == nil {
p.PlatformType = int32(v)
}
}
return p
}
func NewContextWithPlatform(ctx context.Context, p ClientPlatform) context.Context {
return context.WithValue(ctx, platformKey{}, p)
}
func ClientPlatformFromContext(ctx context.Context) ClientPlatform {
if p, ok := ctx.Value(platformKey{}).(ClientPlatform); ok {
return p
}
return DefaultPlatform
}