httpapi

package
v0.0.0-...-b4442d7 Latest Latest
Warning

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

Go to latest
Published: Apr 9, 2024 License: GPL-3.0 Imports: 30 Imported by: 2

Documentation

Index

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 AutoTransaction[reqModel any](next func(ctx *Context, query reqModel) (interface{}, error)) func(ctx *Context, query reqModel) (interface{}, error)

func CallEncodeApi

func CallEncodeApi[respModel any](url string, postdata []byte, base64key string) (bool, *respModel)

CallEncodeApi 调用 MyHandleMiddlewareY2 加密服务器

xmodel 返回的结构体 respModel

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 ReusableReader

func ReusableReader(r io.Reader) io.Reader

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) Handle

func (c *HttpApiRoute) Handle(pattern string, handler http.Handler)

func (*HttpApiRoute) HandleFunc

func (c *HttpApiRoute) HandleFunc(pattern string, handler func(http.ResponseWriter, *http.Request))

func (*HttpApiRoute) Handler

func (c *HttpApiRoute) Handler(r *http.Request) (h http.Handler, pattern string)

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 MiddlewareX interface {
	Handle(ctx *Context) (Abort bool)
	Enable() bool
	Name() string
}

type ResponseDataProvider

type ResponseDataProvider struct {
	Code string
	Msg  string
	Data interface{}
}

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)

func (*ServerProvider) RunServer

func (sp *ServerProvider) RunServer(Addr string, xtls *tls.Config)

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

Jump to

Keyboard shortcuts

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