Documentation
¶
Index ¶
- Constants
- Variables
- func GetMsgByCode(code int) string
- func NewRequest(method string, url string, body io.Reader) *http.Request
- func NewResponse(writer io.Writer) http.ResponseWriter
- type CodeMap
- type Config
- type Context
- func (p *Context) AllQuerys() map[string]interface{}
- func (p *Context) Attachment(file string, name string) error
- func (p *Context) Bind(i interface{}) error
- func (p *Context) Blob(code int, contentType string, b []byte) error
- func (p *Context) Body() []byte
- func (p *Context) BodyParser(i interface{}) error
- func (p *Context) ClientIP() string
- func (p *Context) ContentType() string
- func (p *Context) Cookie(name string) (*http.Cookie, error)
- func (p *Context) Cookies() []*http.Cookie
- func (p *Context) Error(err error)
- func (p *Context) File(file string) error
- func (p *Context) FormFile(name string) (*multipart.FileHeader, error)
- func (p *Context) FormParams() (url.Values, error)
- func (p *Context) FormValue(name string) string
- func (p *Context) FullPath() string
- func (p *Context) Get(key string) interface{}
- func (p *Context) HTML(code int, html string) error
- func (p *Context) HTMLBlob(code int, b []byte) error
- func (p *Context) Header(key string) string
- func (p *Context) Host() string
- func (p *Context) InitTemplate(ctx *Context) error
- func (p *Context) Inline(file string, name string) error
- func (p *Context) IsCreating() bool
- func (p *Context) IsDetail() bool
- func (p *Context) IsEditing() bool
- func (p *Context) IsExport() bool
- func (p *Context) IsImport() bool
- func (p *Context) IsIndex() bool
- func (p *Context) IsTLS() bool
- func (p *Context) IsWebSocket() bool
- func (p *Context) JSON(code int, i interface{}) error
- func (p *Context) JSONBlob(code int, b []byte) error
- func (p *Context) JSONError(message ...interface{}) error
- func (p *Context) JSONErrorByCode(message ...interface{}) error
- func (p *Context) JSONOk(message ...interface{}) error
- func (p *Context) JSONP(code int, callback string, i interface{}) error
- func (p *Context) JSONPBlob(code int, callback string, b []byte) error
- func (p *Context) JSONPretty(code int, i interface{}, indent string) error
- func (p *Context) JSONRedirectTo(message ...interface{}) error
- func (p *Context) JwtAuthUser(claims interface{}) (err error)
- func (p *Context) JwtAuthUserMap() (result jwt.MapClaims, err error)
- func (p *Context) JwtToken(claims interface{}) (tokenString string, err error)
- func (p *Context) Method() string
- func (p *Context) MultipartForm() (*multipart.Form, error)
- func (p *Context) Next() error
- func (p *Context) NoContent(code int) error
- func (p *Context) OriginalURL() string
- func (p *Context) Param(key string) string
- func (p *Context) Path() string
- func (p *Context) Query(params ...interface{}) interface{}
- func (p *Context) QueryParam(name string) string
- func (p *Context) QueryParams() url.Values
- func (p *Context) QueryString() string
- func (p *Context) RealIP() string
- func (p *Context) Redirect(code int, url string) error
- func (p *Context) Render(code int, name string, data interface{}) error
- func (p *Context) ResourceName() string
- func (p *Context) RouterPathToUrl(routerPath string) string
- func (p *Context) SaveFile(file *multipart.FileHeader, path string) error
- func (p *Context) Scheme() string
- func (p *Context) Session(name string) (*sessions.Session, error)
- func (p *Context) Set(key string, val interface{})
- func (p *Context) SetCookie(cookie *http.Cookie)
- func (p *Context) SetFullPath(fullPath string) *Context
- func (p *Context) SetParams(params map[string]string) *Context
- func (p *Context) SetSession(name string, values map[interface{}]interface{}) error
- func (p *Context) SetSessionWithOptions(name string, options *sessions.Options, values map[interface{}]interface{}) error
- func (p *Context) Stream(code int, contentType string, r io.Reader) error
- func (p *Context) String(code int, s string) error
- func (p *Context) Token() string
- func (p *Context) Validate(i interface{}) error
- func (p *Context) Write(data []byte)
- func (p *Context) XML(code int, i interface{}) error
- func (p *Context) XMLBlob(code int, b []byte) error
- func (p *Context) XMLPretty(code int, i interface{}, indent string) error
- type DBConfig
- type Engine
- func (p *Engine) Any(path string, handle Handle) error
- func (p *Engine) DELETE(path string, handle Handle) error
- func (p *Engine) Echo() *echo.Echo
- func (p *Engine) GET(path string, handle Handle) error
- func (p *Engine) GetConfig() *Config
- func (p *Engine) GetProviders() []interface{}
- func (p *Engine) GetRoutePaths() []*RouteMapping
- func (p *Engine) GetUrlPaths() []*UrlPath
- func (p *Engine) Group(path string, handlers ...Handle) *Group
- func (p *Engine) HEAD(path string, handle Handle) error
- func (p *Engine) NewContext(writer http.ResponseWriter, request *http.Request) *Context
- func (p *Engine) OPTIONS(path string, handle Handle) error
- func (p *Engine) PATCH(path string, handle Handle) error
- func (p *Engine) POST(path string, handle Handle) error
- func (p *Engine) PUT(path string, handle Handle) error
- func (p *Engine) ParseAction(provider interface{}, ctx *Context, url string) []interface{}
- func (p *Engine) Render(ctx *Context) error
- func (p *Engine) Run(addr string)
- func (p *Engine) Static(pathPrefix string, fsRoot string)
- func (p *Engine) TransformContext(fullPath string, header map[string][]string, method string, url string, ...) *Context
- func (p *Engine) Use(args interface{})
- func (p *Engine) UseHandlers() []func(ctx *Context) error
- type File
- type FileInfo
- type FileSystem
- func (p *FileSystem) CheckFile() error
- func (p *FileSystem) CheckFileExist() *FileSystem
- func (p *FileSystem) Driver(driver string) *FileSystem
- func (p *FileSystem) FileContent(fileContent []byte) *FileSystem
- func (p *FileSystem) FileHeader(fileHeader map[string][]string) *FileSystem
- func (p *FileSystem) FileName(fileName string) *FileSystem
- func (p *FileSystem) GetFileHash() (string, error)
- func (p *FileSystem) LimitImageHeight(limitImageHeight int) *FileSystem
- func (p *FileSystem) LimitImageWidth(limitImageWidth int) *FileSystem
- func (p *FileSystem) LimitSize(limitSize int64) *FileSystem
- func (p *FileSystem) LimitType(limitType []string) *FileSystem
- func (p *FileSystem) Name(name string) *FileSystem
- func (p *FileSystem) Path(path string) *FileSystem
- func (p *FileSystem) RandName() *FileSystem
- func (p *FileSystem) Reader(file *File) *FileSystem
- func (p *FileSystem) Save() (fileInfo *FileInfo, err error)
- func (p *FileSystem) SaveToLocal() error
- func (p *FileSystem) SaveToMinio() error
- func (p *FileSystem) SaveToOSS() error
- func (p *FileSystem) WithImageExtra() *FileSystem
- type Group
- func (p *Group) Any(path string, handle Handle) error
- func (p *Group) DELETE(path string, handle Handle) error
- func (p *Group) GET(path string, handle Handle) error
- func (p *Group) Group(path string, handlers ...Handle) *Group
- func (p *Group) HEAD(path string, handle Handle) error
- func (p *Group) OPTIONS(path string, handle Handle) error
- func (p *Group) PATCH(path string, handle Handle) error
- func (p *Group) POST(path string, handle Handle) error
- func (p *Group) PUT(path string, handle Handle) error
- type Handle
- type Message
- type MinioConfig
- type OSSConfig
- type ParamValue
- type RedisConfig
- type Response
- type RouteMapping
- type StorageConfig
- type Template
- func (p *Template) AddRouteMapping(method string, path string, handler func(ctx *Context) error) *Template
- func (p *Template) Any(path string, handler func(ctx *Context) error)
- func (p *Template) DELETE(path string, handler func(ctx *Context) error)
- func (p *Template) GET(path string, handler func(ctx *Context) error)
- func (p *Template) GetRouteMapping() []*RouteMapping
- func (p *Template) HEAD(path string, handler func(ctx *Context) error)
- func (p *Template) OPTIONS(path string, handler func(ctx *Context) error)
- func (p *Template) PATCH(path string, handler func(ctx *Context) error)
- func (p *Template) POST(path string, handler func(ctx *Context) error)
- func (p *Template) PUT(path string, handler func(ctx *Context) error)
- func (p *Template) Route() interface{}
- type Templater
- type UrlPath
Constants ¶
const ( // 应用名称 AppName = "QuarkGo" // 版本号 Version = "4.0.0" // 包名 PkgName = "github.com/quarkcloudio/quark-go/v4" )
Variables ¶
var ( StatusOk = 200 // 执行成功 StatusForbidden = 403 // 无权限 StatusError = 10001 // 自定义错误信息 StatusParamError = 10002 // 参数错误 )
var ( OssStorage = "oss" LocalStorage = "local" MinioStorage = "minio" )
var CodeMaps = []*CodeMap{ { Code: StatusOk, Msg: "ok", }, { Code: StatusError, Msg: "Internal Server Error", }, { Code: StatusParamError, Msg: "Param Error", }, { Code: StatusUnauthorized, Msg: "Unauthorized", }, { Code: StatusForbidden, Msg: "Forbidden", }, }
var ContentTypeList = map[string]string{
"application/x-dosexec": "exe",
"application/msword": "doc",
"application/vnd.ms-excel": "xls",
"application/x-xls": "xls",
"application/vnd.ms-powerpoint": "ppt",
"application/x-ppt": "ppt",
"application/x-dmg": "dmg",
"application/x-gzip": "gz",
"application/x-rar": "rar",
"application/x-tar": "tar",
"application/x-xar": "pkg",
"application/x-rpm": "rpm",
"application/x-stuffit": "sif",
"application/x-archive": "",
"application/x-arc": "arc",
"application/x-eet": "eet",
"application/x-zoo": "zoo",
"application/x-lz4": "lz4",
"application/x-lrzip": "lrz",
"application/x-lzh": "lzh",
"application/warc": "warc",
"application/x-7z-compressed": "7z",
"application/x-xz": "xz",
"application/x-lha": "lha",
"application/x-arj": "arj",
"application/x-cpio": "cpio",
"application/x-compress": "",
"application/x-lzma": "",
"application/zip": "zip",
"application/vnd.ms-cab-compressed": "cab",
"application/pdf": "pdf",
"application/vnd.openxmlformats-officedocument.wordprocessingml.document": "docx",
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet": "xlsx",
"application/vnd.openxmlformats-officedocument.presentationml.presentation": "pptx",
"application/font-woff": "woff",
"application/x-font-ttf": "ttf",
"application/vnd.ms-fontobject": "eot",
"application/x-font-sfn": "",
"application/vnd.ms-opentype": "otf",
"application/x-mif": "mif",
"application/vnd.font-fontforge-sfd": "sfd",
"audio/mpeg": "mp3",
"audio/x-m4a": "m4a",
"audio/x-wav": "wav",
"image/tiff": "tiff",
"image/gif": "gif",
"image/jpeg": "jpg",
"image/x-ms-bmp": "bmp",
"image/x-icon": "ico",
"image/svg+xml": "svg",
"image/x-cursor": "cur",
"image/vnd.adobe.photoshop": "pnd",
"image/png": "png",
"text/html": "html",
"text/plain": "txt",
"text/json": "json",
"text/rtf": "rtf",
"application/xml": "xml",
"text/rss": "rss",
"application/java-archive": "jar",
"application/x-java-applet": "jar",
"application/x-shockwave-flash": "swf",
"application/pkcs7-signature": "p7",
"application/x-pem": "pem",
"application/x-java-jnlp-file": "jnlp",
"application/vnd.tcpdump.pcap": "pcap",
"text/x-shellscript": "sh",
"text/x-perl": "pl",
"text/x-ruby": "rb",
"text/x-python": "py",
"text/x-awk": "awk",
"text/x-lua": "lua",
"application/javascript": "js",
"text/x-php": "php",
"application/x-executable": "",
"application/x-coredump": "core",
"video/x-flv": "flv",
"video/x-fli": "fli",
"video/x-flc": "flc",
"video/mj2": "mj2",
"video/x-mng": "mng",
"video/x-jng": "jng",
"video/mpeg": "mpg",
"video/mpv": "mpv",
"video/h264": "264",
"video/webm": "webm",
"video/matroska": "mkv",
"vidoe/x-sgi-movie": "sgi",
"video/quicktime": "qt",
"video/mp4": "mp4",
"video/3gpp": "3gp",
}
对照表
Functions ¶
func NewResponse ¶
func NewResponse(writer io.Writer) http.ResponseWriter
Types ¶
type Config ¶
type Config struct {
AppKey string // 应用加密Key,用于JWT认证
DBConfig *DBConfig // 数据库配置
RedisConfig *RedisConfig // Redis配置
CookieStore *sessions.CookieStore // Cookie存储,用于保存Session
StaticPath string // 静态文件目录
Providers []interface{} // 服务列表
}
var AppConfig *Config
全局配置
type Context ¶
type Context struct {
Engine *Engine // 引擎实例
EchoContext echo.Context // Echo框架上下文
Request *http.Request // Request
Writer http.ResponseWriter // ResponseWriter
Template interface{} // 资源模板实例
Params map[string]string // URL param
Querys map[string]interface{} // URL querys
// contains filtered or unexported fields
}
Context is the most important part of gin. It allows us to pass variables between middleware, manage the flow, validate the JSON of a request and render a JSON response for example.
func (*Context) Attachment ¶
Attachment sends a response as attachment, prompting client to save the file.
func (*Context) Bind ¶
Bind binds the request body into provided type `i`. The default binder does it based on Content-Type header.
func (*Context) BodyParser ¶
BodyParser binds the request body to a struct. It supports decoding the following content types based on the Content-Type header: application/json, application/xml, application/x-www-form-urlencoded, multipart/form-data If none of the content types above are matched, it will return a ErrUnprocessableEntity error
func (*Context) ClientIP ¶
IP tries to parse the headers in [X-Real-Ip, X-Forwarded-For]. It calls RemoteIP() under the hood
func (*Context) ContentType ¶
ContentType returns the Content-Type header of the request.
func (*Context) Error ¶
Error invokes the registered global HTTP error handler. Generally used by middleware. A side-effect of calling global error handler is that now Response has been committed (sent to the client) and middlewares up in chain can not change Response status code or Response body anymore.
Avoid using this method in handlers as no middleware will be able to effectively handle errors after that.
func (*Context) FormFile ¶
func (p *Context) FormFile(name string) (*multipart.FileHeader, error)
FormFile returns the multipart form file for the provided name.
func (*Context) FormParams ¶
FormParams returns the form parameters as `url.Values`.
func (*Context) FullPath ¶
FullPath returns a matched route full path. For not found routes returns an empty string.
router.GET("/user/:id", func(c *gin.Context) {
c.FullPath() == "/user/:id" // true
})
func (*Context) Host ¶
Host returns requested host.
The host is valid until returning from RequestHandler.
func (*Context) IsWebSocket ¶
IsWebSocket returns true if HTTP connection is WebSocket otherwise false.
func (*Context) JSONError ¶
输出失败状态的JSON数据,JSONError("错误") | JSONError("错误", map[string]interface{}{"title":"标题"})
func (*Context) JSONErrorByCode ¶
根据Code输出失败状态的JSON数据,JSONErrorByCode(10001) | JSONErrorByCode(10001, map[string]interface{}{"title":"标题"})
func (*Context) JSONOk ¶
输出成功状态的JSON数据,JSONOk("成功") | JSONOk("成功", map[string]interface{}{"title":"标题"})
func (*Context) JSONP ¶
JSONP sends a JSONP response with status code. It uses `callback` to construct the JSONP payload.
func (*Context) JSONPBlob ¶
JSONPBlob sends a JSONP blob response with status code. It uses `callback` to construct the JSONP payload.
func (*Context) JSONPretty ¶
JSONPretty sends a pretty-print JSON with status code.
func (*Context) JSONRedirectTo ¶
输出URL跳转,JSONRedirectTo("/home/index") | JSONRedirectTo("成功", "/home/index") | JSONRedirectTo("错误", "/home/index", 10001)
func (*Context) JwtAuthUser ¶
获取当前JWT认证的用户信息
func (*Context) JwtAuthUserMap ¶
获取当前JWT认证的用户信息,返回的数据为map格式
func (*Context) Method ¶
Method return request method.
Returned value is valid until returning from RequestHandler.
func (*Context) MultipartForm ¶
MultipartForm returns the multipart form.
func (*Context) OriginalURL ¶
OriginalURL returns url query data
func (*Context) Param ¶
Param returns the value of the URL param. It is a shortcut for c.Params.ByName(key)
router.GET("/user/:id", func(c *hertz.RequestContext) {
// a GET request to /user/john
id := c.Param("id") // id == "john"
})
func (*Context) Path ¶
Path returns requested path.
The path is valid until returning from RequestHandler.
func (*Context) Query ¶
func (p *Context) Query(params ...interface{}) interface{}
Query returns the value of the URL query.
func (*Context) QueryParam ¶
QueryParam returns the query param for the provided name.
func (*Context) QueryParams ¶
QueryParams returns the query parameters as `url.Values`.
func (*Context) QueryString ¶
QueryString returns the URL query string.
func (*Context) RealIP ¶
RealIP returns the client's network address based on `X-Forwarded-For` or `X-Real-IP` request header. The behavior can be configured using `Echo#IPExtractor`.
func (*Context) Render ¶
Render renders a template with data and sends a text/html response with status code. Renderer must be registered using `Echo.Renderer`.
func (*Context) ResourceName ¶
ResourceName returns the value of the URL Resource param. If request path is "/api/admin/login/index" and route is "/api/admin/login/:resource"
resourceName := p.ResourceName() // resourceName = "index"
func (*Context) RouterPathToUrl ¶
替换路由中的资源参数
url := p.RouteToEngineUrl("/api/admin/login/:resource/captchaId") // url = "/api/admin/login/index/captchaId"
func (*Context) SaveFile ¶
func (p *Context) SaveFile(file *multipart.FileHeader, path string) error
File upload
func (*Context) SetSession ¶
SetSession adds a `session` in HTTP response.
func (*Context) SetSessionWithOptions ¶
func (p *Context) SetSessionWithOptions(name string, options *sessions.Options, values map[interface{}]interface{}) error
SetSessionWithOptions adds a `session` with options in HTTP response.
func (*Context) Validate ¶
Validate validates provided `i`. It is usually called after `Context#Bind()`. Validator must be registered using `Echo#Validator`.
func (*Context) Write ¶
Method return request method.
Returned value is valid until returning from RequestHandler.
type Engine ¶
type Engine struct {
// contains filtered or unexported fields
}
func (*Engine) NewContext ¶
创建上下文
func (*Engine) ParseAction ¶
解析行为
type File ¶
type File struct {
Header map[string][]string // map[Content-Disposition:[form-data; name="file"; filename="demo.jpg"] Content-Type:[image/jpeg]]
Name string // 文件名称
Size int64 // 文件大小
Ext string // 文件扩展名
ContentType string // 文件类型
Content []byte // 文件内容
Hash string // 文件哈希值
Extra interface{} // 文件扩展信息
}
文件结构体
type FileInfo ¶
type FileInfo struct {
Name string `json:"name"` // 文件名称
Size int64 `json:"size"` // 文件大小
Ext string `json:"ext"` // 文件扩展名
ContentType string `json:"contentType"` // 文件类型
Path string `json:"path"` // 上传路径
Url string `json:"url"` // Url路径
Hash string `json:"hash"` // 文件哈希值
Extra interface{} `json:"extra"` // 文件扩展信息
}
文件信息
type FileSystem ¶
type FileSystem struct {
Config *StorageConfig // 配置信息
File *File // 文件信息
}
结构体
func (*FileSystem) FileContent ¶
func (p *FileSystem) FileContent(fileContent []byte) *FileSystem
设置二进制内容
func (*FileSystem) FileHeader ¶
func (p *FileSystem) FileHeader(fileHeader map[string][]string) *FileSystem
设置文件标头
func (*FileSystem) LimitImageHeight ¶
func (p *FileSystem) LimitImageHeight(limitImageHeight int) *FileSystem
限制图片高度
func (*FileSystem) LimitImageWidth ¶
func (p *FileSystem) LimitImageWidth(limitImageWidth int) *FileSystem
限制图片宽度
func (*FileSystem) LimitType ¶
func (p *FileSystem) LimitType(limitType []string) *FileSystem
限制文件类型
type Message ¶
type Message struct {
Code int `json:"code"`
Msg string `json:"msg"`
Data interface{} `json:"data,omitempty"`
Url string `json:"url,omitempty"`
}
func Error ¶
func Error(params ...interface{}) *Message
返回错误信息,Error("内部服务调用异常") | Error("错误", map[string]interface{}{"title":"标题"})
func ErrorByCode ¶
func ErrorByCode(params ...interface{}) *Message
返回错误信息,ErrorByCode(10001) | ErrorByCode(10001, map[string]interface{}{"title":"标题"})
func RedirectTo ¶
func RedirectTo(params ...interface{}) *Message
输出模版引擎URL跳转,RedirectTo("/home/index") | RedirectTo("成功", "/home/index") | RedirectTo("失败", "/home/index", 10001)
type MinioConfig ¶
type MinioConfig struct {
Endpoint string // Endpoint
AccessKeyID string // AccessKeyID
AccessKeySecret string // AccessKey
SecretAccessKey string // SecretAccessKey
UseSSL bool // UseSSL
BucketName string // BucketName
Domain string // OSS自定义域名
}
Minio配置
type OSSConfig ¶
type OSSConfig struct {
Endpoint string // OSS endpoint
AccessKeyID string // AccessId
AccessKeySecret string // AccessKey
BucketName string // BucketName
Domain string // OSS自定义域名
}
OSS配置
type ParamValue ¶
type RedisConfig ¶
type Response ¶
type Response struct {
// contains filtered or unexported fields
}
func (*Response) StatusCode ¶
func (*Response) WriteHeader ¶
type RouteMapping ¶
type StorageConfig ¶
type StorageConfig struct {
LimitSize int64 // 限制文件大小
LimitType []string // 限制文件类型
LimitImageWidth int // 限制图片宽度
LimitImageHeight int // 限制图片高度
Driver string // 存储驱动
SavePath string // 保存路径
SaveName string // 保存文件名称
SaveRandName bool // 随机保存文件名称
CheckFileExist bool // 检测文件是否已存在
OSSConfig *OSSConfig // OSS配置
MinioConfig *MinioConfig // Minio配置
}
配置
type Template ¶
type Template struct {
DB *gorm.DB // DB对象
RouteMapping []*RouteMapping // 路由映射
}
模板
func (*Template) AddRouteMapping ¶
func (p *Template) AddRouteMapping(method string, path string, handler func(ctx *Context) error) *Template
注册路由
type Templater ¶
type Templater interface {
// 启动模版
Bootstrap() interface{}
// 加载初始化路由
LoadInitRoute() interface{}
// 加载初始化数据
LoadInitData(ctx *Context) interface{}
// 模版初始化
Init(ctx *Context) interface{}
// 自定义路由
Route() interface{}
// 获取路由
GetRouteMapping() []*RouteMapping
// 添加路由
AddRouteMapping(method string, path string, handler func(ctx *Context) error) *Template
// ANY请求
Any(path string, handler func(ctx *Context) error)
// GET请求
GET(path string, handler func(ctx *Context) error)
// HEAD请求
HEAD(path string, handler func(ctx *Context) error)
// OPTIONS请求
OPTIONS(path string, handler func(ctx *Context) error)
// POST请求
POST(path string, handler func(ctx *Context) error)
// PUT请求
PUT(path string, handler func(ctx *Context) error)
// PATCH请求
PATCH(path string, handler func(ctx *Context) error)
// DELETE请求
DELETE(path string, handler func(ctx *Context) error)
}
模版接口
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
adapter
|
|
|
examples
|
|
|
fiberadmin
command
|
|
|
gfadmin
command
|
|
|
ginadmin
command
|
|
|
hertzadmin
command
|
|
|
kratosadmin
command
|
|
|
quarkadmin
command
|
|
|
sqlitedriver
command
|
|
|
zeroadmin
command
|
|
|
zeroadmin/internal/handler
Code generated by goctl.
|
Code generated by goctl. |
|
zeroadmin/internal/types
Code generated by goctl.
|
Code generated by goctl. |
|
template
|
|
|
utils
|
|