web

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Jan 4, 2026 License: Apache-2.0 Imports: 22 Imported by: 0

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

View Source
var NoLogin = &NoLoginError{}

Functions

func ToGinHandlerFunc

func ToGinHandlerFunc(digestAuth *DigestAuth, handlers ...HandlerFunc) []gin.HandlerFunc

func ToGinHandlerRawFunc

func ToGinHandlerRawFunc(digestAuth *DigestAuth, handlers ...HandlerRawFunc) []gin.HandlerFunc

func User

func User[T any](r *Request) (T, error)

Types

type Authentication

type Authentication interface {
	SignIn(user any, request *Request) (any, error)
	SignOut(request *Request) (any, error)
	User(request *Request) (any, error)
	NewUser() any
}

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) Start added in v0.1.1

func (cm *CertManager) Start()
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 DigestAuth

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

func NewDigestAuth

func NewDigestAuth(authentication Authentication) *DigestAuth

func (*DigestAuth) Authentication

func (digestAuth *DigestAuth) Authentication() Authentication

func (*DigestAuth) SignIn

func (digestAuth *DigestAuth) SignIn(user any, request *Request) (any, error)

func (*DigestAuth) SignOut

func (digestAuth *DigestAuth) SignOut(r *Request) (any, error)

func (*DigestAuth) User

func (digestAuth *DigestAuth) User(request *Request) (any, error)

type File

type File struct {
	Path     string
	FileName string
	Suffix   string
}

type HandlerFunc

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

func AuthChecks

func AuthChecks(handlers ...HandlerFunc) []HandlerFunc

type HandlerRawFunc

type HandlerRawFunc func(*Request, Response) error

func AuthRawChecks

func AuthRawChecks(handlers ...HandlerRawFunc) []HandlerRawFunc

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 HandlersRawChain added in v0.1.1

type HandlersRawChain []HandlerRawFunc

func OfRaw added in v0.1.1

func OfRaw(handlerRawFunc ...HandlerRawFunc) HandlersRawChain

func (HandlersRawChain) GetFuncName added in v0.1.1

func (c HandlersRawChain) GetFuncName() string

func (HandlersRawChain) Last added in v0.1.1

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) Any added in v0.1.2

func (httpServer *HttpServer) Any(relativePath string, handlers ...gin.HandlerFunc)

func (*HttpServer) Close added in v0.1.1

func (httpServer *HttpServer) Close() error

func (*HttpServer) DELETE added in v0.1.2

func (httpServer *HttpServer) DELETE(relativePath string, handlers ...gin.HandlerFunc)

func (*HttpServer) GET added in v0.1.1

func (httpServer *HttpServer) GET(relativePath string, handlers ...gin.HandlerFunc)

func (*HttpServer) Handle added in v0.1.2

func (httpServer *HttpServer) Handle(httpMethod string, relativePath string, handlers ...gin.HandlerFunc)

func (*HttpServer) POST added in v0.1.1

func (httpServer *HttpServer) POST(relativePath string, handlers ...gin.HandlerFunc)

func (*HttpServer) PUT added in v0.1.2

func (httpServer *HttpServer) PUT(relativePath string, handlers ...gin.HandlerFunc)

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() error

func (*HttpServer) Use added in v0.1.2

func (httpServer *HttpServer) Use(handlers ...gin.HandlerFunc)

type JsonObject

type JsonObject map[string]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 NoLoginError

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

func (*NoLoginError) Error

func (e *NoLoginError) Error() string

type Page

type Page struct {
	PageNo   int
	PageSize int
	LastId   int
}

type PageAble

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

func ToPage

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

type Request

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

func NewRequest

func NewRequest(c *gin.Context, digestAuth *DigestAuth) *Request

func (*Request) Abort added in v0.1.2

func (r *Request) Abort()

func (*Request) BindJSON

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

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

func (r *Request) GetDigestAuth() *DigestAuth

func (*Request) GetFormParam

func (r *Request) GetFormParam(key 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) IsGet

func (r *Request) IsGet() bool

func (*Request) IsPost

func (r *Request) IsPost() bool

func (*Request) JSON added in v0.1.2

func (r *Request) JSON(code int, value any)

func (*Request) Json

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

func (*Request) JsonPage

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

func (*Request) Message added in v0.1.2

func (r *Request) Message(t *Message)

func (*Request) Next added in v0.1.2

func (r *Request) Next()

Next should be used only inside middleware. It executes the pending handlers in the chain inside the calling handler. See example in GitHub.

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

Query returns the keyed url query value if it exists, otherwise it returns an empty string `("")`. It is shortcut for `c.Request.URL.Query().Get(key)`

    GET /path?id=1234&name=Manu&value=
	   c.Query("id") == "1234"
	   c.Query("name") == "Manu"
	   c.Query("value") == ""
	   c.Query("wtf") == ""

func (*Request) RemoteAddr

func (r *Request) RemoteAddr() string

func (*Request) SignIn

func (r *Request) SignIn(user any) (any, error)

func (*Request) SignOut

func (r *Request) SignOut() (any, error)

func (*Request) User

func (r *Request) User() (any, error)

type Response

type Response interface {
	gin.ResponseWriter
	SetAttachmentFileName(fileName string)
}

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