helper

package
v1.1.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 8, 2025 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
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

func GetBool(key string, defaultValue bool) bool

GetBool returns the env variable (parsed as bool) for the given key and falls back to the given defaultValue if not set

func GetFloat64

func GetFloat64(key string, defaultValue float64) float64

GetFloat64 returns the env variable (parsed as float64) for the given key and falls back to the given defaultValue if not set

func GetInt

func GetInt(key string, defaultValue int) int

GetInt returns the env variable (parsed as integer) for the given key and falls back to the given defaultValue if not set

func GetInt64

func GetInt64(key string, defaultValue int64) int64

GetInt64 returns the env variable (parsed as integer) for the given key and falls back to the given defaultValue if not set

func GetString

func GetString(key, defaultValue string) string

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 GzipCompressData

func GzipCompressData(data []byte) ([]byte, error)

CompressData zpi

func GzipDecompressData

func GzipDecompressData(compressedData []byte) ([]byte, error)

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) GetDel

func (r RedisExtend) GetDel(ctx context.Context, key string) *redis.Cmd

func (RedisExtend) IncByExpire

func (r RedisExtend) IncByExpire(ctx context.Context, key string, value int, expire time.Duration) *redis.Cmd

func (RedisExtend) LPopCount

func (r RedisExtend) LPopCount(ctx context.Context, key string, count int) *redis.Cmd

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

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL