quark

package module
v4.0.0-...-f2a333d Latest Latest
Warning

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

Go to latest
Published: Feb 11, 2026 License: MIT Imports: 36 Imported by: 0

README

介绍

QuarkGO 是一个基于golang的低代码工具;它提供的丰富组件,能帮助您使用很少的代码就能搭建出功能完善的应用系统。

系统特性

  • 用户管理
  • 权限系统
  • 菜单管理
  • 系统配置
  • 操作日志
  • 附件管理
  • 组件丰富

快速开始

  1. 创建 demo 文件夹,进入该目录中执行如下命令,初始化项目:
go mod init demo/hello
  1. 创建 main.go 文件
  2. 在 main.go 文件中添加如下代码:
package main

import (
	"github.com/quarkcloudio/quark-go/v4"
	"github.com/quarkcloudio/quark-go/v4/app"
	"gorm.io/driver/sqlite"
	"gorm.io/gorm"
)

func main() {

	// 实例化对象
	b := app.New(&app.Config{
		AppKey: "123456",
		DBConfig: &app.DBConfig{
			Dialector: sqlite.Open("./data.db"),
			Opts:      &gorm.Config{},
		},
	})

	// 响应Get请求
	b.GET("/", func(ctx *quark.Context) error {
		return ctx.String(200, "Hello World!")
	})

	// 启动服务
	b.Run(":3000")
}
  1. 拉取依赖
go mod tidy
  1. 启动服务
go run main.go

后台地址: http://127.0.0.1:3000/admin/

账号:administrator 密码:123456

特别注意

  1. 后台用户认证使用了AppKey作为JWT的加密密串,生产环境请务必更改

相关项目

演示站点

香港站点,页面加载可能比较缓慢

技术支持

为了避免打扰作者日常工作,你可以在Github上提交 Issues

相关教程,你可以查看 在线文档

License

QuarkGo is licensed under The MIT License (MIT).

Documentation

Index

Constants

View Source
const (

	// 应用名称
	AppName = "QuarkGo"

	// 版本号
	Version = "4.0.0"

	// 包名
	PkgName = "github.com/quarkcloudio/quark-go/v4"
)

Variables

View Source
var (
	StatusOk           = 200   // 执行成功
	StatusUnauthorized = 401   // 未授权
	StatusForbidden    = 403   // 无权限
	StatusError        = 10001 // 自定义错误信息
	StatusParamError   = 10002 // 参数错误
)
View Source
var (
	OssStorage   = "oss"
	LocalStorage = "local"
	MinioStorage = "minio"
)
View Source
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",
	},
}
View Source
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 GetMsgByCode

func GetMsgByCode(code int) string

根据code获取错误信息

func NewRequest

func NewRequest(method string, url string, body io.Reader) *http.Request

func NewResponse

func NewResponse(writer io.Writer) http.ResponseWriter

Types

type CodeMap

type CodeMap struct {
	Code int    `json:"code"`
	Msg  string `json:"msg"`
}

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

全局配置

func GetConfig

func GetConfig() *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) AllQuerys

func (p *Context) AllQuerys() map[string]interface{}

AllQuerys returns all query arguments from RequestURI.

func (*Context) Attachment

func (p *Context) Attachment(file string, name string) error

Attachment sends a response as attachment, prompting client to save the file.

func (*Context) Bind

func (p *Context) Bind(i interface{}) error

Bind binds the request body into provided type `i`. The default binder does it based on Content-Type header.

func (*Context) Blob

func (p *Context) Blob(code int, contentType string, b []byte) error

Blob sends a blob response with status code and content type.

func (*Context) Body

func (p *Context) Body() []byte

Body returns body data

func (*Context) BodyParser

func (p *Context) BodyParser(i interface{}) error

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

func (p *Context) ClientIP() string

IP tries to parse the headers in [X-Real-Ip, X-Forwarded-For]. It calls RemoteIP() under the hood

func (*Context) ContentType

func (p *Context) ContentType() string

ContentType returns the Content-Type header of the request.

func (*Context) Cookie

func (p *Context) Cookie(name string) (*http.Cookie, error)

Cookie returns the named cookie provided in the request.

func (*Context) Cookies

func (p *Context) Cookies() []*http.Cookie

Cookies returns the HTTP cookies sent with the request.

func (*Context) Error

func (p *Context) Error(err 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) File

func (p *Context) File(file string) error

File sends a response with the content of the file.

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

func (p *Context) FormParams() (url.Values, error)

FormParams returns the form parameters as `url.Values`.

func (*Context) FormValue

func (p *Context) FormValue(name string) string

FormValue returns the form field value for the provided name.

func (*Context) FullPath

func (p *Context) FullPath() string

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

func (p *Context) Get(key string) interface{}

Get retrieves data from the context.

func (*Context) HTML

func (p *Context) HTML(code int, html string) error

HTML sends an HTTP response with status code.

func (*Context) HTMLBlob

func (p *Context) HTMLBlob(code int, b []byte) error

HTMLBlob sends an HTTP blob response with status code.

func (*Context) Header

func (p *Context) Header(key string) string

获取请求头数据

func (*Context) Host

func (p *Context) Host() string

Host returns requested host.

The host is valid until returning from RequestHandler.

func (*Context) InitTemplate

func (p *Context) InitTemplate(ctx *Context) error

初始化模板

func (*Context) Inline

func (p *Context) Inline(file string, name string) error

Inline sends a response as inline, opening the file in the browser.

func (*Context) IsCreating

func (p *Context) IsCreating() bool

判断当前页面是否为创建页面

func (*Context) IsDetail

func (p *Context) IsDetail() bool

判断当前页面是否为详情页面

func (*Context) IsEditing

func (p *Context) IsEditing() bool

判断当前页面是否为编辑页面

func (*Context) IsExport

func (p *Context) IsExport() bool

判断当前页面是否为导出页面

func (*Context) IsImport

func (p *Context) IsImport() bool

判断当前页面是否为导入页面

func (*Context) IsIndex

func (p *Context) IsIndex() bool

判断当前页面是否为列表页面 todo

func (*Context) IsTLS

func (p *Context) IsTLS() bool

IsTLS returns true if HTTP connection is TLS otherwise false.

func (*Context) IsWebSocket

func (p *Context) IsWebSocket() bool

IsWebSocket returns true if HTTP connection is WebSocket otherwise false.

func (*Context) JSON

func (p *Context) JSON(code int, i interface{}) error

JSON sends a JSON response with status code.

func (*Context) JSONBlob

func (p *Context) JSONBlob(code int, b []byte) error

JSONBlob sends a JSON blob response with status code.

func (*Context) JSONError

func (p *Context) JSONError(message ...interface{}) error

输出失败状态的JSON数据,JSONError("错误") | JSONError("错误", map[string]interface{}{"title":"标题"})

func (*Context) JSONErrorByCode

func (p *Context) JSONErrorByCode(message ...interface{}) error

根据Code输出失败状态的JSON数据,JSONErrorByCode(10001) | JSONErrorByCode(10001, map[string]interface{}{"title":"标题"})

func (*Context) JSONOk

func (p *Context) JSONOk(message ...interface{}) error

输出成功状态的JSON数据,JSONOk("成功") | JSONOk("成功", map[string]interface{}{"title":"标题"})

func (*Context) JSONP

func (p *Context) JSONP(code int, callback string, i interface{}) error

JSONP sends a JSONP response with status code. It uses `callback` to construct the JSONP payload.

func (*Context) JSONPBlob

func (p *Context) JSONPBlob(code int, callback string, b []byte) error

JSONPBlob sends a JSONP blob response with status code. It uses `callback` to construct the JSONP payload.

func (*Context) JSONPretty

func (p *Context) JSONPretty(code int, i interface{}, indent string) error

JSONPretty sends a pretty-print JSON with status code.

func (*Context) JSONRedirectTo

func (p *Context) JSONRedirectTo(message ...interface{}) error

输出URL跳转,JSONRedirectTo("/home/index") | JSONRedirectTo("成功", "/home/index") | JSONRedirectTo("错误", "/home/index", 10001)

func (*Context) JwtAuthUser

func (p *Context) JwtAuthUser(claims interface{}) (err error)

获取当前JWT认证的用户信息

func (*Context) JwtAuthUserMap

func (p *Context) JwtAuthUserMap() (result jwt.MapClaims, err error)

获取当前JWT认证的用户信息,返回的数据为map格式

func (*Context) JwtToken

func (p *Context) JwtToken(claims interface{}) (tokenString string, err error)

生成JWT认证的token

func (*Context) Method

func (p *Context) Method() string

Method return request method.

Returned value is valid until returning from RequestHandler.

func (*Context) MultipartForm

func (p *Context) MultipartForm() (*multipart.Form, error)

MultipartForm returns the multipart form.

func (*Context) Next

func (p *Context) Next() error

执行下一个Use方法,TODO

func (*Context) NoContent

func (p *Context) NoContent(code int) error

NoContent sends a response with no body and a status code.

func (*Context) OriginalURL

func (p *Context) OriginalURL() string

OriginalURL returns url query data

func (*Context) Param

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

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

func (p *Context) Path() string

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

func (p *Context) QueryParam(name string) string

QueryParam returns the query param for the provided name.

func (*Context) QueryParams

func (p *Context) QueryParams() url.Values

QueryParams returns the query parameters as `url.Values`.

func (*Context) QueryString

func (p *Context) QueryString() string

QueryString returns the URL query string.

func (*Context) RealIP

func (p *Context) RealIP() string

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

func (p *Context) Redirect(code int, url string) error

Redirect redirects the request to a provided URL with status code.

func (*Context) Render

func (p *Context) Render(code int, name string, data interface{}) error

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

func (p *Context) ResourceName() string

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

func (p *Context) RouterPathToUrl(routerPath string) string

替换路由中的资源参数

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

func (p *Context) Scheme() string

Scheme returns the HTTP protocol scheme, `http` or `https`.

func (*Context) Session

func (p *Context) Session(name string) (*sessions.Session, error)

Session returns the named session provided in the request.

func (*Context) Set

func (p *Context) Set(key string, val interface{})

Set saves data in the context.

func (*Context) SetCookie

func (p *Context) SetCookie(cookie *http.Cookie)

SetCookie adds a `Set-Cookie` header in HTTP response.

func (*Context) SetFullPath

func (p *Context) SetFullPath(fullPath string) *Context

设置SetFullPath

func (*Context) SetParams

func (p *Context) SetParams(params map[string]string) *Context

设置Params

func (*Context) SetSession

func (p *Context) SetSession(name string, values map[interface{}]interface{}) error

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

func (p *Context) Stream(code int, contentType string, r io.Reader) error

Stream sends a streaming response with status code and content type.

func (*Context) String

func (p *Context) String(code int, s string) error

String sends a string response with status code.

func (*Context) Token

func (p *Context) Token() string

获取Header中的token

func (*Context) Validate

func (p *Context) Validate(i interface{}) error

Validate validates provided `i`. It is usually called after `Context#Bind()`. Validator must be registered using `Echo#Validator`.

func (*Context) Write

func (p *Context) Write(data []byte)

Method return request method.

Returned value is valid until returning from RequestHandler.

func (*Context) XML

func (p *Context) XML(code int, i interface{}) error

XML sends an XML response with status code.

func (*Context) XMLBlob

func (p *Context) XMLBlob(code int, b []byte) error

XMLBlob sends an XML blob response with status code.

func (*Context) XMLPretty

func (p *Context) XMLPretty(code int, i interface{}, indent string) error

XMLPretty sends a pretty-print XML with status code.

type DBConfig

type DBConfig struct {
	Dialector gorm.Dialector
	Opts      gorm.Option
}

type Engine

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

func New

func New(config *Config) *Engine

初始化对象

func (*Engine) Any

func (p *Engine) Any(path string, handle Handle) error

Any请求

func (*Engine) DELETE

func (p *Engine) DELETE(path string, handle Handle) error

DELETE请求

func (*Engine) Echo

func (p *Engine) Echo() *echo.Echo

获取Echo框架实例

func (*Engine) GET

func (p *Engine) GET(path string, handle Handle) error

GET请求

func (*Engine) GetConfig

func (p *Engine) GetConfig() *Config

获取当前配置

func (*Engine) GetProviders

func (p *Engine) GetProviders() []interface{}

获取所有服务

func (*Engine) GetRoutePaths

func (p *Engine) GetRoutePaths() []*RouteMapping

获取路由列表

func (*Engine) GetUrlPaths

func (p *Engine) GetUrlPaths() []*UrlPath

获取请求列表

func (*Engine) Group

func (p *Engine) Group(path string, handlers ...Handle) *Group

路由组

func (*Engine) HEAD

func (p *Engine) HEAD(path string, handle Handle) error

HEAD请求

func (*Engine) NewContext

func (p *Engine) NewContext(writer http.ResponseWriter, request *http.Request) *Context

创建上下文

func (*Engine) OPTIONS

func (p *Engine) OPTIONS(path string, handle Handle) error

OPTIONS请求

func (*Engine) PATCH

func (p *Engine) PATCH(path string, handle Handle) error

PATCH请求

func (*Engine) POST

func (p *Engine) POST(path string, handle Handle) error

POST请求

func (*Engine) PUT

func (p *Engine) PUT(path string, handle Handle) error

PUT请求

func (*Engine) ParseAction

func (p *Engine) ParseAction(provider interface{}, ctx *Context, url string) []interface{}

解析行为

func (*Engine) Render

func (p *Engine) Render(ctx *Context) error

渲染

func (*Engine) Run

func (p *Engine) Run(addr string)

Run Server

func (*Engine) Static

func (p *Engine) Static(pathPrefix string, fsRoot string)

加载静态文件

func (*Engine) TransformContext

func (p *Engine) TransformContext(fullPath string, header map[string][]string, method string, url string, body io.Reader, writer io.Writer) *Context

转换Request、Response对象

func (*Engine) Use

func (p *Engine) Use(args interface{})

通用调用方法

func (*Engine) UseHandlers

func (p *Engine) UseHandlers() []func(ctx *Context) error

获取通用调用方法

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 NewStorage

func NewStorage(config *StorageConfig) *FileSystem

初始化对象

func (*FileSystem) CheckFile

func (p *FileSystem) CheckFile() error

检测文件合法性

func (*FileSystem) CheckFileExist

func (p *FileSystem) CheckFileExist() *FileSystem

检测文件是否已存在

func (*FileSystem) Driver

func (p *FileSystem) Driver(driver string) *FileSystem

存储驱动

func (*FileSystem) FileContent

func (p *FileSystem) FileContent(fileContent []byte) *FileSystem

设置二进制内容

func (*FileSystem) FileHeader

func (p *FileSystem) FileHeader(fileHeader map[string][]string) *FileSystem

设置文件标头

func (*FileSystem) FileName

func (p *FileSystem) FileName(fileName string) *FileSystem

设置文件名称

func (*FileSystem) GetFileHash

func (p *FileSystem) GetFileHash() (string, error)

计算文件哈希值

func (*FileSystem) LimitImageHeight

func (p *FileSystem) LimitImageHeight(limitImageHeight int) *FileSystem

限制图片高度

func (*FileSystem) LimitImageWidth

func (p *FileSystem) LimitImageWidth(limitImageWidth int) *FileSystem

限制图片宽度

func (*FileSystem) LimitSize

func (p *FileSystem) LimitSize(limitSize int64) *FileSystem

限制文件大小

func (*FileSystem) LimitType

func (p *FileSystem) LimitType(limitType []string) *FileSystem

限制文件类型

func (*FileSystem) Name

func (p *FileSystem) Name(name string) *FileSystem

保存文件名称

