web

package
v0.5.1 Latest Latest
Warning

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

Go to latest
Published: Mar 17, 2026 License: Apache-2.0 Imports: 34 Imported by: 1

Documentation

Index

Constants

View Source
const (
	GetNotSupportJson = "JSON parameters are not supported in GET requests"
)
View Source
const MaxHeaderBytes = 8192
View Source
const MaxReadHeaderTimeout = time.Second * 30
View Source
const MaxReadTimeout = time.Minute * 10
View Source
const ServerConfigKey = "web.server"

Variables

This section is empty.

Functions

func SaveUploadedFile added in v0.1.3

func SaveUploadedFile(file *multipart.FileHeader, dst string) error

Types

type CertManager added in v0.1.1

type CertManager struct {
	// contains filtered or unexported fields
}

func NewCertManager added in v0.1.1

func NewCertManager() *CertManager

func (*CertManager) AddHost added in v0.1.1

func (cm *CertManager) AddHost(host string)

func (*CertManager) AddPort added in v0.1.1

func (cm *CertManager) AddPort(port int)

func (*CertManager) GetCertManager added in v0.1.1

func (cm *CertManager) GetCertManager() (*autocert.Manager, error)

func (*CertManager) GetPEM added in v0.1.4

func (cm *CertManager) GetPEM(host string) (certPEM []byte, keyPEM []byte, err error)

func (*CertManager) HasTLS added in v0.1.3

func (cm *CertManager) HasTLS() bool

func (*CertManager) Run added in v0.1.3

func (cm *CertManager) Run(ctx context.Context) error

type Converter added in v0.1.3

type Converter interface {
	Request(filterChain FilterChain, request *Request)
}
type Cookie struct {
	// contains filtered or unexported fields
}

func NewCookie

func NewCookie(c *gin.Context) *Cookie

func (*Cookie) Delete

func (c *Cookie) Delete(key string)

func (*Cookie) Expire

func (c *Cookie) Expire(key string)

func (*Cookie) Forever

func (c *Cookie) Forever(key string, value string)

func (*Cookie) ForeverDomain

func (c *Cookie) ForeverDomain(domain string, key string, value string)

func (*Cookie) Get

func (c *Cookie) Get(key string) string

func (*Cookie) Set

func (c *Cookie) Set(key string, value string)

func (*Cookie) SetDomain

func (c *Cookie) SetDomain(domain string, key string, value string)

func (*Cookie) SetWithExpire

func (c *Cookie) SetWithExpire(key string, value string, expire int)

func (*Cookie) Update

func (c *Cookie) Update(key string, value string)

type DefaultConverter added in v0.1.3

type DefaultConverter struct {
}

func (*DefaultConverter) Request added in v0.1.3

func (c *DefaultConverter) Request(filterChain FilterChain, request *Request)

type File

type File struct {
	Path     string
	FileName string
	Suffix   string
}

type Filter added in v0.1.3

type Filter interface {
	Handle(filterChain FilterChain, request *Request) (any, error)
}

type FilterChain added in v0.1.3

type FilterChain interface {
	Next() (any, error)
}

type HandlerConfig added in v0.1.3

type HandlerConfig struct {
	// contains filtered or unexported fields
}

func NewHandlerConfig added in v0.1.3

func NewHandlerConfig(converter Converter, handles *Handles) *HandlerConfig

func (*HandlerConfig) Handle added in v0.1.3

func (h *HandlerConfig) Handle(httpMethods []string, relativePath string, handlers ...HandlerFunc) *HandlerInfo

func (*HandlerConfig) HandlerMeta added in v0.1.3

func (h *HandlerConfig) HandlerMeta(httpMethod string, fullPath string) *HandlerMeta

func (*HandlerConfig) Handles added in v0.1.3

func (h *HandlerConfig) Handles() *Handles

func (*HandlerConfig) HasHandler added in v0.1.3

func (h *HandlerConfig) HasHandler(httpMethod string, fullPath string) bool

func (*HandlerConfig) Use added in v0.1.3

func (h *HandlerConfig) Use(handlers ...Filter)

type HandlerFunc

type HandlerFunc func(*Request) (any, error)

type HandlerInfo added in v0.1.3

type HandlerInfo struct {
	// contains filtered or unexported fields
}

func NewHandlerInfo added in v0.1.3

func NewHandlerInfo(path string, handlers ...HandlerFunc) *HandlerInfo

func (*HandlerInfo) HandlerFunc added in v0.1.3

func (hi *HandlerInfo) HandlerFunc() []HandlerFunc

func (*HandlerInfo) RelativePath added in v0.1.3

func (hi *HandlerInfo) RelativePath() string

func (*HandlerInfo) WithMeta added in v0.1.3

func (hi *HandlerInfo) WithMeta(mo ...MetaOption) *HandlerInfo

type HandlerMeta added in v0.1.3

type HandlerMeta struct {
	// contains filtered or unexported fields
}

func NewHandlerMeta added in v0.1.3

func NewHandlerMeta() *HandlerMeta

func (*HandlerMeta) Add added in v0.1.3

func (hm *HandlerMeta) Add(key string, value any)

