application

package
v0.0.24 Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2020 License: MIT Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DecodeGRPCRuntimeKey

func DecodeGRPCRuntimeKey(ctx context.Context, runtimeKey []truntime.RuntimeKey) map[string]string

DecodeGRPCRuntimeKey decode runtime key from ctx

func DecodeHTTPRuntimeKey

func DecodeHTTPRuntimeKey(c *gin.Context, runtimeKey []truntime.RuntimeKey) map[string]string

DecodeHTTPRuntimeKey decode http runtime

func DiAllFields

func DiAllFields(dest interface{}, tctx Context, app Application, c *gin.Context) map[reflect.Type]interface{}

DiAllFields di service pool

func DiFree

func DiFree(dest interface{})

DiFree di controller

func DiSelfCheck added in v0.0.22

func DiSelfCheck(destName interface{}, pool *sync.Pool, app Application)

DiSelfCheck ()map[reflect.Type]interface{} {}

func GetAutowiredTags added in v0.0.22

func GetAutowiredTags(object interface{}, index int) bool

GetAutowiredTags get autowired tags from struct

func GetResourceTags added in v0.0.22

func GetResourceTags(object interface{}, index int) string

GetResourceTags get resource tags

func TransactionTag added in v0.0.22

func TransactionTag(object interface{}, index int) bool

TransactionTag get the transaction tag from struct

Types

type Application

type Application interface {
	IsLogSelfCheck() bool
	Logger() *golog.Logger
	RuntimeKeys() []truntime.RuntimeKey
	Conf() conf.Conf
	ContextPool() *ContextPool
	DB() *gorm.DB
	InstallDB(f func() *gorm.DB)
	ControllerPool() *ControllerPool
	ContainerPool() *ContainerPool
	UseInterceptor(interceptor ...grpc.UnaryServerInterceptor) Application
	UseMiddleware(middleware ...gin.HandlerFunc) Application
	RegRuntimeKey(runtime ...truntime.RuntimeKey) Application
	InitGRPC()
	InitHTTP()
	InitRouter()
	GetGRPCServer() *grpc.Server
	ServeGRPC()
	ServeHTTP()
}

Application global app interface

type ContainerPool

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

ContainerPool service pool

func NewContainerPool

func NewContainerPool() *ContainerPool

NewContainerPool new pool with init map

func (*ContainerPool) CheckContainerNameIfExist added in v0.0.22

func (s *ContainerPool) CheckContainerNameIfExist(containerName reflect.Type) bool

CheckContainerNameIfExist check contain name if exist

func (*ContainerPool) ContainerDISelfCheck added in v0.0.22

func (s *ContainerPool) ContainerDISelfCheck(app Application)

ContainerDISelfCheck self check di request registered func exist or not

func (*ContainerPool) GetContainer

func (s *ContainerPool) GetContainer(containerType reflect.Type, tctx Context, app Application, c *gin.Context) (interface{}, map[reflect.Type]interface{})

GetContainer get service with di

func (*ContainerPool) GetContainerType

func (s *ContainerPool) GetContainerType(tags string) []reflect.Type

GetContainerType get all service type

func (*ContainerPool) NewContainer

func (s *ContainerPool) NewContainer(containerType reflect.Type, containerPool *sync.Pool, containerTags []string)

NewContainer add new container

func (*ContainerPool) Release

func (s *ContainerPool) Release(container interface{})

Release release service

type Context

type Context interface {
	Application() Application

	Runtime() map[string]string
	DB() *gorm.DB
	DBTx() *gorm.DB
	SafeCommit()
	SafeRollback()
	DBTxIsOpen() bool

	GinCtx() *gin.Context

	HTTPResponseUnauthorizedErr(error)
	HTTPResponseInternalErr(error)
	HTTPResponseErr(int, error)
	HTTPResponseOk(interface{}, error)
	HTTPResponseCreated(interface{}, error)
	HTTPResponse(int, interface{}, error)
	// contains filtered or unexported methods
}

Context record all thing inside one request

func MockContext

func MockContext(app Application, db *gorm.DB, c *gin.Context, runtime map[string]string) Context

MockContext used for unittest , don't use in production

func NewContext

func NewContext(app Application) Context

NewContext new contedt

type ContextImpl

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

ContextImpl Context impl

func (*ContextImpl) Application

func (c *ContextImpl) Application() Application

Application get app

func (*ContextImpl) DB

func (c *ContextImpl) DB() *gorm.DB

DB get db instance

func (*ContextImpl) DBTx

func (c *ContextImpl) DBTx() *gorm.DB

DBTx get db instance

func (*ContextImpl) DBTxIsOpen

func (c *ContextImpl) DBTxIsOpen() bool

DBTxIsOpen return is transactioon is open

func (*ContextImpl) GinCtx

func (c *ContextImpl) GinCtx() *gin.Context

GinCtx get gin ctx

func (*ContextImpl) HTTPResponse

func (c *ContextImpl) HTTPResponse(status int, res interface{}, err error)

HTTPResponse handle respoonse

func (*ContextImpl) HTTPResponseCreated

func (c *ContextImpl) HTTPResponseCreated(res interface{}, err error)

HTTPResponseCreated handle http http.StatusCreated 201 response

func (*ContextImpl) HTTPResponseErr

func (c *ContextImpl) HTTPResponseErr(status int, err error)

HTTPResponseErr handle http 400 response

func (*ContextImpl) HTTPResponseInternalErr

func (c *ContextImpl) HTTPResponseInternalErr(err error)

HTTPResponseInternalErr handle http 400 response

func (*ContextImpl) HTTPResponseOk

