Documentation
¶
Index ¶
Constants ¶
const ( Version = "0.0.1" UTF8 = "UTF-8" )
const ( CONNECT = "CONNECT" DELETE = "DELETE" GET = "GET" HEAD = "HEAD" OPTIONS = "OPTIONS" PATCH = "PATCH" POST = "POST" PROPFIND = "PROPFIND" PUT = "PUT" TRACE = "TRACE" )
HTTP methods
const ( 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" )
MIME types
const ( HeaderAccept = "Accept" HeaderAcceptEncoding = "Accept-Encoding" 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" 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" HeaderXRequestedWith = "X-Requested-With" HeaderServer = "Server" HeaderOrigin = "Origin" HeaderExpires = "Expires" HeaderCacheControl = "Cache-Control" HeaderPragma = "Pragma" // 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" HeaderXCSRFToken = "X-CSRF-Token" )
Headers
const (
// GlobalFileName is the name of the global program configuration file
GlobalFileName = "__global.yaml"
)
The configuration program uses viper;see: github.com/spf13/viper The structure tag uses `mapstructure` When writing a file, the tag changes according to the file type. For example, json, yaml...
Variables ¶
var ( ErrUnsupportedMediaType = NewHTTPError(http.StatusUnsupportedMediaType) ErrNotFound = NewHTTPError(http.StatusNotFound) ErrForbidden = NewHTTPError(http.StatusForbidden) ErrMethodNotAllowed = NewHTTPError(http.StatusMethodNotAllowed) ErrStatusRequestEntityTooLarge = NewHTTPError(http.StatusRequestEntityTooLarge) ErrValidatorNotRegistered = errors.New("validator not registered") ErrRendererNotRegistered = errors.New("renderer not registered") ErrInvalidRedirectCode = errors.New("invalid redirect status code") ErrCookieNotFound = errors.New("cookie not found") )
Errors
var ( //Queue External configuration, you must pass the queue in the use method. Queue = make(chan func()) Job = grpool.NewPool(100, runtime.NumCPU()) )
var ( DefaultProcess = Process{ ListenPort: 8100, Mode: "release", CacheType: "memory", Secret: gofutils.NewRandom(gofutils.Crs).RandomString(32), } DefaultRedis = Redis{ Addr: "127.0.0.1:6379", Password: "", } DefaultLog = Log{ ConsoleEnable: true, FileEnable: true, FilePath: "logs/web" + gofutils.Delimiter, } )
Functions ¶
func AddJobWithTimeout ¶
AddJobWithTimeout Add a co-procedure with a timeout constraint Add timeout validation and exit the current goroutine automatically after more than 10 seconds.
func Initialize ¶
func Initialize()
Initialize ... This method needs to be referenced when the configuration file needs to be initialized
func ReadObjInformation ¶
ReadObjInformation Read information from the configuration file into a global variable, and if there is no information about the object in the configuration file, write the initial properties of the object to the configuration file.
Types ¶
type HTTPError ¶
type HTTPError struct { Code int `json:"code"` Message interface{} `json:"message"` Internal error `json:"-"` //Errors returned by external dependencies can be stored }
HTTPError represents an error that occurred while handling a request.
func NewHTTPError ¶
NewHTTPError creates a new HTTPError instance.
type Log ¶
type Log struct { ConsoleEnable bool FileEnable bool FilePath string // Program current directory;`logs/web` }
Log Log system Settings The server log system is placed in the "logs/web" directory. Whenever the log file size exceeds 1MB, the system will automatically backup the log file. The system will only back up the log file for the last 3 days.
type Process ¶
type Process struct { // Key string `mapstructure:"-"` //the name of config key ListenPort int // server listen port Mode string // program run mode,debug or release CacheType string // redis or memory Secret string // program secret , use to jwt ReadTimeOut time.Duration WriteTimeOut time.Duration }
Process Program global configuration items