func (*HandlerMeta) Get added in v0.1.3

func (hm *HandlerMeta) Get(key string) any

func (*HandlerMeta) Has added in v0.1.3

func (hm *HandlerMeta) Has(key string) bool

type HandlersChain added in v0.1.1

type HandlersChain []HandlerFunc

func Of added in v0.1.1

func Of(handlerFunc ...HandlerFunc) HandlersChain

func (HandlersChain) GetFuncName added in v0.1.1

func (c HandlersChain) GetFuncName() string

func (HandlersChain) Last added in v0.1.1

func (c HandlersChain) Last() HandlerFunc

type Handles added in v0.1.3

type Handles struct {
	// contains filtered or unexported fields
}

func NewHandles added in v0.1.3

func NewHandles() *Handles

func (*Handles) Handle added in v0.1.3

func (h *Handles) Handle(httpMethod string, relativePath string, handlers ...HandlerFunc) *HandlerInfo

func (*Handles) HandlerMeta added in v0.1.3

func (h *Handles) HandlerMeta(httpMethod string, fullPath string) *HandlerMeta

func (*Handles) Handles added in v0.1.3

func (h *Handles) Handles(httpMethods []string, relativePath string, handlers ...HandlerFunc) *HandlerInfo

func (*Handles) HasHandler added in v0.1.3

func (h *Handles) HasHandler(httpMethod string, fullPath string) bool

func (*Handles) RouteTree added in v0.1.3

func (h *Handles) RouteTree() RouteTree

type HttpServer added in v0.1.1

type HttpServer struct {
	// contains filtered or unexported fields
}

func NewHttpServer added in v0.1.1

func NewHttpServer(serverConfig *ServerConfig, certManager *CertManager) *HttpServer

func (*HttpServer) Close added in v0.1.1

func (httpServer *HttpServer) Close() error

func (*HttpServer) Handle added in v0.1.2

func (httpServer *HttpServer) Handle(handlerConfig *HandlerConfig)

func (*HttpServer) Port added in v0.1.1

func (httpServer *HttpServer) Port() int

func (*HttpServer) Run added in v0.1.1

func (httpServer *HttpServer) Run(ctx context.Context) error

func (*HttpServer) ToGinHandlerFunc added in v0.1.3

func (httpServer *HttpServer) ToGinHandlerFunc(handlerConfig *HandlerConfig, handlers ...HandlerFunc) []gin.HandlerFunc

type JsonObject

type JsonObject map[string]any

func (JsonObject) Add added in v0.1.3

func (o JsonObject) Add(key string, value any)

func (JsonObject) GetInt

func (o JsonObject) GetInt(key string) int

func (JsonObject) GetIntForDefault

func (o JsonObject) GetIntForDefault(key string, defaultValue int) int

func (JsonObject) GetString

func (o JsonObject) GetString(key string) string

type MemFileSystem added in v0.1.2

type MemFileSystem struct {
	// contains filtered or unexported fields
}

func DefaultMemFileSystem added in v0.1.2

func DefaultMemFileSystem(serverConfig *ServerConfig) *MemFileSystem

func NewMemFileSystem added in v0.1.2

func NewMemFileSystem(cacheTime time.Duration, serverConfig *ServerConfig) *MemFileSystem

func (*MemFileSystem) Exists added in v0.1.2

func (m *MemFileSystem) Exists(name string) (bool, error)

func (*MemFileSystem) Open added in v0.1.2

func (m *MemFileSystem) Open(name string) (http.File, error)

func (*MemFileSystem) Stat added in v0.1.2

func (m *MemFileSystem) Stat(name string) (os.FileInfo, error)

type Message

type Message struct {
	Code int    `json:"code"`
	Data any    `json:"data"`
	Msg  string `json:"msg"`
	Type string `json:"type"`
}

func Data

func Data(data any) *Message

func DataCode added in v0.1.1

func DataCode(code int, data any) *Message

func DataType added in v0.1.1

func DataType(t string, data any) *Message

func Error

func Error(err ...error) *Message

func ErrorMessage

func ErrorMessage(msg ...string) *Message

func Errors

func Errors(data any, msg ...error) *Message

func Ok

func Ok(msg ...string) *Message

func Redirect added in v0.1.1

func Redirect(url string) *Message

func Unauthorized

func Unauthorized(data any, msg ...error) *Message

func (*Message) IsOK

func (msg *Message) IsOK() bool

type MetaOption added in v0.1.3

type MetaOption interface {
	// contains filtered or unexported methods
}

func WithKey added in v0.1.3

func WithKey(keys ...string) MetaOption

func WithValue added in v0.1.3

func WithValue(key string, value any) MetaOption

type Page

type Page struct {
	PageNo   int
	PageSize int
	LastId   int
}

type PageAble

type PageAble[T any] struct {
	Total int64 `json:"total"`
	List  []T   `json:"list"`
}

func ToPage

func ToPage[T any](total int64, list []T) *PageAble[T]

type Request

type Request struct {
	// contains filtered or unexported fields
}

func NewRequest

func NewRequest(c *gin.Context, response Response, handlerMeta *HandlerMeta) *Request

