utils

package
v2.1.0+incompatible Latest Latest
Warning

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

Go to latest
Published: Jan 16, 2020 License: GPL-3.0 Imports: 25 Imported by: 17

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"

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

	ModuleConnectionSuffix = "MODULE_CONNECTED"

	ModuleNameGetParamKey   = "module_name"
	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 added in v1.3.0

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

func IsValidUUID(uuid string) bool

func ModuleConnected

func ModuleConnected(moduleName string) string

func NewBufferInjector

func NewBufferInjector() *bufInjector

func ParseParameters

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

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 added in v1.1.4

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