water

package module
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Feb 11, 2024 License: MIT Imports: 22 Imported by: 6

README

简介:go-water 是一款设计层面的框架,帮助您更好的使用 web 框架(比如:gin,iris,beego,echo等),更好的业务隔离,更好的系统设计,通过一系列接口、规范、约定、中间件,深度解耦业务系统。

星星增长趋势

Stargazers over time

安装

go get -u github.com/go-water/water

技术概览

  • zap 日志
  • rsa 加密,openssl 生成公/私钥对
  • jwt 登陆认证
  • errors 自定义处理
  • pool 管理请求参数
  • option 配置修改
  • rate limit(限流)
  • circuit breaker(熔断)

样例仓库

官方文档

Documentation

Index

Constants

View Source
const ContextKey = "_go-water/context-key"

Variables

This section is empty.

Functions

func BindJSON added in v0.5.0

func BindJSON[T any](c *Context) (t *T, err error)

func Error added in v0.2.8

func Error(msg string, fields ...zap.Field)

func Info added in v0.2.8

func Info(msg string, fields ...zap.Field)

func InitZap added in v0.2.8

func InitZap()

func NewLogger added in v0.2.8

func NewLogger() *zap.Logger

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

func SetAuthToken(uniqueUser, issuer, privateKeyPath string, expire time.Duration) (tokenString string, err error)

func Warn added in v0.2.8

func Warn(msg string, fields ...zap.Field)

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) Deadline added in v0.5.0

func (c *Context) Deadline() (deadline time.Time, ok bool)

Deadline returns that there is no deadline (ok==false) when c.Request has no Context.

func (*Context) Done added in v0.5.0

func (c *Context) Done() <-chan struct{}

Done returns nil (chan which will wait forever) when c.Request has no Context.

func (*Context) Err added in v0.5.0

func (c *Context) Err() error

Err returns nil when c.Request has no Context.

func (*Context) Get added in v0.5.0

func (c *Context) Get(key string) (value any, exists bool)

func (*Context) JSON added in v0.5.0

func (c *Context) JSON(status int, data any) error

func (*Context) Param added in v0.5.0

func (c *Context) Param(key string) string

func (*Context) Set added in v0.5.0

func (c *Context) Set(key string, value any)

func (*Context) ShouldBindJSON added in v0.5.0

func (c *Context) ShouldBindJSON(obj any) error

func (*Context) ShouldBindWith added in v0.5.0

func (c *Context) ShouldBindWith(obj any, b binding.Binding) error

func (*Context) Value added in v0.5.0

func (c *Context) Value(key any) any

Value returns the value associated with this context for key, or nil if no value is associated with key. Successive calls to Value with the same key returns the same result.

type ErrorHandler

type ErrorHandler interface {
	Handle(ctx context.Context, err error)
}

type ErrorHandlerFunc

type ErrorHandlerFunc func(ctx context.Context, err error)

func (ErrorHandlerFunc) Handle

func (f ErrorHandlerFunc) Handle(ctx context.Context, err error)

type H added in v0.5.0

type H map[string]any

type Handler

type Handler interface {
	ServerWater(ctx context.Context, req any) (any, error)
	GetLogger() *zap.Logger
}

func NewHandler

func NewHandler(srv Service, options ...ServerOption) Handler

type HandlerFunc added in v0.5.0

type HandlerFunc func(*Context)

func (HandlerFunc) ServeHTTP added in v0.5.0

func (handle HandlerFunc) ServeHTTP(w http.ResponseWriter, req *http.Request)

type LogErrorHandler

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

func NewLogErrorHandler

func NewLogErrorHandler(l *zap.Logger, n string) *LogErrorHandler

func (*LogErrorHandler) Handle

func (h *LogErrorHandler) Handle(ctx context.Context, err error)

type Router added in v0.5.0

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

func NewRouter added in v0.5.0

func NewRouter() *Router

func (*Router) Get added in v0.5.0

func (r *Router) Get(route string, handler HandlerFunc)

func (*Router) Group added in v0.5.0

func (r *Router) Group(prefix string) *Router

func (*Router) Method added in v0.5.0

func (r *Router) Method(method, route string, handler HandlerFunc)

func (*Router) Post added in v0.5.0

func (r *Router) Post(route string, handler HandlerFunc)

func (*Router) Serve added in v0.5.0

func (r *Router) Serve(addr string, server ...*http.Server) error

func (*Router) Use added in v0.5.0

func (r *Router) Use(middlewares ...func(HandlerFunc) HandlerFunc)

type Server

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

func (*Server) GetLogger added in v0.0.22

func (s *Server) GetLogger() *zap.Logger

func (*Server) ServerWater added in v0.0.16

func (s *Server) ServerWater(ctx context.Context, req any) (resp any, err error)

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() *zap.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 *zap.Logger)

type ServerFinalizerFunc

type ServerFinalizerFunc func(ctx context.Context, err error)

type ServerOption

type ServerOption func(*Server)

func ServerBreaker added in v0.3.3

func ServerBreaker(breaker *gobreaker.CircuitBreaker) ServerOption

func ServerErrorHandler added in v0.0.5

func ServerErrorHandler(errorHandler ErrorHandler) ServerOption

func ServerFinalizer added in v0.0.5

func ServerFinalizer(f ...ServerFinalizerFunc) ServerOption

func ServerLimiter added in v0.3.0

func ServerLimiter(interval time.Duration, b int) ServerOption

type Service

type Service interface {
	Name(srv Service) string
	SetLogger(l *zap.Logger)
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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