router

package
v0.0.0-...-e120e2b Latest Latest
Warning

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

Go to latest
Published: Jan 14, 2023 License: BSD-3-Clause Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	HeaderContentType = "content-type"
)

Variables

This section is empty.

Functions

func AddIgnoreAuthPath

func AddIgnoreAuthPath(pathList ...string)

func AddOpenApiPath

func AddOpenApiPath(pathList ...string)

func CheckIfIgnoreAuth

func CheckIfIgnoreAuth(path string) bool

func CheckIfOpenApi

func CheckIfOpenApi(path string) bool

func CreateMetadataFromHeader

func CreateMetadataFromHeader(header http.Header) metadata.MD

func LoggerHandler

func LoggerHandler(ctx *Context)

func RecoverHandler

func RecoverHandler(ctx *Context)

func Register

func Register(groupName string, handler interface{}) error

func SetPrefix

func SetPrefix(prefix string)

func Start

func Start(addr string) error

func TraceHandler

func TraceHandler(ctx *Context)

func Use

func Use(handlerChain ...HandleFunc)

func WriteJson

func WriteJson(w http.ResponseWriter, data interface{}, code ...int)

func WriteProtobuf

func WriteProtobuf(w http.ResponseWriter, data proto.Message, code ...int)

func WriteProtobufError

func WriteProtobufError(w http.ResponseWriter, errContent *dt.Error, code ...int)

func WriteString

func WriteString(w http.ResponseWriter, data string, code ...int)

func WriteSuccessData

func WriteSuccessData(w http.ResponseWriter, data interface{})

Types

type Context

type Context struct {
	Request        *http.Request
	ResponseWriter http.ResponseWriter
	BodyContent    []byte

	RpcContext context.Context

	StatusCode int
	// contains filtered or unexported fields
}

func (*Context) Abort

func (t *Context) Abort()

func (*Context) DATA

func (t *Context) DATA(data interface{}) (int, error)

func (*Context) ERROR

func (t *Context) ERROR(data errors.Error) (int, error)

func (*Context) GetAccessKey

func (t *Context) GetAccessKey() string

func (*Context) GetContentType

func (t *Context) GetContentType() string

func (*Context) GetCopyOfBodyBytes

func (t *Context) GetCopyOfBodyBytes() ([]byte, error)

func (*Context) GetHeader

func (t *Context) GetHeader(k string) string

func (*Context) GetRequestBodyBytes

func (t *Context) GetRequestBodyBytes() ([]byte, error)

func (*Context) GetSign

func (t *Context) GetSign() string

func (*Context) GetSignMethod

func (t *Context) GetSignMethod() yc.SignMethod

func (*Context) GetTimestamp

func (t *Context) GetTimestamp() int64

func (*Context) GetToken

func (t *Context) GetToken() string

func (*Context) IsJson

func (t *Context) IsJson() bool

func (*Context) IsPost

func (t *Context) IsPost() bool

func (*Context) IsProtoBuf

func (t *Context) IsProtoBuf() bool

func (*Context) Next

func (t *Context) Next()

func (*Context) SUCCESS

func (t *Context) SUCCESS(data interface{}) (int, error)

func (*Context) SetUserId

func (t *Context) SetUserId(userId *dt.ID)

func (*Context) Write

func (t *Context) Write(data []byte) (int, error)

func (*Context) WriteHeaderCode

func (t *Context) WriteHeaderCode(code int)

func (*Context) WriteJsonFailed

func (t *Context) WriteJsonFailed(data interface{}) (int, error)

func (*Context) WriteJsonSuccess

func (t *Context) WriteJsonSuccess(data interface{}) (int, error)

func (*Context) WriteJsonWithCode

func (t *Context) WriteJsonWithCode(data interface{}, code int) (int, error)

func (*Context) WriteProtobufFailed

func (t *Context) WriteProtobufFailed(data proto.Message) (int, error)

func (*Context) WriteProtobufSuccess

func (t *Context) WriteProtobufSuccess(data proto.Message) (int, error)

func (*Context) WriteProtobufWithCode

func (t *Context) WriteProtobufWithCode(data proto.Message, code int) (int, error)

type HandleFunc

type HandleFunc func(ctx *Context)

type JsonResponseWrapper

type JsonResponseWrapper struct {
	Code int         `json:"code"`
	Data interface{} `json:"data"`
	Msg  string      `json:"msg"`
}

type Router

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

func NewRouter

func NewRouter(prefix string, handlerChain ...HandleFunc) *Router

func (*Router) AddIgnoreAuthPath

func (t *Router) AddIgnoreAuthPath(pathList ...string)

func (*Router) AddOpenApiPath

func (t *Router) AddOpenApiPath(pathList ...string)

func (*Router) CheckIfIgnoreAuth

func (t *Router) CheckIfIgnoreAuth(path string) bool

func (*Router) CheckIfOpenApi

func (t *Router) CheckIfOpenApi(path string) bool

func (*Router) Register

func (t *Router) Register(groupName string, handler interface{}) error

func (*Router) ServeHTTP

func (t *Router) ServeHTTP(w http.ResponseWriter, r *http.Request)

func (*Router) SetPrefix

func (t *Router) SetPrefix(prefix string)

func (*Router) Start

func (t *Router) Start(addr string) error

func (*Router) Use

func (t *Router) Use(handlerChain ...HandleFunc)

type ValidatorHandler

type ValidatorHandler interface {
	Validate() error
}

Jump to

Keyboard shortcuts

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