Documentation ¶
Index ¶
- Constants
- Variables
- func BindJSON[T any](c *Context) (t *T, err error)
- func Dir(root string, listDirectory bool) http.FileSystem
- func Error(msg string, args ...any)
- func Info(msg string, args ...any)
- func ParseFromRequest(req *http.Request, publicKeyPath string) (uniqueUser, issuer, signature string, err error)
- func SetAuthToken(uniqueUser, issuer, privateKeyPath string, expire time.Duration) (tokenString string, err error)
- func Warn(msg string, args ...any)
- type Context
- func (c *Context) BindHeader(obj any) error
- func (c *Context) BindJSON(obj any) error
- func (c *Context) BindQuery(obj any) error
- func (c *Context) ClientIP() string
- func (c *Context) ContentType() string
- func (c *Context) Cookie(name string) (string, error)
- func (c *Context) Deadline() (deadline time.Time, ok bool)
- func (c *Context) DefaultPostForm(key, defaultValue string) string
- func (c *Context) DefaultQuery(key, defaultValue string) string
- func (c *Context) Done() <-chan struct{}
- func (c *Context) Err() error
- func (c *Context) File(filepath string)
- func (c *Context) FormFile(name string) (*multipart.FileHeader, error)
- func (c *Context) Get(key string) (value any, exists bool)
- func (c *Context) GetBool(key string) (b bool)
- func (c *Context) GetDuration(key string) (d time.Duration)
- func (c *Context) GetFloat64(key string) (f64 float64)
- func (c *Context) GetHeader(key string) string
- func (c *Context) GetInt(key string) (i int)
- func (c *Context) GetInt64(key string) (i64 int64)
- func (c *Context) GetPostForm(key string) (string, bool)
- func (c *Context) GetPostFormArray(key string) (values []string, ok bool)
- func (c *Context) GetQuery(key string) (string, bool)
- func (c *Context) GetQueryArray(key string) (values []string, ok bool)
- func (c *Context) GetString(key string) (s string)
- func (c *Context) GetStringMap(key string) (sm map[string]any)
- func (c *Context) GetStringMapString(key string) (sms map[string]string)
- func (c *Context) GetStringMapStringSlice(key string) (smss map[string][]string)
- func (c *Context) GetStringSlice(key string) (ss []string)
- func (c *Context) GetTime(key string) (t time.Time)
- func (c *Context) GetUint(key string) (ui uint)
- func (c *Context) GetUint64(key string) (ui64 uint64)
- func (c *Context) HTML(code int, name string, obj any)
- func (c *Context) Header(key, value string)
- func (c *Context) JSON(status int, data any) error
- func (c *Context) MustBindWith(obj any, b binding.Binding) error
- func (c *Context) Param(key string) string
- func (c *Context) PostForm(key string) (value string)
- func (c *Context) PostFormArray(key string) (values []string)
- func (c *Context) Query(key string) (value string)
- func (c *Context) QueryArray(key string) (values []string)
- func (c *Context) Redirect(code int, location string)
- func (c *Context) RemoteIP() string
- func (c *Context) Render(code int, r render.Render)
- func (c *Context) SaveUploadedFile(file *multipart.FileHeader, dst string) error
- func (c *Context) Set(key string, value any)
- func (c *Context) SetCookie(name, value string, maxAge int, path, domain string, secure, httpOnly bool)
- func (c *Context) SetSameSite(sameSite http.SameSite)
- func (c *Context) ShouldBind(obj any) error
- func (c *Context) ShouldBindJSON(obj any) error
- func (c *Context) ShouldBindQuery(obj any) error
- func (c *Context) ShouldBindWith(obj any, b binding.Binding) error
- func (c *Context) Status(code int)
- func (c *Context) Text(code int, format string, values ...any)
- func (c *Context) Value(key any) any
- type Err
- type H
- type Handler
- type HandlerFunc
- type HttpHandler
- type Middleware
- type Router
- func (r *Router) Delete(route string, handler HandlerFunc)
- func (r *Router) GET(route string, handler HandlerFunc)
- func (r *Router) Group(prefix string) *Router
- func (r *Router) HEAD(route string, handler HandlerFunc)
- func (r *Router) Method(method, route string, handler HandlerFunc)
- func (r *Router) OPTIONS(route string, handlers HandlerFunc)
- func (r *Router) POST(route string, handler HandlerFunc)
- func (r *Router) Patch(route string, handler HandlerFunc)
- func (r *Router) Put(route string, handler HandlerFunc)
- func (r *Router) Static(relativePath, root string) *Router
- func (r *Router) StaticFS(relativePath string, fs http.FileSystem) *Router
- func (r *Router) StaticFile(relativePath, filepath string) *Router
- func (r *Router) Use(middlewares ...Middleware)
- type RouterHandler
- type ServerBase
- type ServerFinalizerFunc
- type ServerOption
- type Service
- type Water
Constants ¶
View Source
const (
ContextKey = "_go-water/context-key"
)
View Source
const Version = "v0.9.7"
Variables ¶
View Source
var MaxMultipartMemory int64 = 32 << 20 // 32 MB
Functions ¶
func Dir ¶ added in v0.6.0
func Dir(root string, listDirectory bool) http.FileSystem
Dir returns a http.FileSystem that can be used by http.FileServer(). It is used internally in router.Static(). if listDirectory == true, then it works the same as http.Dir() otherwise it returns a filesystem that prevents http.FileServer() to list the directory files.
func ParseFromRequest ¶ added in v0.2.6
func ParseFromRequest(req *http.Request, publicKeyPath string) (uniqueUser, issuer, signature string, err error)
ParseFromRequest 兼容 http,ws
func SetAuthToken ¶ added in v0.2.0
Types ¶
type Context ¶ added in v0.5.0
type Context struct { Request *http.Request Writer http.ResponseWriter Keys map[string]any // contains filtered or unexported fields }
func (*Context) BindHeader ¶ added in v0.9.1
func (*Context) ContentType ¶ added in v0.8.4
func (*Context) DefaultPostForm ¶ added in v0.8.6
func (*Context) DefaultQuery ¶ added in v0.8.6
func (*Context) FormFile ¶ added in v0.6.0
func (c *Context) FormFile(name string) (*multipart.FileHeader, error)
func (*Context) GetDuration ¶ added in v0.8.8
func (*Context) GetFloat64 ¶ added in v0.8.8
func (*Context) GetPostForm ¶ added in v0.8.6
func (*Context) GetPostFormArray ¶ added in v0.8.6
func (*Context) GetQueryArray ¶ added in v0.8.6
func (*Context) GetStringMap ¶ added in v0.8.8
func (*Context) GetStringMapString ¶ added in v0.8.8
func (*Context) GetStringMapStringSlice ¶ added in v0.8.8
func (*Context) GetStringSlice ¶ added in v0.8.8
func (*Context) MustBindWith ¶ added in v0.9.1
func (*Context) PostFormArray ¶ added in v0.8.6
func (*Context) QueryArray ¶ added in v0.8.6
func (*Context) SaveUploadedFile ¶ added in v0.6.0
func (c *Context) SaveUploadedFile(file *multipart.FileHeader, dst string) error
func (*Context) SetSameSite ¶ added in v0.7.0
func (*Context) ShouldBind ¶ added in v0.8.2
func (*Context) ShouldBindJSON ¶ added in v0.5.0
func (*Context) ShouldBindQuery ¶ added in v0.9.1
func (*Context) ShouldBindWith ¶ added in v0.5.0
type Handler ¶
type Handler interface { ServerWater(ctx context.Context, req any) (any, error) GetLogger() *slog.Logger }
func NewHandler ¶
func NewHandler(srv Service, options ...ServerOption) Handler
type HandlerFunc ¶ added in v0.5.0
type HandlerFunc func(*Context)
type Middleware ¶ added in v0.6.0
type Middleware func(HandlerFunc) HandlerFunc
type Router ¶ added in v0.5.0
type Router struct {
// contains filtered or unexported fields
}
func (*Router) Delete ¶ added in v0.8.0
func (r *Router) Delete(route string, handler HandlerFunc)
func (*Router) GET ¶ added in v0.6.0
func (r *Router) GET(route string, handler HandlerFunc)
func (*Router) HEAD ¶ added in v0.6.0
func (r *Router) HEAD(route string, handler HandlerFunc)
func (*Router) Method ¶ added in v0.5.0
func (r *Router) Method(method, route string, handler HandlerFunc)
func (*Router) OPTIONS ¶ added in v0.8.0
func (r *Router) OPTIONS(route string, handlers HandlerFunc)
func (*Router) POST ¶ added in v0.6.0
func (r *Router) POST(route string, handler HandlerFunc)
func (*Router) Patch ¶ added in v0.8.0
func (r *Router) Patch(route string, handler HandlerFunc)
func (*Router) Put ¶ added in v0.8.0
func (r *Router) Put(route string, handler HandlerFunc)
func (*Router) StaticFS ¶ added in v0.6.0
func (r *Router) StaticFS(relativePath string, fs http.FileSystem) *Router
func (*Router) StaticFile ¶ added in v0.6.0
func (*Router) Use ¶ added in v0.5.0
func (r *Router) Use(middlewares ...Middleware)
type RouterHandler ¶ added in v0.8.0
type RouterHandler struct {
// contains filtered or unexported fields
}
func (*RouterHandler) ServeHTTP ¶ added in v0.8.0
func (r *RouterHandler) ServeHTTP(w http.ResponseWriter, req *http.Request)
type ServerBase ¶ added in v0.0.12
type ServerBase struct {
// contains filtered or unexported fields
}
func (*ServerBase) GetLogger ¶ added in v0.0.18
func (s *ServerBase) GetLogger() *slog.Logger
func (*ServerBase) Name ¶ added in v0.0.12
func (s *ServerBase) Name(srv Service) string
func (*ServerBase) SetLogger ¶ added in v0.0.19
func (s *ServerBase) SetLogger(l *slog.Logger)
type ServerFinalizerFunc ¶
type ServerOption ¶
type ServerOption func(h *handler)
func ServerBreaker ¶ added in v0.3.3
func ServerBreaker(breaker *gobreaker.CircuitBreaker) ServerOption
func ServerDelayLimiter ¶ added in v0.9.4
func ServerDelayLimiter(interval time.Duration, b int) ServerOption
func ServerErrorLimiter ¶ added in v0.9.5
func ServerErrorLimiter(interval time.Duration, b int) ServerOption
func ServerFinalizer ¶ added in v0.0.5
func ServerFinalizer(f ...ServerFinalizerFunc) ServerOption
Source Files ¶
Click to show internal directories.
Click to hide internal directories.