web

package
v1.3.2 Latest Latest
Warning

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

Go to latest
Published: Jan 8, 2021 License: Apache-2.0 Imports: 24 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Opts = &struct {
		ReadTimeout  int64 // 读取超时
		WriteTimeout int64 // 写入超时
	}{}

	Flags = []cli.Flag{
		&cli.Int64Flag{
			Name:        "web_read_timeout",
			Usage:       "Web读取超时. 单位秒",
			EnvVars:     []string{"WEB_READ_TIMEOUT"},
			Value:       30,
			Destination: &Opts.ReadTimeout,
		},
		&cli.Int64Flag{
			Name:        "web_white_timeout",
			Usage:       "Web写入超时. 单位秒",
			EnvVars:     []string{"WEB_WHITE_TIMEOUT"},
			Value:       30,
			Destination: &Opts.WriteTimeout,
		},
	}
)
View Source
var (
	DefaultMaxHeaderBytes = 1024 // 默认Header大小限制
)

Functions

func CtxError

func CtxError(ctx echo.Context, code int, msg ...string) error

func CtxResult

func CtxResult(ctx echo.Context, res *Result) error

func CtxSuccess

func CtxSuccess(ctx echo.Context, data interface{}, msg ...string) error

func ErrorHandler

func ErrorHandler(err error, ctx echo.Context)

统一错误处理

func FileAssets

func FileAssets(ctx echo.Context, storeRoot string) error

FileAssets 文件资源访问

Types

type Context

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

func NewContext

func NewContext(ctx echo.Context) *Context

func (*Context) Bind

func (c *Context) Bind(req interface{}) error

func (*Context) BindValid

func (c *Context) BindValid(req interface{}) error

func (*Context) CaptchaCheck

func (c *Context) CaptchaCheck(key string, captcha string) bool

验证验证码

func (*Context) CaptchaNew

func (c *Context) CaptchaNew(key string, width, height int, setOpt ...captcha.SetOption) error

创建验证码

func (*Context) Echo

func (c *Context) Echo() echo.Context

func (*Context) Error

func (c *Context) Error(err error) error

func (*Context) JsonError

func (c *Context) JsonError(code int, msg ...string) error

func (*Context) JsonSuccess

func (c *Context) JsonSuccess(data interface{}, msg ...string) error

func (*Context) SessClean

func (c *Context) SessClean()

func (*Context) SessDel

func (c *Context) SessDel(key ...interface{})

func (*Context) SessFlash

func (c *Context) SessFlash(key ...string) []interface{}

func (*Context) SessFlashAdd

func (c *Context) SessFlashAdd(val interface{}, key ...string)

func (*Context) SessGet

func (c *Context) SessGet(key interface{}) interface{}

func (*Context) SessGetValues

func (c *Context) SessGetValues() map[interface{}]interface{}

func (*Context) SessHas

func (c *Context) SessHas(key interface{}) bool

func (*Context) SessId

func (c *Context) SessId() string

func (*Context) SessOpts

func (c *Context) SessOpts() *sessions.Options

func (*Context) SessOptsSet

func (c *Context) SessOptsSet(opts *sessions.Options)

func (*Context) SessSet

func (c *Context) SessSet(key, val interface{})

func (*Context) SessSetValues

func (c *Context) SessSetValues(values map[interface{}]interface{})

func (*Context) Session

func (c *Context) Session() *sessions.Session

func (*Context) SessionDo

func (c *Context) SessionDo(closure func(*sessions.Session) interface{}) interface{}

type Result

type Result struct {
	Code int         `json:"code"`
	Msg  string      `json:"msg"`
	Data interface{} `json:"data"`
	Time int64       `json:"time"`
}

func NewResult

func NewResult(code int, msg string, data interface{}) *Result

func ParseError

func ParseError(err error) *Result

type Server

type Server struct {
	sync.Mutex
	// contains filtered or unexported fields
}

Web服务

func NewServer

func NewServer(name string, validator ...echo.Validator) *Server

func (*Server) Start

func (s *Server) Start() error

func (*Server) Stop

func (s *Server) Stop() error

func (*Server) With

func (s *Server) With(with ...ServerWith)

type ServerWith

type ServerWith func(s *Server)

func WithAddr

func WithAddr(addr string) ServerWith

func WithAssets

func WithAssets(prefix string, handler echo.HandlerFunc) ServerWith

绑定资源访问

func WithCORS

func WithCORS(origins ...string) ServerWith

跨域设置

func WithDebug

func WithDebug(debug bool) ServerWith

func WithGzip

func WithGzip() ServerWith

启用GZIP

func WithRouter

func WithRouter(prefix string, routes ...func(g *echo.Group)) ServerWith

WithRouter 注册路由

func WithSecure

func WithSecure() ServerWith

func WithSession

func WithSession(store string, secret string) ServerWith

启用Session

func WithValidator

func WithValidator(validator echo.Validator) ServerWith

func WithView

func WithView(prefix string, fs http.FileSystem, uri ...string) ServerWith

绑定视图

type Upload

type Upload struct {
	SaveFile string `json:"save_file"` // 保存文件
	FileName string `json:"file_name"` // 文件名称
	FileSize int64  `json:"file_size"` // 文件大小
	OldName  string `json:"old_name"`  // 原始名称
}

上传文件返回的结果

func FileUpload

func FileUpload(file *multipart.FileHeader, storeRoot, savePath string) (*Upload, error)

上传文件

Jump to

Keyboard shortcuts

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