gofconf

package
v0.0.0-...-40c044f Latest Latest
Warning

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

Go to latest
Published: May 16, 2019 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Version = "0.0.1"
	UTF8    = "UTF-8"
)
View Source
const (
	CONNECT  = "CONNECT"
	DELETE   = "DELETE"
	GET      = "GET"
	HEAD     = "HEAD"
	OPTIONS  = "OPTIONS"
	PATCH    = "PATCH"
	POST     = "POST"
	PROPFIND = "PROPFIND"
	PUT      = "PUT"
	TRACE    = "TRACE"
)

HTTP methods

View Source
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

View Source
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

View Source
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

View Source
var (
	ErrUnsupportedMediaType        = NewHTTPError(http.StatusUnsupportedMediaType)
	ErrNotFound                    = NewHTTPError(http.StatusNotFound)
	ErrUnauthorized                = NewHTTPError(http.StatusUnauthorized)
	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

View Source
var (
	//Queue External configuration, you must pass the queue in the use method.
	Queue = make(chan func())
	Job   = grpool.NewPool(100, runtime.NumCPU())
)
View Source
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 AddDefaultInformation

func AddDefaultInformation(obj ...Init)

AddDefaultInformation ...

func AddJobWithTimeout

func AddJobWithTimeout(out time.Duration, fn func())

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

func ReadObjInformation(ptr Init) error

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

func NewHTTPError(code int, message ...interface{}) *HTTPError

NewHTTPError creates a new HTTPError instance.

func (*HTTPError) Error

func (he *HTTPError) Error() string

Error makes it compatible with `error` interface.

type Init

type Init interface {
	InitFunc() error
}

Init ...

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.

func (*Log) InitFunc

func (p *Log) InitFunc() error

InitFunc ReadIn ...

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

func (*Process) InitFunc

func (p *Process) InitFunc() error

InitFunc ReadIn ...

type Redis

type Redis struct {
	Addr     string // redis server address;example:127.0.0.1:6379
	Password string
	DB       int
}

Redis set;need cacheType = `redis`

func (*Redis) InitFunc

func (p *Redis) InitFunc() error

InitFunc ReadIn ...

Jump to

Keyboard shortcuts

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