func (*FileSystem) Path

func (p *FileSystem) Path(path string) *FileSystem

保存路径

func (*FileSystem) RandName

func (p *FileSystem) RandName() *FileSystem

随机保存文件名称

func (*FileSystem) Reader

func (p *FileSystem) Reader(file *File) *FileSystem

设置文件信息

func (*FileSystem) Save

func (p *FileSystem) Save() (fileInfo *FileInfo, err error)

保存文件

func (*FileSystem) SaveToLocal

func (p *FileSystem) SaveToLocal() error

保存文件到本地

func (*FileSystem) SaveToMinio

func (p *FileSystem) SaveToMinio() error

保存文件到Minio

func (*FileSystem) SaveToOSS

func (p *FileSystem) SaveToOSS() error

保存文件到OSS

func (*FileSystem) WithImageExtra

func (p *FileSystem) WithImageExtra() *FileSystem

读取图片宽高

type Group

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

定义路由组

func (*Group) Any

func (p *Group) Any(path string, handle Handle) error

Any请求

func (*Group) DELETE

func (p *Group) DELETE(path string, handle Handle) error

DELETE请求

func (*Group) GET

func (p *Group) GET(path string, handle Handle) error

GET请求

func (*Group) Group

func (p *Group) Group(path string, handlers ...Handle) *Group

路由组

func (*Group) HEAD

func (p *Group) HEAD(path string, handle Handle) error

HEAD请求

func (*Group) OPTIONS

func (p *Group) OPTIONS(path string, handle Handle) error

OPTIONS请求

func (*Group) PATCH

func (p *Group) PATCH(path string, handle Handle) error

PATCH请求

func (*Group) POST

func (p *Group) POST(path string, handle Handle) error

POST请求

func (*Group) PUT

func (p *Group) PUT(path string, handle Handle) error

PUT请求

type Handle

type Handle func(ctx *Context) error

定义路由方法类型

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)

func Success

func Success(message string, data interface{}) *Message

返回正确信息

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 ParamValue struct {
	Key   int
	Value string
}

type RedisConfig

type RedisConfig struct {
	Host     string // 地址
	Password string // 密码
	Port     string // 端口
	Database int    // 数据库
}

type Response

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

func (*Response) Flush

func (w *Response) Flush()

func (*Response) Header

func (w *Response) Header() http.Header

func (*Response) StatusCode

func (w *Response) StatusCode() int

func (*Response) Write

func (w *Response) Write(p []byte) (int, error)

func (*Response) WriteHeader

func (w *Response) WriteHeader(statusCode int)

type RouteMapping

type RouteMapping struct {
	Method  string
	Path    string
	Handler func(ctx *Context) error
}

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

注册路由

func (*Template) Any

func (p *Template) Any(path string, handler func(ctx *Context) error)

ANY请求

func (*Template) DELETE

func (p *Template) DELETE(path string, handler func(ctx *Context) error)

DELETE请求

func (*Template) GET

func (p *Template) GET(path string, handler func(ctx *Context) error)

GET请求

func (*Template) GetRouteMapping

func (p *Template) GetRouteMapping() []*RouteMapping

获取路由

func (*Template) HEAD

func (p *Template) HEAD(path string, handler func(ctx *Context) error)

HEAD请求

func (*Template) OPTIONS

func (p *Template) OPTIONS(path string, handler func(ctx *Context) error)

OPTIONS请求

func (*Template) PATCH

func (p *Template) PATCH(path string, handler func(ctx *Context) error)

PATCH请求

func (*Template) POST

func (p *Template) POST(path string, handler func(ctx *Context) error)

POST请求

func (*Template) PUT

func (p *Template) PUT(path string, handler func(ctx *Context) error)

PUT请求

func (*Template) Route

func (p *Template) Route() interface{}

自定义路由

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

模版接口

type UrlPath

type UrlPath struct {
	Method string
	Url    string
}

Directories

Path Synopsis
adapter
app
tpl
dal
db
dto
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
hex
tag

Jump to

Keyboard shortcuts

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