func (c *ContextImpl) HTTPResponseOk(res interface{}, err error)

HTTPResponseOk handle http http.StatusOK 200 response

func (*ContextImpl) HTTPResponseUnauthorizedErr

func (c *ContextImpl) HTTPResponseUnauthorizedErr(err error)

HTTPResponseUnauthorizedErr handle http 400 response

func (*ContextImpl) Runtime

func (c *ContextImpl) Runtime() map[string]string

Runtime get runtime info

func (*ContextImpl) SafeCommit

func (c *ContextImpl) SafeCommit()

SafeCommit safe commit

func (*ContextImpl) SafeRollback

func (c *ContextImpl) SafeRollback()

SafeRollback safe rollback

type ContextPool

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

ContextPool is the context pool, it's used inside router and the framework by itself.

It's the only one real implementation inside this package because it used widely.

func New

func New(newFunc func() Context) *ContextPool

New creates and returns a new context pool.

func (*ContextPool) Acquire

func (c *ContextPool) Acquire(app Application, runtime map[string]string, db *gorm.DB, ginCtx *gin.Context) Context

Acquire returns a Context from pool. See Release.

func (*ContextPool) Attach

func (c *ContextPool) Attach(newFunc func() Context)

Attach changes the pool's return value Context.

func (*ContextPool) Release

func (c *ContextPool) Release(ctx Context)

Release puts a Context back to its pull, this function releases its resources. See Acquire.

func (*ContextPool) ReleaseLight

func (c *ContextPool) ReleaseLight(ctx Context)

ReleaseLight will just release the object back to the pool, but the clean method is caller's responsibility now

type ControllerPool

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

ControllerPool service pool if grpc string is the full method of method if http os the GET@/ping/:id need to filter controllerFuncMap to filter funcname

func NewControllerPool

func NewControllerPool() *ControllerPool

NewControllerPool new pool with init map

func (*ControllerPool) ControllerFuncSelfCheck added in v0.0.22

func (s *ControllerPool) ControllerFuncSelfCheck(contailerPool *ContainerPool, isLog bool, logger *golog.Logger)

ControllerFuncSelfCheck self check http request registered func exist or not

func (*ControllerPool) GetController

func (s *ControllerPool) GetController(controllerName string, tctx Context, app Application, c *gin.Context) (interface{}, map[reflect.Type]interface{})

GetController from pool

func (*ControllerPool) GetControllerFuncName

func (s *ControllerPool) GetControllerFuncName(controllerName string) (string, bool)

GetControllerFuncName get controller func name

func (*ControllerPool) GetControllerMap

func (s *ControllerPool) GetControllerMap() []string

GetControllerMap get controller map

func (*ControllerPool) GetControllerValidators

func (s *ControllerPool) GetControllerValidators(controllerName string) []Validator

GetControllerValidators get controller func name

func (*ControllerPool) NewController

func (s *ControllerPool) NewController(controllerType string, container reflect.Type)

NewController add new service

func (*ControllerPool) NewControllerFunc

func (s *ControllerPool) NewControllerFunc(controllerType string, funcName string)

NewControllerFunc register funcname for controllertype

func (*ControllerPool) NewControllerValidators

func (s *ControllerPool) NewControllerValidators(controllerType string, validator ...Validator)

NewControllerValidators register funcname for controllertype

type DBLogger

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

DBLogger db logger

func NewDBLogger

func NewDBLogger(app Application, runtime map[string]string, config ...*LogConfig) *DBLogger

NewDBLogger new db logger

func (*DBLogger) Print

func (l *DBLogger) Print(v ...interface{})

Print db logger func

type LogConfig

type LogConfig struct {
	ProjectName    bool
	ProjectVersion bool

	// Method displays the request path (bool).
	// Defaults to true.
	Path bool

	// used in http request , show http method
	// default true
	Method bool

	// ClientIP
	// default true
	ClientIP bool

	// used in http request , show http status
	Status bool

	// used in http request , show body size
	BodySize bool

	// Req show request info
	// Defaults to true.
	Request bool
	// Response show response einfo
	// Defaults to true.
	Response bool
	// Error show error messagee
	// Defaults to true.
	Error bool

	// Latency show latency
	// Defaulte to true
	Latency bool

	// Runtime
	// Defaulte to true
	Runtime bool

	// Defaults nil
	LogFunc func(now time.Time, projectName, projectVersion, method string, latency time.Duration, runtimeValue map[string]string)

	// Skippers will according method to see if skip the logger middleware
	Skippers []SkipperFunc
}

LogConfig middleware config

func DefaultLogConfig

func DefaultLogConfig() *LogConfig

DefaultLogConfig default log miiddleware setting

type Logger

type Logger interface {
	Interceptor() func(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (interface{}, error)
	Middleware() gin.HandlerFunc
}

Logger for log middleware

func NewLogLogger

func NewLogLogger(app Application, config *LogConfig) Logger

NewLogLogger new log logger

type RequestMap

type RequestMap struct {
	Method     httputil.RequestMethod
	SubPath    string
	FuncName   string
	Validators []Validator
}

RequestMap request map to register request

func NewRequestMapping

func NewRequestMapping(method httputil.RequestMethod, path string, funcName string, validators ...Validator) *RequestMap

NewRequestMapping request mapping @funcName if funcname is "" , trinitygoo will use the default http method name to find the method e.g : http method "GET" ==> find method "GET"

type SkipperFunc

type SkipperFunc func(method string) bool

SkipperFunc check if method need to be skip

type Validator

type Validator func(Context)

Validator to validator request

Jump to

Keyboard shortcuts

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