utils

package
v2.11.0 Latest Latest
Warning

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

Go to latest
Published: Sep 13, 2022 License: GPL-3.0 Imports: 21 Imported by: 2

Documentation

Index

Constants

View Source
const (
	ErrorHeader      = "X-MP-ERROR"
	ErrorsHeader     = "X-MP-ERRORS"
	ExpectFileHeader = "X-EXPECT-FILE"

	// ===== ERRORS =====
	ServiceError    = "Service is not available now, please try later"
	ValidationError = "Validation errors"
	Required        = "Required"

	// ===== DATE =====
	FullDateFormat = "2006-01-02T15:04:05.999-07:00"

	// ===== GRPC =====
	ProxyMethodNameHeader = "proxy_method_name"
	MethodDefaultGroup    = "api"

	ApplicationIdHeader = "x-application-identity"
	UserIdHeader        = "x-user-identity"
	DeviceIdHeader      = "x-device-identity"
	ServiceIdHeader     = "x-service-identity"
	DomainIdHeader      = "x-domain-identity"
	SystemIdHeader      = "x-system-identity"
	InstanceIdHeader    = "x-instance-identity"

	ApplicationTokenHeader = "X-APPLICATION-TOKEN"
	UserTokenHeader        = "X-USER-TOKEN"
	DeviceTokenHeader      = "X-DEVICE-TOKEN"

	HeaderNotSpecifiedValue = "not_specified"
)
View Source
const (
	ErrorConnection = "ERROR_CONNECTION"
	ConfigError     = "ERROR_CONFIG"

	ConfigSendConfigWhenConnected = "CONFIG:SEND_CONFIG_WHEN_CONNECTED"
	ConfigSendConfigChanged       = "CONFIG:SEND_CONFIG_CHANGED"
	ConfigSendConfigOnRequest     = "CONFIG:SEND_CONFIG_ON_REQUEST"

	ConfigSendRoutesWhenConnected = "CONFIG:SEND_ROUTES_WHEN_CONNECTED"
	ConfigSendRoutesChanged       = "CONFIG:SEND_ROUTES_CHANGED"
	ConfigSendRoutesOnRequest     = "CONFIG:SEND_ROUTES_ON_REQUEST"
	ConfigLogRotation             = "CONFIG:LOG_ROTATION"
	ConfigRestart                 = "CONFIG:MODULE_RESTART"

	ModuleReady            = "MODULE:READY"
	ModuleSendRequirements = "MODULE:SEND_REQUIREMENTS"
	ModuleUpdateRoutes     = "MODULE:UPDATE_ROUTES"
	ModuleSendConfigSchema = "MODULE:SEND_CONFIG_SCHEMA"

	ModuleConnectionSuffix = "MODULE_CONNECTED"

	ModuleNameGetParamKey = "module_name"
	// Deprecated: no longer used.
	InstanceUuidGetParamKey = "instance_uuid"
	WsOkResponse            = "ok"
)

Variables

View Source
var (
	// ===== ENV =====
	EnvProfileName   = os.Getenv("APP_PROFILE")
	EnvConfigPath    = os.Getenv("APP_CONFIG_PATH")
	EnvMigrationPath = os.Getenv("APP_MIGRATION_PATH")
	DEV              = strings.ToLower(os.Getenv("APP_MODE")) == "dev"
	LOG_LEVEL        = os.Getenv("LOG_LEVEL")
)
View Source
var (
	UserTokenHeaderLC = strings.ToLower(UserTokenHeader)
)

Functions

func ConvertBytesToGo

func ConvertBytesToGo(b []byte, ptr interface{}) error

func ConvertGoToBytes

func ConvertGoToBytes(data interface{}) ([]byte, error)

func ConvertGrpcStructToInterface

func ConvertGrpcStructToInterface(data *structpb.Value) interface{}

func ConvertGrpcStructToMap

func ConvertGrpcStructToMap(data map[string]*structpb.Value) map[string]interface{}

func ConvertGrpcToGo

func ConvertGrpcToGo(data *structpb.Value, ptr interface{}) error

func ConvertInterfaceToGrpcStruct

func ConvertInterfaceToGrpcStruct(data interface{}) *structpb.Value

func ConvertMapMapToGrpcStruct

func ConvertMapMapToGrpcStruct(data map[string]map[string]int) *structpb.Struct

func ConvertMapToGrpcStruct

func ConvertMapToGrpcStruct(data map[string]interface{}) *structpb.Struct

func CreateValidationErrorDetails

func CreateValidationErrorDetails(errorCode codes.Code, errorMessage string, errors map[string]string) error

func CreateValidationErrorDetailsV2

func CreateValidationErrorDetailsV2(errorCode codes.Code, errorMessage string, detailsPairs ...string) error

func GetFieldName

func GetFieldName(fieldType reflect.StructField) (string, bool)

func IsValidUUID deprecated

func IsValidUUID(uuid string) bool

Deprecated: can validate only v1, v4. Use external lib for correct validation.

func ModuleConnected

func ModuleConnected(moduleName string) string

func ParseParameters

func ParseParameters(queryRaw string) (instanceUUID string, moduleName string, error error)

ParseParameters always return empty instanceUUID as it was deprecated.

func ResolveMetadataIdentity

func ResolveMetadataIdentity(key string, md metadata.MD) (int, error)

func ResolveMetadataIdentityV2

func ResolveMetadataIdentityV2(key string, md metadata.MD) (string, error)

func Validate

func Validate(value interface{}) error

func ValidateV2

func ValidateV2(value interface{}) error

func WrapError

func WrapError(err error) error

Types

type GrpcValueMarshaler

type GrpcValueMarshaler interface {
	ToGrpcValue() *structpb.Value
}

type GrpcValueUnmarshaler

type GrpcValueUnmarshaler interface {
	FromGrpcValue(*structpb.Value) (bool, error)
}

Jump to

Keyboard shortcuts

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