Documentation
¶
Index ¶
- Constants
- Variables
- func Abs(path string) string
- func AddStatusError(c *gin.Context, err error, codes ...int)
- func ByteSize(path string) (int64, error)
- func Clean(path string)
- func ContextIResponse(c *gin.Context, response IResponse, statusRuleFuns ...IResponseStatusRuleFun)
- func Copy(source string, dest string, ignoreErrors ...bool) error
- func DefaultTranslator() *translator
- func Exists(path string) bool
- func FormatSize(bytesize int64, sigfig ...int) string
- func IsDirectory(path string) bool
- func IsExecutable(path string) bool
- func IsFile(path string) bool
- func IsReadable(path string) bool
- func IsSymlink(path string) bool
- func IsWritable(path string) bool
- func JsonBaseResponse(c *gin.Context, v any)
- func JsonError(ctx *gin.Context, err error, codes ...int)
- func JsonErrorString(ctx *gin.Context, err string, codes ...int)
- func JsonSuccess(ctx *gin.Context, data any, messages ...string)
- func LastModified(path string) (time.Time, error)
- func List(directory string, recursive bool, ignore ...string) ([]string, error)
- func ListDirectories(directory string, recursive bool, ignore ...string) ([]string, error)
- func ListFiles(directory string, recursive bool, ignore ...string) ([]string, error)
- func Mkdir(path string) string
- func Move(source string, dest string, ignoreErrors ...bool) error
- func NewTranslator(supportedLocales []locales.Translator, ...) *translator
- func ReadFile(path string) ([]byte, error)
- func ReadTextFile(path string) (string, error)
- func Size(path string, sigfig ...int) (string, error)
- func Symlink(target string, name string) error
- func Touch(path string, flags ...any) string
- func WriteFile(path string, content string) (int, error)
- func WriteTextFile(path string, content string, args ...any) error
- func XmlBaseResponse(c *gin.Context, v any)
- type BaseResponse
- type Engine
- func (e *Engine) BindingValidatorEngine(locale string, translators ...*translator)
- func (e *Engine) Controller(controllers ...IController)
- func (e *Engine) Plugin(Plugins ...IPlugin)
- func (e *Engine) PrefixController(prefix string, controllers ...IController)
- func (e *Engine) SetFuncMaps(funcMaps ...template.FuncMap) *Engine
- type GinContext
- func (c *GinContext) All() GinContextInput
- func (c *GinContext) Form() url.Values
- func (c *GinContext) Header() http.Header
- func (c *GinContext) Host() string
- func (c *GinContext) IsDelete() bool
- func (c *GinContext) IsGet() bool
- func (c *GinContext) IsHead() bool
- func (c *GinContext) IsOptions() bool
- func (c *GinContext) IsPatch() bool
- func (c *GinContext) IsPost() bool
- func (c *GinContext) IsPut() bool
- func (c *GinContext) Path() string
- func (c *GinContext) PostForm() url.Values
- func (c *GinContext) URI() string
- type GinContextInput
- type IController
- type IPlugin
- type IResponse
- type IResponseStatusRuleFun
- type JsonResponse
- type LocaleRegisterDefaultTranslations
- type ValidateError
- type ValidateErrors
Constants ¶
const ( // KB represents the size of a kilobyte. KB float64 = 1024 // MB represents the size of a megabyte. MB float64 = 1024 * KB // GB represents the size of a gigabyte. GB float64 = 1024 * MB // TB represents the size of a terabyte. TB float64 = 1024 * GB // PB represents the size of a petabyte. PB float64 = 1024 * TB )
const ( HeaderAccept = "Accept" HeaderAcceptEncoding = "Accept-Encoding" // HeaderAllow is the name of the "Allow" header field used to list the set of methods // advertised as supported by the target resource. Returning an Allow header is mandatory // for status 405 (method not found) and useful for the OPTIONS method in responses. HeaderAllow = "Allow" HeaderAuthorization = "Authorization" HeaderContentDisposition = "Content-Disposition" HeaderContentEncoding = "Content-Encoding" HeaderContentLength = "Content-Length" HeaderContentType = "Content-Type" HeaderCookie = "Cookie" HeaderSetCookie = "Set-Cookie" HeaderIfModifiedSince = "If-Modified-Since" HeaderLastModified = "Last-Modified" HeaderLocation = "Location" HeaderRetryAfter = "Retry-After" HeaderUpgrade = "Upgrade" HeaderVary = "Vary" HeaderWWWAuthenticate = "WWW-Authenticate" HeaderXForwardedFor = "X-Forwarded-For" HeaderXForwardedProto = "X-Forwarded-Proto" HeaderXForwardedProtocol = "X-Forwarded-Protocol" HeaderXForwardedSsl = "X-Forwarded-Ssl" HeaderXUrlScheme = "X-Url-Scheme" HeaderXHTTPMethodOverride = "X-HTTP-Method-Override" HeaderXRealIP = "X-Real-Ip" HeaderXRequestID = "X-Request-Id" HeaderXCorrelationID = "X-Correlation-Id" HeaderXRequestedWith = "X-Requested-With" HeaderServer = "Server" HeaderOrigin = "Origin" HeaderCacheControl = "Cache-Control" HeaderConnection = "Connection" HeaderUserAgent = "User-Agent" // Access control HeaderAccessControlRequestMethod = "Access-Control-Request-Method" HeaderAccessControlRequestHeaders = "Access-Control-Request-Headers" HeaderAccessControlAllowOrigin = "Access-Control-Allow-Origin" HeaderAccessControlAllowMethods = "Access-Control-Allow-Methods" HeaderAccessControlAllowHeaders = "Access-Control-Allow-Headers" HeaderAccessControlAllowCredentials = "Access-Control-Allow-Credentials" HeaderAccessControlExposeHeaders = "Access-Control-Expose-Headers" HeaderAccessControlMaxAge = "Access-Control-Max-Age" // Security HeaderStrictTransportSecurity = "Strict-Transport-Security" HeaderXContentTypeOptions = "X-Content-Type-Options" HeaderXXSSProtection = "X-XSS-Protection" HeaderXFrameOptions = "X-Frame-Options" HeaderContentSecurityPolicy = "Content-Security-Policy" HeaderContentSecurityPolicyReportOnly = "Content-Security-Policy-Report-Only" HeaderXCSRFToken = "X-CSRF-Token" HeaderReferrerPolicy = "Referrer-Policy" // PROPFIND Method can be used on collection and property resources. PROPFIND = "PROPFIND" // REPORT Method can be used to get information about a resource, see rfc 3253 REPORT = "REPORT" MIMEApplicationJSON = "application/json" MIMEApplicationJSONCharsetUTF8 = MIMEApplicationJSON + "; " + charsetUTF8 MIMEApplicationJavaScript = "application/javascript" MIMEApplicationJavaScriptCharsetUTF8 = MIMEApplicationJavaScript + "; " + charsetUTF8 MIMEApplicationXML = "application/xml" MIMEApplicationXMLCharsetUTF8 = MIMEApplicationXML + "; " + charsetUTF8 MIMETextXML = "text/xml" MIMETextXMLCharsetUTF8 = MIMETextXML + "; " + charsetUTF8 MIMEApplicationForm = "application/x-www-form-urlencoded" MIMEApplicationProtobuf = "application/protobuf" MIMEApplicationMsgpack = "application/msgpack" MIMETextHTML = "text/html" MIMETextHTMLCharsetUTF8 = MIMETextHTML + "; " + charsetUTF8 MIMETextPlain = "text/plain" MIMETextPlainCharsetUTF8 = MIMETextPlain + "; " + charsetUTF8 MIMEMultipartForm = "multipart/form-data" MIMEOctetStream = "application/octet-stream" MIMEEventStream = "text/event-stream" )
Headers
const ( TranslatorLocaleEN = "en" TranslatorLocaleZH = "zh" )
Variables ¶
var ( Translator *translator UtTranslator ut.Translator )
var ( // BusinessCodeOK represents the business code for success. BusinessCodeOK = 0 // BusinessMsgOk represents the business message for success. BusinessMsgOk = "ok" // BusinessCodeError represents the business code for error. BusinessCodeError = -1 )
Functions ¶
func Abs ¶
Abs Returns the fully resolved path, even if the path does not exist.
``` fsx.Abs("./does/not/exist") ``` If the code above was run within `/home/user`, the result would be `/home/user/does/not/exist`.
func AddStatusError ¶
AddStatusError 向gin.error中追加错误
func Clean ¶
func Clean(path string)
Clean will ensure the specified directory exists. If the directory already exists, all of contents are deleted. If the directory does not exist, it is automatically created.
func ContextIResponse ¶
func ContextIResponse(c *gin.Context, response IResponse, statusRuleFuns ...IResponseStatusRuleFun)
func DefaultTranslator ¶
func DefaultTranslator() *translator
func FormatSize ¶
FormatSize returns a nicely formatted representation of a number of bytes, such as `3.14MB`
func IsDirectory ¶
IsDirectory determines whether the specified path represents a directory.
func IsExecutable ¶
IsExecutable determines whether the file/directory is executable for the active system user.
func IsReadable ¶
IsReadable determines whether the file/directory is readable for the active system user.
func IsWritable ¶
IsWritable determines whether the file/directory is writable for the active system user.
func JsonBaseResponse ¶
JsonBaseResponse writes v into w with http.StatusOK.
func LastModified ¶
LastModified identies the last time the path was modified.
func List ¶
List Generate a list of path names for the given directory. Optionally provide a list of ignored paths, using [glob](https://en.wikipedia.org/wiki/Glob_%28programming%29) syntax.
func ListDirectories ¶
ListDirectories provides absolute paths of directories only, ignoring files.
func Mkdir ¶
Mkdir is the equivalent of [mkdir -p](https://en.wikipedia.org/wiki/Mkdir) It will generate the full directory path if it does not already exist.
func NewTranslator ¶
func NewTranslator(supportedLocales []locales.Translator, localeRegisterDefaultTranslations LocaleRegisterDefaultTranslations) *translator
func ReadTextFile ¶
ReadTextFile reads a text file and converts results from bytes to a string.
func Touch ¶
Touch Similar to the touch command on *nix, where the file or directory will be created if it does not already exist. Returns the absolute path. The optional second boolean argument will force the method to treat the path as a file instead of a directory (useful when the filename has no extension). An optional 3rd boolean argument will force the method to treat the path as a directory even if a file extension is present.
For example: `fsx.Touch("./path/to/archive.old", false, true)`
Normally, any file path with an extension is determined to be a file. However; the second argument (`false`) instructs the command to **not** force a file. The third argument (`true`) instructs the command to **treat the path like a directory**.
func WriteTextFile ¶
WriteTextFile writes text to a file (automatically converts string to a byte array). If the path does not exist, it will be created automatically. This is the equivalent of using the Touch() method first, then writing text content to the file.
It is also possible to pass a third argument, a custom permission. By default, os.ModePerm is used.
func XmlBaseResponse ¶
XmlBaseResponse writes v into w with http.StatusOK.
Types ¶
type BaseResponse ¶
type BaseResponse[T any] struct { // Code represents the business code, not the http status code. Code int `json:"code" xml:"code"` // Msg represents the business message, if Code = BusinessCodeOK, // and Msg is empty, then the Msg will be set to BusinessMsgOk. Msg string `json:"msg" xml:"msg"` // Data represents the business data. Data T `json:"data,omitempty" xml:"data,omitempty"` }
type Engine ¶
func (*Engine) BindingValidatorEngine ¶
func (*Engine) Controller ¶
func (e *Engine) Controller(controllers ...IController)
func (*Engine) PrefixController ¶
func (e *Engine) PrefixController(prefix string, controllers ...IController)
type GinContext ¶
func (*GinContext) All ¶ added in v0.1.2
func (c *GinContext) All() GinContextInput
type GinContextInput ¶ added in v0.1.2
type IController ¶
type IPlugin ¶
type IPlugin interface { Register(group *gin.RouterGroup) RouterPath() string }
type IResponse ¶
type IResponse interface { //WithStatusCode 携带状态码 WithStatusCode(statusCode int) //StatusCode 响应状态码 StatusCode() int //Abort 是否抛出异常 Abort() bool //Render 渲染数据 Render() render.Render }
IResponse 响应状态码根据你传入的状态码走
type IResponseStatusRuleFun ¶
type JsonResponse ¶
type JsonResponse struct { Code int `json:"code"` Message string `json:"message"` Data any `json:"data"` Error error `json:"-"` }
func (*JsonResponse) SetErr ¶
func (j *JsonResponse) SetErr(err error)
func (*JsonResponse) WithMessage ¶
func (j *JsonResponse) WithMessage(message string)
WithMessage 携带错误消息信息
func (*JsonResponse) WithStatusCode ¶
func (j *JsonResponse) WithStatusCode(code int)
WithStatusCode 携带状态码
type LocaleRegisterDefaultTranslations ¶
type LocaleRegisterDefaultTranslations func(locale string, v *validator.Validate, UtTranslator ut.Translator)
type ValidateError ¶
func (*ValidateError) Error ¶
func (v *ValidateError) Error() string
type ValidateErrors ¶
type ValidateErrors []*ValidateError
func (ValidateErrors) Error ¶
func (v ValidateErrors) Error() string
func (ValidateErrors) Errors ¶
func (v ValidateErrors) Errors() []string