core

package
v0.0.0-...-b273383 Latest Latest
Warning

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

Go to latest
Published: Jan 12, 2026 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	UserIDKey = "_user_id_"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type BusinessError

type BusinessError interface {
	// WithError setting error message
	WithStack(err error) BusinessError

	// BusinessCode get business code
	BusinessCode() string

	// HTTPCode get the HTTP status code
	HTTPCode() int

	// Message get the error description
	Message() string

	// StackError get the error message with stack
	StackError() error

	Error() string
}

func Error

func Error(businessCode, message string) BusinessError

type Context

type Context interface {
	ShouldBind(obj interface{}) error

	// ShouldBindQuery deserialization querystring
	// tag: `form:"xxx"`(note: do not write query)
	ShouldBindQuery(obj interface{}) error

	// ShouldBindPostForm deserialization postform (querystring will be ignored)
	// tag: `form:"xxx"`
	ShouldBindPostForm(obj interface{}) error

	// ShouldBindJSON deserialization postjson
	// tag: `json:"xxx"`
	ShouldBindJSON(obj interface{}) error

	// ShouldBindURI the deserialization path parameter (if the routing path is/user/:name)
	// tag: `uri:"xxx"`
	ShouldBindURI(obj interface{}) error

	Param(key string) string

	// Payload returned correctly
	GetMethodPath() (method string, path string)

	// Payload 正确返回
	Payload(payload interface{})

	// AbortWithError error return
	AbortWithPermissionError(err error, expectCode string, emptyResp any)

	// c.AbortWithError(
	// 			http.StatusBadRequest,
	// 			code.ParamBindError,
	// 			err,
	// 		)
	// AbortWithError(err BusinessError)
	// If err is BusinessError, param businessCode will be ignored
	AbortWithError(statusCode int, businessCode string, err error)

	// Header Gets the Header object
	Header() http.Header
	// Get the header GetHeader
	GetHeader(key string) string
	// Set the header SetHeader
	SetHeader(key, value string)

	GetContext() go_context.Context
	// Set Sets key-value pairs in context
	Set(key string, value interface{})
	// Get Gets the value of the key in context.
	Get(key string) (any, bool)

	Next()
	Request() *http.Request

	ClientIP() string

	LANG() string
	UserID() int64

	ErrMessage(errCode string) string

	Clone() Context

	Done() <-chan struct{}
	Err() error
	Value(key any) any
	Deadline() (deadline time.Time, ok bool)
	// contains filtered or unexported methods
}

func EmptyCtx

func EmptyCtx() Context

type HandlerFunc

type HandlerFunc func(c Context)

type Mux

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

func New

func New(logger *zap.Logger) (*Mux, error)

func (*Mux) Group

func (m *Mux) Group(relativePath string, handlers ...HandlerFunc) *Router

func (*Mux) ServeHTTP

func (m *Mux) ServeHTTP(w http.ResponseWriter, req *http.Request)

type Router

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

func (*Router) Any

func (r *Router) Any(relativePath string, handlers ...HandlerFunc)

func (*Router) DELETE

func (r *Router) DELETE(relativePath string, handlers ...HandlerFunc)

func (*Router) GET

func (r *Router) GET(relativePath string, handlers ...HandlerFunc)

func (*Router) GET_Gin

func (r *Router) GET_Gin(relativePath string, handlers []gin.HandlerFunc)

func (*Router) PATCH

func (r *Router) PATCH(relativePath string, handlers ...HandlerFunc)

func (*Router) POST

func (r *Router) POST(relativePath string, handlers ...HandlerFunc)

func (*Router) POST_Gin

func (r *Router) POST_Gin(relativePath string, handlers []gin.HandlerFunc)

func (*Router) PUT

func (r *Router) PUT(relativePath string, handlers ...HandlerFunc)

func (*Router) Use

func (r *Router) Use(middleware HandlerFunc) *Router

Jump to

Keyboard shortcuts

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