Documentation
¶
Index ¶
- Constants
- func ClientContextInterceptor() grpc.UnaryClientInterceptor
- func Coalesce[T comparable](value, def T) T
- func EncodeUserContext(userCtx *UserContext) (string, error)
- func GetBool(key string, defaultValue bool) bool
- func GetFloat64(key string, defaultValue float64) float64
- func GetInt(key string, defaultValue int) int
- func GetInt64(key string, defaultValue int64) int64
- func GetString(key, defaultValue string) string
- func GrpcDialCredentials(ctx context.Context, host string, opts ...grpc.DialOption) (*grpc.ClientConn, error)
- func GzipCompressData(data []byte) ([]byte, error)
- func GzipDecompressData(compressedData []byte) ([]byte, error)
- func ServerContextInterceptor(requireAuth bool) grpc.UnaryServerInterceptor
- func WithUserContext(ctx context.Context, userCtx *UserContext) context.Context
- type RedisExtend
- type UserContext
Constants ¶
const UserContextKey = "user-context"
Variables ¶
This section is empty.
Functions ¶
func ClientContextInterceptor ¶
func ClientContextInterceptor() grpc.UnaryClientInterceptor
func Coalesce ¶
func Coalesce[T comparable](value, def T) T
Coalesce returns the first non-zero parameter value, and if the value is zero, it returns the default value def. Suitable for various comparable types such as int, string, boolean, struct, etc. When value==zero of def, it will trigger the return of def.
func EncodeUserContext ¶
func EncodeUserContext(userCtx *UserContext) (string, error)
func GetBool ¶
GetBool returns the env variable (parsed as bool) for the given key and falls back to the given defaultValue if not set
func GetFloat64 ¶
GetFloat64 returns the env variable (parsed as float64) for the given key and falls back to the given defaultValue if not set
func GetInt ¶
GetInt returns the env variable (parsed as integer) for the given key and falls back to the given defaultValue if not set
func GetInt64 ¶
GetInt64 returns the env variable (parsed as integer) for the given key and falls back to the given defaultValue if not set
func GetString ¶
GetString returns the env variable for the given key and falls back to the given defaultValue if not set
func GrpcDialCredentials ¶
func GrpcDialCredentials(ctx context.Context, host string, opts ...grpc.DialOption) (*grpc.ClientConn, error)
func GzipDecompressData ¶
GzipDecompressData unzip
func ServerContextInterceptor ¶
func ServerContextInterceptor(requireAuth bool) grpc.UnaryServerInterceptor
func WithUserContext ¶
func WithUserContext(ctx context.Context, userCtx *UserContext) context.Context
Types ¶
type RedisExtend ¶
type RedisExtend struct {
redis.UniversalClient
}
func (RedisExtend) IncByExpire ¶
type UserContext ¶
type UserContext struct { UserId string `json:"userId"` TeamId string `json:"teamId"` AccessToken string `json:"accessToken"` }
func DecodeUserContext ¶
func DecodeUserContext(encodedValue string) (*UserContext, error)
func ExtractFromIncoming ¶
func ExtractFromIncoming(md metadata.MD) (*UserContext, bool)
func FromContext ¶
func FromContext(ctx context.Context) (*UserContext, error)
func (*UserContext) GetTeamId ¶
func (userCtx *UserContext) GetTeamId() string
func (*UserContext) GetUserId ¶
func (userCtx *UserContext) GetUserId() string