func (*Request) BindJSON

func (r *Request) BindJSON(value any) error

func (*Request) ClientIP added in v0.5.1

func (r *Request) ClientIP() string

func (*Request) ContentType added in v0.1.3

func (r *Request) ContentType() string

func (*Request) Cookie

func (r *Request) Cookie() *Cookie

func (*Request) Domain

func (r *Request) Domain() string

func (*Request) FormParamsPage

func (r *Request) FormParamsPage() (*Page, error)

func (*Request) FullPath added in v0.1.2

func (r *Request) FullPath() string

func (*Request) GetFormParam

func (r *Request) GetFormParam(key string) string

func (*Request) GetHeader added in v0.1.3

func (r *Request) GetHeader(s string) string

func (*Request) GetIntFormParam

func (r *Request) GetIntFormParam(key string) int

func (*Request) GetIntFormParamOrDefault

func (r *Request) GetIntFormParamOrDefault(key string, defaultValue int) int

func (*Request) GetJsonIntValue

func (r *Request) GetJsonIntValue(key string) (int, error)

func (*Request) GetJsonIntValueOrDefault

func (r *Request) GetJsonIntValueOrDefault(key string, defaultValue int) int

func (*Request) GetJsonStringValue

func (r *Request) GetJsonStringValue(key string) (string, error)

func (*Request) GetJsonStringValueOrDefault

func (r *Request) GetJsonStringValueOrDefault(key string, defaultValue string) string

func (*Request) GinContext added in v0.1.1

func (r *Request) GinContext() *gin.Context

func (*Request) HandlerMeta added in v0.1.3

func (r *Request) HandlerMeta() *HandlerMeta

func (*Request) IsGet

func (r *Request) IsGet() bool

func (*Request) IsMultipartForm added in v0.1.3

func (r *Request) IsMultipartForm() bool

func (*Request) IsPost

func (r *Request) IsPost() bool

func (*Request) Json

func (r *Request) Json() (*JsonObject, error)

func (*Request) JsonPage

func (r *Request) JsonPage() (*Page, error)

func (*Request) MultipartForm added in v0.1.3

func (r *Request) MultipartForm() (*multipart.Form, error)

func (*Request) Page

func (r *Request) Page() (*Page, error)

func (*Request) Param added in v0.1.1

func (r *Request) Param(key string) string

func (*Request) ParamInt added in v0.1.2

func (r *Request) ParamInt(key string) int

func (*Request) ParamIntForDefault added in v0.5.1

func (r *Request) ParamIntForDefault(key string, defaultValue int) int

func (*Request) ParamUint added in v0.1.2

func (r *Request) ParamUint(key string) uint

func (*Request) Query added in v0.1.2

func (r *Request) Query(key string) string

func (*Request) RemoteAddr

func (r *Request) RemoteAddr() string

func (*Request) RemoteIp added in v0.1.3

func (r *Request) RemoteIp() string

RemoteIp 返回真实客户端 IP,支持从 X-Forwarded-For 获取

func (*Request) Request added in v0.1.3

func (r *Request) Request() *http.Request

func (*Request) Response added in v0.1.3

func (r *Request) Response() Response

func (*Request) URL added in v0.1.3

func (r *Request) URL() *url.URL

type Response

type Response interface {
	gin.ResponseWriter
	SetAttachmentFileName(fileName string)
	JSON(code int, value any)
	Abort()
	Redirect(code int, location string)
	FileAttachment(path string, name string)
	WriteStatus(code int)
	Message(t *Message)
	AbortWithMessage(t *Message)
	AbortWithStatusJSON(i int, value any)
	AbortWithError(err error) error
}

type ResponseWriteCloser

type ResponseWriteCloser struct {
	// contains filtered or unexported fields
}

func CreateResponseWriteCloser

func CreateResponseWriteCloser(response Response) *ResponseWriteCloser

func (*ResponseWriteCloser) Close

func (w *ResponseWriteCloser) Close() error

func (*ResponseWriteCloser) Write

func (w *ResponseWriteCloser) Write(p []byte) (n int, err error)

type RouteInfo added in v0.1.3

type RouteInfo []*HandlerInfo

type RouteTree added in v0.1.3

type RouteTree map[string]RouteInfo

func (RouteTree) GetHandlerMeta added in v0.1.3

func (rt RouteTree) GetHandlerMeta(method, path string) *HandlerMeta

func (RouteTree) Has added in v0.1.3

func (rt RouteTree) Has(method, path string) bool

func (RouteTree) Set added in v0.1.3

func (rt RouteTree) Set(method string, handlerInfo *HandlerInfo)

type SSLConfig added in v0.1.1

type SSLConfig struct {
	Enabled bool
	Hosts   []string
}

type ServerConfig added in v0.1.1

type ServerConfig struct {
	Port      int
	Locations []string
	Page404   string
	SSL       *SSLConfig
}

func DefaultServerConfig added in v0.1.1

func DefaultServerConfig() *ServerConfig

func (*ServerConfig) SSLEnabled added in v0.1.1

func (s *ServerConfig) SSLEnabled() bool

Jump to

Keyboard shortcuts

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