ginctx

package
v0.0.0-...-496a76a Latest Latest
Warning

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

Go to latest
Published: Jan 3, 2025 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	LogKeyRequestID = "requestID"
	LogKeyAction    = "action"

	ActionExecStartTime = "startTime"
)
View Source
const (
	// * plugin
	ErrPluginNotFound Code = "ErrPluginNotFound"
	ErrPluginInvalid       = "ErrPluginInvalid"

	// * request
	ErrRequestAccessDenied   = "ErrRequestAccessDenied"
	ErrRequestMethodNotFound = "ErrRequestMethodNotFound"
	ErrRequestParamInvalid   = "ErrRequestParamInvalid"
	// * resource
	ErrResourceNotFound        = "ErrResourceNotFound"
	ErrResourceAccessForbidden = "ErrResourceAccessForbidden"
	ErrResourceConflict        = "ErrResourceConflict"
	ErrResourceDeleteForbidden = "ErrResourceDeleteForbidden"
	ErrResourceHasBeenUsed     = "ErrResourceHasBeenUsed"
	ErrSubResourceExist        = "ErrSubResourceExist"
	ErrNodeNotReady            = "ErrNodeNotReady"
	ErrInvalidToken            = "ErrInvalidToken"

	// * volumes
	ErrVolumeType = "ErrVolumeType"
	// * unknown
	ErrUnknown = "UnknownError"
	// * application
	ErrAppNameConflict         = "ErrAppNameConflict"
	ErrVolumeNotFoundWhenMount = "ErrVolumeNotFoundWhenMount"
	ErrAppReferencedByNode     = "ErrAppReferencedByNode"
	// * node
	ErrNodeNumMaxLimit       = "ErrNodeNumMaxLimit"
	ErrNodeNumQueryException = "ErrNodeNumQueryException"

	// * config
	ErrConfigInUsed = "ErrConfigInUsed"
	// * register
	ErrRegisterQuotaNumOut     = "ErrRegisterQuotaNumOut"
	ErrRegisterDeleteRecord    = "ErrRegisterDeleteRecord"
	ErrRegisterDeleteCallback  = "ErrRegisterDeleteCallback"
	ErrRegisterPackage         = "ErrRegisterPackage"
	ErrRegisterRecordActivated = "ErrRegisterRecordActivated"
	// * db
	ErrDatabase  = "ErrDatabase"
	ErrUpdateCas = "ErrUpdateCas"
	// * k8s
	ErrK8S = "ErrK8S"
	// * ceph
	ErrCeph = "ErrCeph"
	// * io
	ErrIO = "ErrIO"
	// * template
	ErrTemplate = "ErrTemplate"
	// * function
	ErrFunction = "ErrFunction"
	// * resourceName
	ErrInvalidResourceName = "resourceName"
	ErrInvalidLabels       = "validLabels"
	ErrInvalidRequired     = "required"
	// * batchOp
	ErrInvalidArrayLength = "maxLength"
	// * fingerprintValue
	ErrInvalidFingerprintValue = "fingerprintValue"
	// * memory
	ErrInvalidMemory = "memory"
	// * duration
	ErrInvalidDuration = "duration"
	// * setcpus
	ErrInvalidSetcpus = "setcpus"
	// * nonBaetyl
	ErrInvalidName = "nonBaetyl"
	// * license
	ErrLicenseExpired      = "ErrLicenseExpired"
	ErrLicenseQuota        = "ErrLicenseQuota"
	ErrLicenseQuotaAcquire = "ErrLicenseQuotaAcquire"
	ErrLicenseQuotaRelease = "ErrLicenseQuotaRelease"
	// * third server error
	ErrThirdServer = "ErrThirdServer"
	// * object error
	ErrObjectOperationException = "ErrObjectOperationException"

	ErrResourceInvisible = "ErrResourceInvisible"
	ErrConvertConflict   = "ErrConvertConflict"

	ErrPubsubTimeout   = "ErrPubsubTimeout"
	ErrUpdateSubLabels = "ErrUpdateSubLabels"
	ErrDataTooLarge    = "ErrDataTooLarge"
)

all codes

Variables

This section is empty.

Functions

func Error

func Error(c Code, fs ...*F) error

Error returns an error with code and fields

func PackageResponse

func PackageResponse(res interface{}) (int, interface{})

