Documentation ¶
Index ¶
- Constants
- Variables
- func NewHttpError(code int, messages ...any) *httpError
- func PotetoJsonRPCAdapter[T any, S any](ctx Context, api *T) error
- type Binder
- type Context
- type HandlerFunc
- type HttpError
- type HttpErrorHandler
- type HttpParam
- type IPHandler
- type Leaf
- type LeafHandler
- type MiddlewareFunc
- type MiddlewareTree
- type ParamUnit
- type Poteto
- type PotetoOption
- type PotetoWorkflows
- type Response
- type Route
- type Router
- type UnitWorkflow
- type WorkflowFunc
Constants ¶
View Source
const Banner = `` /* 1937-byte string literal not displayed */
Variables ¶
View Source
var DefaultPotetoOption = PotetoOption{ WithRequestId: true, ListenerNetwork: "tcp", }
Functions ¶
func NewHttpError ¶
func PotetoJsonRPCAdapter ¶
inspired by https://github.com/kanocz/goginjsonrpc/blob/master/jsonrpc.go * Only Support "POST" method
Types ¶
type Context ¶
type Context interface { JSON(code int, value any) error JSONRPCError(code int, message string, data string, id int) error Bind(object any) error WriteHeader(code int) JsonSerialize(value any) error JsonDeserialize(object any) error SetQueryParam(queryParams url.Values) SetParam(paramType string, paramUnit ParamUnit) PathParam(key string) (string, bool) QueryParam(key string) (string, bool) DebugParam() (string, bool) SetPath(path string) GetPath() string Set(key string, val any) Get(key string) (any, bool) GetResponse() *response SetResponseHeader(key, value string) GetRequest() *http.Request GetRequestHeaderParam(key string) string ExtractRequestHeaderParam(key string) []string NoContent() error // set request id to store // and return value RequestId() string GetRemoteIP() (string, error) RegisterTrustIPRange(ranges *net.IPNet) GetIPFromXFFHeader() (string, error) RealIP() (string, error) Reset(w http.ResponseWriter, r *http.Request) SetLogger(logger any) Logger() any }
func NewContext ¶
func NewContext(w http.ResponseWriter, r *http.Request) Context
type HandlerFunc ¶
type HttpErrorHandler ¶
type HttpParam ¶
type HttpParam interface { GetParam(paramType, key string) (string, bool) AddParam(paramType string, paramUnit ParamUnit) JsonSerialize() ([]byte, error) }
func NewHttpParam ¶
func NewHttpParam() HttpParam
type Leaf ¶
type Leaf interface { Register(middlewares ...MiddlewareFunc) *middlewareTree GET(addPath string, handler HandlerFunc) error POST(addPath string, handler HandlerFunc) error PUT(addPath string, handler HandlerFunc) error PATCH(path string, handler HandlerFunc) error DELETE(addPath string, handler HandlerFunc) error HEAD(path string, handler HandlerFunc) error OPTIONS(path string, handler HandlerFunc) error TRACE(path string, handler HandlerFunc) error CONNECT(path string, handler HandlerFunc) error }
type LeafHandler ¶
type LeafHandler func(leaf Leaf)
type MiddlewareFunc ¶
type MiddlewareFunc func(next HandlerFunc) HandlerFunc
type MiddlewareTree ¶
type MiddlewareTree interface { SearchMiddlewares(pattern string) []MiddlewareFunc Insert(pattern string, middlewares ...MiddlewareFunc) *middlewareTree Register(middlewares ...MiddlewareFunc) }
func NewMiddlewareTree ¶
func NewMiddlewareTree() MiddlewareTree
type Poteto ¶
type Poteto interface { // If requested, call this ServeHTTP(w http.ResponseWriter, r *http.Request) Run(addr string) error RunTLS(addr string, cert, key []byte) error Stop(ctx stdContext.Context) error Register(middlewares ...MiddlewareFunc) Combine(pattern string, middlewares ...MiddlewareFunc) *middlewareTree SetLogger(logger any) Leaf(basePath string, handler LeafHandler) // workflow is a function that is executed when the server starts | end // - constant.START_UP_WORKFLOW: "startUp" // - This is a workflow that is executed when the server starts RegisterWorkflow(workflowType string, priority uint, workflow WorkflowFunc) GET(path string, handler HandlerFunc) error POST(path string, handler HandlerFunc) error PUT(path string, handler HandlerFunc) error PATCH(path string, handler HandlerFunc) error DELETE(path string, handler HandlerFunc) error HEAD(path string, handler HandlerFunc) error OPTIONS(path string, handler HandlerFunc) error TRACE(path string, handler HandlerFunc) error CONNECT(path string, handler HandlerFunc) error // contains filtered or unexported methods }
func NewWithOption ¶
func NewWithOption(option PotetoOption) Poteto
type PotetoOption ¶
type PotetoWorkflows ¶ added in v1.3.0
type PotetoWorkflows interface { RegisterWorkflow(workflowType string, priority uint, workflow WorkflowFunc) ApplyStartUpWorkflows() error }
workflow is a function that is executed when the server starts | end - constant.START_UP_WORKFLOW: "startUp"
- This is a workflow that is executed when the server starts
func NewPotetoWorkflows ¶ added in v1.3.0
func NewPotetoWorkflows() PotetoWorkflows
type Response ¶
type Response interface { WriteHeader(code int) Write(b []byte) (int, error) SetStatus(code int) Header() http.Header SetHeader(key, value string) AddHeader(key, value string) }
func NewResponse ¶
func NewResponse(w http.ResponseWriter) Response
type Route ¶
type Route interface { Search(path string) (*route, []ParamUnit) Insert(path string, handler HandlerFunc) GetHandler() HandlerFunc }
type Router ¶
type Router interface { GET(path string, handler HandlerFunc) error POST(path string, handler HandlerFunc) error PUT(path string, handler HandlerFunc) error PATCH(path string, handler HandlerFunc) error DELETE(path string, handler HandlerFunc) error HEAD(path string, handler HandlerFunc) error OPTIONS(path string, handler HandlerFunc) error TRACE(path string, handler HandlerFunc) error CONNECT(path string, handler HandlerFunc) error GetRoutesByMethod(method string) *route // contains filtered or unexported methods }
type UnitWorkflow ¶ added in v1.3.0
type UnitWorkflow struct {
// contains filtered or unexported fields
}
type WorkflowFunc ¶ added in v1.3.0
type WorkflowFunc func() error
Source Files ¶
Click to show internal directories.
Click to hide internal directories.