mrcore

package
v0.4.2 Latest Latest
Warning

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

Go to latest
Published: Sep 12, 2023 License: Apache-2.0 Imports: 13 Imported by: 40

Documentation

Index

Constants

View Source
const (
	PlatformMobile = "MOBILE"
	PlatformWeb    = "WEB"
)

Variables

View Source
var (
	FactoryErrInternal = NewFactory(
		ErrorIdInternal, ErrorKindInternal, "internal server error")

	FactoryErrInternalNilPointer = NewFactory(
		"errInternalNilPointer", ErrorKindInternal, "nil pointer")

	FactoryErrInternalTypeAssertion = NewFactory(
		"errInternalTypeAssertion", ErrorKindInternal, "invalid type '{{ .type }}' assertion (value: {{ .value }})")

	FactoryErrInternalInvalidType = NewFactory(
		"errInternalInvalidType", ErrorKindInternal, "invalid type '{{ .type1 }}', expected: '{{ .type2 }}'")

	FactoryErrInternalInvalidData = NewFactory(
		"errInternalInvalidData", ErrorKindInternal, "invalid data '{{ .value }}'")

	FactoryErrInternalParseData = NewFactory(
		"errInternalParseData", ErrorKindInternal, "data '{{ .name1 }}' parsed to {{ .name2 }} with error")

	FactoryErrInternalFailedToClose = NewFactory(
		"errInternalFailedToClose", ErrorKindInternal, "failed to close '{{ .name }}'")

	FactoryErrInternalMapValueNotFound = NewFactory(
		"errInternalMapValueNotFound", ErrorKindInternal, "'{{ .value }}' is not found in map {{ .name }}")

	FactoryErrInternalNoticeDataContainer = NewFactory(
		"errInternalNoticeDataContainer", ErrorKindInternalNotice, "data: '{{ .value }}'")
)
View Source
var (
	FactoryErrHttpRequestParamLen = NewFactory(
		"errHttpRequestParamLen", ErrorKindUser, "request param with key '{{ .key }}' has value length greater then max '{{ .maxLength }}'")

	FactoryErrHttpRequestParseParam = NewFactory(
		"errHttpRequestParseParam", ErrorKindUser, "request param of type '{{ .type }}' with key '{{ .key }}' contains incorrect value '{{ .value }}'")
)
View Source
var (
	FactoryErrIncorrectInputData = NewFactory(
		"errServiceIncorrectData", ErrorKindInternal, "data '{{ .data }}' is incorrect")

	FactoryErrEntityTemporarilyUnavailable = NewFactory(
		"errServiceEntityTemporarilyUnavailable", ErrorKindSystem, "entity '{{ .name }}' is temporarily unavailable")

	FactoryErrEntityNotFound = NewFactory(
		"errServiceEntityNotFound", ErrorKindInternalNotice, "entity '{{ .name }}' is not found")

	FactoryErrEntityNotCreated = NewFactory(
		"errServiceEntityNotCreated", ErrorKindSystem, "entity '{{ .name }}' is not created")

	FactoryErrEntityNotUpdated = NewFactory(
		"errServiceEntityNotUpdated", ErrorKindSystem, "entity '{{ .name }}' is not updated")

	FactoryErrEntityNotRemoved = NewFactory(
		"errServiceEntityNotRemoved", ErrorKindSystem, "entity '{{ .name }}' is not removed")

	FactoryErrIncorrectSwitchStatus = NewFactory(
		"errServiceIncorrectSwitchStatus", ErrorKindInternal, "incorrect switch status: '{{ .currentStatus }}' -> '{{ .statusTo }}' for entity '{{ .name }}(ID={{ .id }})'")
)
View Source
var (
	FactoryErrConnectionIsAlreadyCreated = NewFactory(
		"errStorageConnectionIsAlreadyCreated", ErrorKindInternal, "connection '{{ .name }}' is already created")

	FactoryErrConnectionIsNotOpened = NewFactory(
		"errStorageConnectionIsNotOpened", ErrorKindInternal, "connection '{{ .name }}' is not opened")

	FactoryErrConnectionFailed = NewFactory(
		"errStorageConnectionFailed", ErrorKindSystem, "connection '{{ .name }}' is failed")

	FactoryErrQueryFailed = NewFactory(
		"errStorageQueryFailed", ErrorKindInternal, "query is failed")

	FactoryErrFetchDataFailed = NewFactory(
		"errStorageFetchDataFailed", ErrorKindInternal, "fetching data is failed")

	FactoryErrFetchedInvalidData = NewFactory(
		"errStorageFetchedInvalidData", ErrorKindInternal, "fetched data '{{ .value }}' is invalid")

	FactoryErrNoRowFound = NewFactory(
		"errStorageNoRowFound", ErrorKindInternalNotice, "no row found")

	FactoryErrRowsNotAffected = NewFactory(
		"errStorageRowsNotAffected", ErrorKindInternalNotice, "rows not affected")
)