PackageResponse PackageResponse

func PopulateFailedMisResponse

func PopulateFailedMisResponse(cc *Context, err error, abort bool)

PopulateFailedMisResponse PopulateFailedMisResponse

func PopulateFailedResponse

func PopulateFailedResponse(cc *Context, err error, abort bool)

PopulateFailedResponse PopulateFailedResponse

func Wrapper

func Wrapper(handler HandlerFunc) func(c *gin.Context)

Wrapper Wrapper TODO: to use gin.HandlerFunc ?

func WrapperMis

func WrapperMis(handler HandlerFunc) func(c *gin.Context)

func WrapperNative

func WrapperNative(handler HandlerFunc, abort bool) func(c *gin.Context)

func WrapperRaw

func WrapperRaw(handler HandlerFunc, abort bool) func(c *gin.Context)

func WrapperString

func WrapperString(handler HandlerFunc) func(c *gin.Context)

func WrapperWithLock

func WrapperWithLock(lockFunc LockFunc, unlockFunc UnlockFunc) func(c *gin.Context)

WrapperWithLock wrap handler with lock

Types

type Code

type Code string

Code code

func (Code) String

func (c Code) String() string

type Context

type Context struct {
	*gin.Context
	*log.Logger
}

Context context

func NewContextEmpty

func NewContextEmpty() *Context

NewContextEmpty create a new empty context

func NewContextWithLog

func NewContextWithLog(log *log.Logger) *Context

NewContext create a new context with log

func NewHttpContext

func NewHttpContext(inner *gin.Context) *Context

NewContext create a new context with gin context

func NewTraceContext

func NewTraceContext(requestID string, field ...log.Field) *Context

NewTraceContext trace contest with start time and field

func (*Context) GetName

func (c *Context) GetName() string

GetName gets name from context if exists

func (*Context) GetNameFromParam

func (c *Context) GetNameFromParam() string

GetNameFromParam gets name from param if exists

func (*Context) GetNamespace

func (c *Context) GetNamespace() string

GetNamespace gets namespace from context if exists

func (*Context) GetRequestID

func (c *Context) GetRequestID() string

GetRequestID get log requestID

func (*Context) GetUser

func (c *Context) GetUser() User

GetUser gets user from context if exists

func (*Context) GetUserInfo

func (c *Context) GetUserInfo() UserInfo

GetUser gets user info from context if exists

func (*Context) LoadBody

func (c *Context) LoadBody(obj interface{}) error

LoadBody loads json data from body into object and set defaults

func (*Context) LoadBodyMulti

func (c *Context) LoadBodyMulti(obj interface{}) error

func (*Context) SetAction

func (c *Context) SetAction(value interface{})

SetAction set exec action func

func (*Context) SetInfo

func (c *Context) SetInfo(key string, value interface{})

func (*Context) SetName

func (c *Context) SetName(n string)

SetName sets name into context

func (*Context) SetNamespace

func (c *Context) SetNamespace(ns string)

SetNamespace sets namespace into context

func (*Context) SetRequestID

func (c *Context) SetRequestID(requestID string)

SetRequestID set log requestID

func (*Context) SetTraceStartTime

func (c *Context) SetTraceStartTime()

SetTraceStartTime set action exec start time

func (*Context) SetUser

func (c *Context) SetUser(user User)

SetUser sets user into context

func (*Context) SetUserInfo

func (c *Context) SetUserInfo(info UserInfo)

SetUser sets user info into context

func (*Context) TraceCostTime

func (c *Context) TraceCostTime(event string)

TraceCostTime add from start trace to this func cost time

type Domain

type Domain struct {
	ID   string
	Name string
}

type F

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

Field field

func Field

func Field(k string, v interface{}) *F

Field returns a field

type HandlerFunc

type HandlerFunc func(c *Context) (interface{}, error)

HandlerFunc HandlerFunc

type LockFunc

type LockFunc func(ctx context.Context, name string, ttl int64) (string, error)

type Role

type Role struct {
	ID   string
	Type string
}

type UnlockFunc

type UnlockFunc func(ctx context.Context, name, version string)

type User

type User struct {
	ID   string
	Name string
}

type UserInfo

type UserInfo struct {
	User   User
	Roles  []Role
	Domain Domain
}

Jump to

Keyboard shortcuts

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