routtp

package module
v0.0.0-...-f16eafe Latest Latest
Warning

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

Go to latest
Published: Dec 11, 2022 License: BSD-3-Clause Imports: 17 Imported by: 1

README

routtp

GitHub GitHub language count GitHub top language GitHub search hit counter

Documentation

Index

Constants

View Source
const AbortIndex int8 = math.MaxInt8 >> 1

AbortIndex represents a typical value used in abort functions.

Variables

View Source
var (

	// ErrConvertMapStringSlice can not covert to map[string][]string
	ErrConvertMapStringSlice = errors.New("can not convert to map slices of strings")

	// ErrConvertToMapString can not convert to map[string]string
	ErrConvertToMapString = errors.New("can not convert to map of strings")
)
View Source
var EnableDecoderDisallowUnknownFields = false

EnableDecoderDisallowUnknownFields is used to call the DisallowUnknownFields method on the JSON Decoder instance. DisallowUnknownFields causes the Decoder to return an error when the destination is a struct and the input contains object keys which do not match any non-ignored, exported fields in the destination.

View Source
var EnableDecoderUseNumber = false

EnableDecoderUseNumber is used to call the UseNumber method on the JSON Decoder instance. UseNumber causes the Decoder to unmarshal a number into an interface{} as a Number instead of as a float64.

Functions

func BytesToString

func BytesToString(b []byte) string

BytesToString converts byte slice to string without a memory allocation.

func InvalidPath

func InvalidPath(path string)

TODO: 实现

func MapFormWithTag

func MapFormWithTag(ptr any, form map[string][]string, tag string) error

func StringToBytes

func StringToBytes(s string) []byte

StringToBytes converts string to byte slice without a memory allocation.

func Wrap

func Wrap(f func(w http.ResponseWriter, r *http.Request)) func(*Context)

Types

type Context

type Context struct {
	Request  *http.Request
	Response http.ResponseWriter

	Cancel context.CancelFunc
	// contains filtered or unexported fields
}

func (*Context) Abort

func (ctx *Context) Abort()

func (*Context) Bind

func (ctx *Context) Bind(v any) error

func (*Context) BindJSON

func (ctx *Context) BindJSON(v any) error

---------- Bind ----------

func (*Context) BindQuery

func (ctx *Context) BindQuery(v any) error

func (*Context) City

func (ctx *Context) City() string

func (*Context) Clone

func (ctx *Context) Clone() (ctxClone *Context)

func (*Context) Deadline

func (ctx *Context) Deadline() (deadline time.Time, ok bool)

func (*Context) Done

func (ctx *Context) Done() <-chan struct{}

func (*Context) Err

func (ctx *Context) Err() error

func (*Context) Exception

func (ctx *Context) Exception(resp Response)

异常响应 不会包含 Msg

func (*Context) Get

func (ctx *Context) Get(key string) any

func (*Context) GetBody

func (ctx *Context) GetBody() []byte

---------- Request Body ----------

func (*Context) GetBool

func (ctx *Context) GetBool(key string) bool

func (*Context) GetFloat32

func (ctx *Context) GetFloat32(key string) float32

func (*Context) GetFloat64

func (ctx *Context) GetFloat64(key string) float64

func (*Context) GetInt

func (ctx *Context) GetInt(key string) int

func (*Context) GetInt64

func (ctx *Context) GetInt64(key string) int64

func (*Context) GetString

func (ctx *Context) GetString(key string) string

func (*Context) GetUint

func (ctx *Context) GetUint(key string) uint

func (*Context) GetUint64

func (ctx *Context) GetUint64(key string) uint64

func (*Context) Header

func (ctx *Context) Header() http.Header

func (*Context) HeaderAdd

func (ctx *Context) HeaderAdd(key, value string)

func (*Context) HeaderClone

func (ctx *Context) HeaderClone() http.Header

func (*Context) HeaderDel

func (ctx *Context) HeaderDel(key string)

func (*Context) HeaderGet

func (ctx *Context) HeaderGet(key string) string

func (*Context) HeaderSet

func (ctx *Context) HeaderSet(key, value string)

func (*Context) HeaderValues

func (ctx *Context) HeaderValues(key string) []string

func (*Context) HeaderWrite

func (ctx *Context) HeaderWrite(w io.Writer) error

func (*Context) HeaderWriteSubset

func (ctx *Context) HeaderWriteSubset(w io.Writer, exclude map[string]bool) error

func (*Context) JSON

func (ctx *Context) JSON(statusCode int, body any)

func (*Context) Next

func (ctx *Context) Next()

func (*Context) Param

func (ctx *Context) Param(key string) string

func (*Context) RealIP

func (ctx *Context) RealIP() string

func (*Context) RequestHeader

func (ctx *Context) RequestHeader() http.Header

---------- Request ---------- ---------- Request Header ----------

func (*Context) Set

func (ctx *Context) Set(key string, val any)

func (*Context) Success

func (ctx *Context) Success(body any)

成功响应

func (*Context) Traceid

func (ctx *Context) Traceid() string

func (*Context) UserPrior

func (ctx *Context) UserPrior() uint8

func (*Context) Userid

func (ctx *Context) Userid() string

func (*Context) Username

func (ctx *Context) Username() string

---------- Apigw ----------

func (*Context) Value

func (ctx *Context) Value(key any) any

not implate

func (*Context) Write

func (ctx *Context) Write(p []byte) (int, error)

---------- Response ----------

func (*Context) WriteHeader

func (ctx *Context) WriteHeader(statusCode int)

type Handler

type Handler = func(*Context)

type Handlers

type Handlers []Handler

type JSON

type JSON = map[string]any

type Node

type Node struct {
	Path     string
	Children []*Node
	Handlers Handlers `json:"-"`
}

func NewNode

func NewNode(path string, handlers Handlers) *Node

func (*Node) AddRoute

func (n *Node) AddRoute(path string, handlers ...Handler)

func (*Node) Fprint

func (n *Node) Fprint(w io.Writer, lvl int) (err error)

func (*Node) Get

func (n *Node) Get(ctx *Context, uri string) bool

func (*Node) Print

func (n *Node) Print() error

func (*Node) String

func (n *Node) String() string

type Pair

type Pair[K, V any] struct {
	Key K
	Val V
}

type Response

type Response interface {
	Code() int
	Msg() string
	Data() any
	Status() int
}

type Router

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

func New

func New(fn ...Handler) *Router

func (*Router) Add

func (router *Router) Add(meth, path string, fn ...Handler)

func (*Router) DELETE

func (router *Router) DELETE(path string, fn ...Handler)

func (*Router) GET

func (router *Router) GET(path string, fn ...Handler)

func (*Router) Group

func (router *Router) Group(fn ...Handler) *Router

func (*Router) PATCH

func (router *Router) PATCH(path string, fn ...Handler)

func (*Router) POST

func (router *Router) POST(path string, fn ...Handler)

func (*Router) PUT

func (router *Router) PUT(path string, fn ...Handler)

func (*Router) ServeHTTP

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

func (*Router) Use

func (router *Router) Use(fn ...Handler)

func (*Router) WithPprof

func (router *Router) WithPprof()

Jump to

Keyboard shortcuts

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