Functions

func LogErr added in v0.4.0

func LogErr(e error)

func LogError

func LogError(message string, args ...any)

func SetDefaultLogger

func SetDefaultLogger(logger Logger)

SetDefaultLogger - WARNING!!! only for main process

Types

type AppHelper

type AppHelper struct {
	// contains filtered or unexported fields
}

func NewAppHelper

func NewAppHelper(logger Logger) *AppHelper

func (*AppHelper) Close

func (h *AppHelper) Close(c io.Closer)

func (*AppHelper) ExitOnError

func (h *AppHelper) ExitOnError(err error)

func (*AppHelper) GracefulShutdown

func (h *AppHelper) GracefulShutdown(cancel context.CancelFunc)

type ClientData

type ClientData interface {
	Request() *http.Request
	Context() context.Context
	WithContext(ctx context.Context) ClientData
	RequestPath() RequestPath
	Writer() http.ResponseWriter

	Parse(structRequest any) error
	Validate(structRequest any) error
	ParseAndValidate(structRequest any) error

	SendResponse(status int, structResponse any) error
	SendResponseNoContent() error
}

type EventBox

type EventBox interface {
	Emit(message string, args ...any)
}

type HttpController

type HttpController interface {
	AddHandlers(router HttpRouter)
}

type HttpHandlerAdapterFunc

type HttpHandlerAdapterFunc func(next HttpHandlerFunc) http.HandlerFunc

type HttpHandlerFunc

type HttpHandlerFunc func(c ClientData) error

type HttpMiddleware

type HttpMiddleware interface {
	Middleware(next http.Handler) http.Handler
}

type HttpMiddlewareFunc

type HttpMiddlewareFunc func(next http.Handler) http.Handler

func (HttpMiddlewareFunc) Middleware

func (f HttpMiddlewareFunc) Middleware(next http.Handler) http.Handler

type HttpRouter

type HttpRouter interface {
	RegisterMiddleware(handlers ...HttpMiddleware)
	Register(controllers ...HttpController)
	HandlerFunc(method, path string, handler http.HandlerFunc)
	HttpHandlerFunc(method, path string, handler HttpHandlerFunc)
	ServeHTTP(w http.ResponseWriter, r *http.Request)
}

type LogLevel

type LogLevel uint32
const (
	LogErrorLevel LogLevel = iota
	LogWarnLevel
	LogInfoLevel
	LogDebugLevel
)

func ParseLogLevel

func ParseLogLevel(level string) (LogLevel, error)

type Logger

type Logger interface {
	With(name string) Logger
	Error(message string, args ...any)
	Err(err error)
	Warn(message string, args ...any)
	Info(message string, args ...any)
	Debug(message string, args ...any)
}

func DefaultLogger

func DefaultLogger() Logger

func NewLogger

func NewLogger(prefix string, level string) (Logger, error)

type RequestPath

type RequestPath interface {
	Get(name string) string
	GetInt(name string) int64
}

type ServiceHelper

type ServiceHelper struct{}

func NewServiceHelper

func NewServiceHelper() *ServiceHelper

func (*ServiceHelper) ReturnErrorIfItemNotFound

func (h *ServiceHelper) ReturnErrorIfItemNotFound(err error, entityName string) error

func (*ServiceHelper) WrapErrorForRemove

func (h *ServiceHelper) WrapErrorForRemove(err error, entityName string) error

func (*ServiceHelper) WrapErrorForSelect

func (h *ServiceHelper) WrapErrorForSelect(err error, entityName string) error

func (*ServiceHelper) WrapErrorForUpdate

func (h *ServiceHelper) WrapErrorForUpdate(err error, entityName string) error

type Validator

type Validator interface {
	Register(tagName string, fn ValidatorTagNameFunc) error
	Validate(ctx context.Context, structure any) error
}

type ValidatorTagNameFunc

type ValidatorTagNameFunc func(value string) bool

Jump to

Keyboard shortcuts

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