Documentation
¶
Index ¶
- func ANY(path string, h any)
- func CONNECT(path string, h any)
- func DELETE(path string, h any)
- func Fail(w http.ResponseWriter, status int, err error)
- func Failf(w http.ResponseWriter, status int, msg string, args ...any)
- func GET(path string, h any)
- func GRPCGatewayMux() *runtime.ServeMux
- func HEAD(path string, h any)
- func ListenAndServe(addr string) error
- func MarshalText(data any) ([]byte, error)
- func OPTION(path string, h any)
- func PATCH(path string, h any)
- func POST(path string, h any)
- func PUT(path string, h any)
- func Return(w http.ResponseWriter, status int, data any, ...)
- func ReturnJSON(w http.ResponseWriter, status int, data any)
- func ReturnText(w http.ResponseWriter, status int, data any)
- func TRACE(path string, h any)
- type Context
- func (c *Context) Body() []byte
- func (c *Context) Deadline() (deadline time.Time, ok bool)
- func (c *Context) Done() <-chan struct{}
- func (c *Context) Err() error
- func (c *Context) Fail(status int, err error)
- func (c *Context) Failf(status int, msg string, args ...any)
- func (c *Context) Get(key string) (value any, exists bool)
- func (c *Context) Return(status int, data any, marshaler func(any) ([]byte, error))
- func (c *Context) ReturnJSON(status int, data any)
- func (c *Context) ReturnText(status int, data any)
- func (c *Context) Set(key string, value any)
- func (c *Context) SetContentType(s string)
- func (c *Context) Value(key any) any
- func (c *Context) With(ctx context.Context) context.Context
- type Group
- func (g *Group) ANY(p string, h any)
- func (g *Group) CONNECT(p string, h any)
- func (g *Group) DELETE(p string, h any)
- func (g *Group) GET(p string, h any)
- func (g *Group) GROUP(p string, middlewares ...Middleware) *Group
- func (g *Group) HEAD(p string, h any)
- func (g *Group) OPTION(p string, h any)
- func (g *Group) PATCH(p string, h any)
- func (g *Group) POST(p string, h any)
- func (g *Group) PUT(p string, h any)
- func (g *Group) TRACE(p string, h any)
- type Handler
- type HandlerCode
- type Middleware
- type ResponseBody
- type Service
- func (srv *Service) ANY(path string, h any)
- func (srv *Service) CONNECT(path string, h any)
- func (srv *Service) DELETE(path string, h any)
- func (srv *Service) GET(path string, h any)
- func (srv *Service) GROUP(path string, middlewares ...Middleware) *Group
- func (srv *Service) GRPCGatewayMux() *runtime.ServeMux
- func (srv *Service) HEAD(path string, h any)
- func (srv *Service) ListenAndServe(addr string) error
- func (srv *Service) OPTION(path string, h any)
- func (srv *Service) PATCH(path string, h any)
- func (srv *Service) POST(path string, h any)
- func (srv *Service) PUT(path string, h any)
- func (srv *Service) ServeHTTP(w http.ResponseWriter, req *http.Request)
- func (srv *Service) TRACE(path string, h any)
- type ServiceOption
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GRPCGatewayMux ¶ added in v0.0.3
func ListenAndServe ¶
func MarshalText ¶ added in v0.0.5
func ReturnJSON ¶ added in v0.0.6
func ReturnJSON(w http.ResponseWriter, status int, data any)
func ReturnText ¶ added in v0.0.6
func ReturnText(w http.ResponseWriter, status int, data any)
Types ¶
type Context ¶ added in v0.0.5
type Context struct { Request *http.Request Writer http.ResponseWriter Keys map[string]any // contains filtered or unexported fields }
Context is the most important part of gin. It allows us to pass variables between middleware, manage the flow, validate the JSON of a request and render a JSON response for example.
func Ctx ¶ added in v0.0.6
Ctx peek *apix.Context from the given context, it return nil if *apix.Context not exist
func (*Context) Deadline ¶ added in v0.0.5
Deadline returns that there is no deadline (ok==false) when c.Request has no Context.
func (*Context) Done ¶ added in v0.0.5
func (c *Context) Done() <-chan struct{}
Done returns nil (chan which will wait forever) when c.Request has no Context.
func (*Context) Get ¶ added in v0.0.5
Get returns the value for the given key, ie: (value, true). If the value does not exist it returns (nil, false)
func (*Context) ReturnJSON ¶ added in v0.0.6
func (*Context) ReturnText ¶ added in v0.0.6
func (*Context) Set ¶ added in v0.0.5
Set is used to store a new key/value pair exclusively for this context. It also lazy initializes c.Keys if it was not used previously.
func (*Context) SetContentType ¶ added in v0.0.5
type Group ¶ added in v0.0.2
type Group struct {
// contains filtered or unexported fields
}
Group represents a api group
func GROUP ¶ added in v0.0.3
func GROUP(path string, middlewares ...Middleware) *Group
type Handler ¶
Handler is a function type for handling http.Request, the return value will be marshaled into json before writing into response.
type HandlerCode ¶
HandlerCode is similar with apix.Handler, but can customze the http status code in response by the second return value.
type Middleware ¶ added in v0.0.2
type Middleware func(http.HandlerFunc) http.HandlerFunc
Middleware wrap the http.HandlerFunc, so that it can handle the http.Request in advance and intercept the request if required(eg. authorization, logging)
type ResponseBody ¶
type ResponseBody struct { Code int `json:"code"` Data any `json:"data,omitempty"` Message string `json:"message,omitempty"` }
ResponseBody represents data type in response body
func (ResponseBody) Error ¶
func (reb ResponseBody) Error() string
Error implements the error interface, it return empty string if ResponseBody.Code == 0
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
var (
DefaultService *Service
)
func New ¶
func New(opts ...ServiceOption) *Service
func (*Service) GROUP ¶ added in v0.0.2
func (srv *Service) GROUP(path string, middlewares ...Middleware) *Group
GROUP create a api group with custom url prefix and middlewares, the middlewares only works on handlers registerd on this group
func (*Service) GRPCGatewayMux ¶
GRPCGatewayMux return the grpcgateway servemux, use it to register grpc service
func (*Service) ListenAndServe ¶
type ServiceOption ¶
type ServiceOption func(*Service)
func UseGRPCHeaders ¶
func UseGRPCHeaders(patterns ...string) ServiceOption
UseGRPCHeaders extends the http headers whould to be forward to grpc service. By default, only headers with 'grpcgateway-' key prefix, and permanent HTTP header(as specified by the IANA, e.g: Accept, Cookie, Host) will be forward.
func WithMiddleware ¶ added in v0.0.2
func WithMiddleware(middlewares ...Middleware) ServiceOption
WithMiddleware specifics middlewares for all the service handlers.
func WithNotFoundHandler ¶
func WithNotFoundHandler(h http.Handler) ServiceOption
WithNotFoundHandler specifics a http handler for 404 case.
func WithResponseMarshaler ¶ added in v0.0.5
func WithResponseMarshaler(marshaler func(any) ([]byte, error)) ServiceOption