Documentation ¶
Index ¶
- Variables
- func AddFileUpload(path string)
- func AutoTransaction[reqModel any](next func(ctx *Context, query reqModel) (interface{}, error)) func(ctx *Context, query reqModel) (interface{}, error)
- func CallEncodeApi[respModel any](url string, postdata []byte, base64key string) (bool, *respModel)
- func CustomXSSMiddleWare[reqModel any](next func(ctx *Context, query reqModel) (interface{}, error)) func(ctx *Context, query reqModel) (interface{}, error)
- func EventStream[reqModel any](path string, ...)
- func Get[reqModel any](path string, next func(ctx *Context, query reqModel) (interface{}, error), ...)
- func HandleApiWithEncode[reqModel any](mux *HttpApiRoute, path string, ...)
- func JTWMiddleWarex(w http.ResponseWriter, r *http.Request)
- func Post[reqModel any](path string, ...)
- func RetCode(w http.ResponseWriter, ret *ResponseDataProvider)
- func ReusableReader(r io.Reader) io.Reader
- func RunMiddlewareX(d []MiddlewareX, ctx *Context) (Abort bool)
- func UploadFile(w http.ResponseWriter, r *http.Request)
- type Context
- type HttpApiRoute
- func (c *HttpApiRoute) AppendApiDoc(i *postman.Items)
- func (ccc *HttpApiRoute) CreateApi()
- func (ccc *HttpApiRoute) CreateApiForHttp(w io.Writer)
- func (c *HttpApiRoute) Handle(pattern string, handler http.Handler)
- func (c *HttpApiRoute) HandleFunc(pattern string, handler func(http.ResponseWriter, *http.Request))
- func (c *HttpApiRoute) Handler(r *http.Request) (h http.Handler, pattern string)
- func (c *HttpApiRoute) ServeHTTP(w http.ResponseWriter, r *http.Request)
- type HttpApiRouteHandler
- type MiddlewareX
- type ResponseDataProvider
- type ServerProvider
- type SessionMiddleWare
- type SesssionStore
- type SqlInjectMiddleWare
- type XSSMiddleWare
Constants ¶
This section is empty.
Variables ¶
View Source
var SkipSqlInjectUrl []string
View Source
var UploadFilePath = "."
View Source
var UploadFilePermission fs.FileMode = 0777
Functions ¶
func AddFileUpload ¶
func AddFileUpload(path string)
func AutoTransaction ¶
func CustomXSSMiddleWare ¶
func CustomXSSMiddleWare[reqModel any](next func(ctx *Context, query reqModel) (interface{}, error)) func(ctx *Context, query reqModel) (interface{}, error)
next func(ctx *Context, query reqModel) (interface{}, error)
func EventStream ¶
func EventStream[reqModel any](path string, next func(ctx *Context, req reqModel, w http.ResponseWriter) (data interface{}, err error))
Create Event stream API
Post 参数定义如下 不区分POST GET 等相关问题 ¶
path string
next func(w http.ResponseWriter, r *http.Request, respData []byte, obj reqModel) (data interface{}, err error)
enableValidate bool 默认开启
func Get ¶
func Get[reqModel any](path string, next func(ctx *Context, query reqModel) (interface{}, error), enableCache bool)
AddGetRoute 将丢弃BODY数据,只返回URL query 数据
func HandleApiWithEncode ¶
func HandleApiWithEncode[reqModel any](mux *HttpApiRoute, path string, next func(w http.ResponseWriter, r *http.Request, respData []byte, obj reqModel) (data interface{}, err error), base64Key string, enableValidate bool)
拥有 data 加密 和 字段校验的函数
func JTWMiddleWarex ¶
func JTWMiddleWarex(w http.ResponseWriter, r *http.Request)
func Post ¶
func Post[reqModel any](path string, next func(ctx *Context, req reqModel) (data interface{}, err error), enableCache bool)
Post 参数定义如下 不区分POST GET 等相关问题
path string
next func(w http.ResponseWriter, r *http.Request, respData []byte, obj reqModel) (data interface{}, err error)
enableValidate bool 默认开启
func RetCode ¶
func RetCode(w http.ResponseWriter, ret *ResponseDataProvider)
func RunMiddlewareX ¶
func RunMiddlewareX(d []MiddlewareX, ctx *Context) (Abort bool)
func UploadFile ¶
func UploadFile(w http.ResponseWriter, r *http.Request)
Types ¶
type Context ¶
type Context struct { Session SesssionStore W http.ResponseWriter R *http.Request RawBody []byte //有些时候各种中间件将处理RawBody数据 , 已知 xss 中间件会修改Body Tx *gorm.DB // }
type HttpApiRoute ¶
type HttpApiRoute struct {
// contains filtered or unexported fields
}
func New ¶
func New() *HttpApiRoute
func (*HttpApiRoute) AppendApiDoc ¶
func (c *HttpApiRoute) AppendApiDoc(i *postman.Items)
func (*HttpApiRoute) CreateApi ¶
func (ccc *HttpApiRoute) CreateApi()
func (*HttpApiRoute) CreateApiForHttp ¶
func (ccc *HttpApiRoute) CreateApiForHttp(w io.Writer)
func (*HttpApiRoute) HandleFunc ¶
func (c *HttpApiRoute) HandleFunc(pattern string, handler func(http.ResponseWriter, *http.Request))
func (*HttpApiRoute) ServeHTTP ¶
func (c *HttpApiRoute) ServeHTTP(w http.ResponseWriter, r *http.Request)
type HttpApiRouteHandler ¶
type HttpApiRouteHandler struct {
// contains filtered or unexported fields
}
func (HttpApiRouteHandler) ServeHTTP ¶
func (h HttpApiRouteHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)
type MiddlewareX ¶
type ResponseDataProvider ¶
func (*ResponseDataProvider) IsOk ¶
func (r *ResponseDataProvider) IsOk() bool
type ServerProvider ¶
type ServerProvider struct { InternalMux *HttpApiRoute Middleware []MiddlewareX // contains filtered or unexported fields }
func Provider ¶
func Provider() *ServerProvider
func (*ServerProvider) AddMux ¶
func (sp *ServerProvider) AddMux(internalMux *HttpApiRoute)
type SessionMiddleWare ¶
type SessionMiddleWare struct { }
func (SessionMiddleWare) Enable ¶
func (x SessionMiddleWare) Enable() bool
func (SessionMiddleWare) Handle ¶
func (x SessionMiddleWare) Handle(w http.ResponseWriter, r *http.Request) (Abort bool)
func (SessionMiddleWare) Name ¶
func (x SessionMiddleWare) Name() string
type SesssionStore ¶
type SesssionStore interface { // Get a session storage context Context() context.Context // Get the current session id SessionID() string // Set session value, call save function to take effect Set(key string, value interface{}) // Get session value Get(key string) (interface{}, bool) // Delete session value, call save function to take effect Delete(key string) interface{} // Save session data Save() error // Clear all session data Flush() error }
type SqlInjectMiddleWare ¶
type SqlInjectMiddleWare struct { }
func (SqlInjectMiddleWare) Enable ¶
func (x SqlInjectMiddleWare) Enable() bool
func (SqlInjectMiddleWare) Handle ¶
func (x SqlInjectMiddleWare) Handle(ctx *Context) bool
func (SqlInjectMiddleWare) Name ¶
func (x SqlInjectMiddleWare) Name() string
type XSSMiddleWare ¶
type XSSMiddleWare struct { }
r.Body = io.NopCloser(ReusableReader(r.Body))
func (XSSMiddleWare) Enable ¶
func (x XSSMiddleWare) Enable() bool
func (XSSMiddleWare) Handle ¶
func (x XSSMiddleWare) Handle(ctx *Context) bool
func (XSSMiddleWare) Name ¶
func (x XSSMiddleWare) Name() string
Click to show internal directories.
Click to hide internal directories.