Documentation ¶
Index ¶
- Constants
- Variables
- func BindData(destination interface{}, data map[string][]string, tag string) error
- func BindGetter(destination interface{}, getter BindGetterFunc, tag string) error
- func GetMode() string
- func GetPostForm(r *http.Request, key string) (string, bool)
- func GetPostFormArray(r *http.Request, key string) ([]string, bool)
- func GetQuery(r *http.Request, key string) (string, bool)
- func GetQueryArray(r *http.Request, key string) ([]string, bool)
- func IsDevMode() bool
- func JSON(w http.ResponseWriter, code int, i interface{}) error
- func NewSwagger(logger Logger, specFilepath, uiTitle string) *swagger
- func OK(w http.ResponseWriter, i interface{}) error
- func PostForm(r *http.Request, key string) string
- func PostFormArray(r *http.Request) map[string][]string
- func Query(r *http.Request, key string) string
- func QueryArray(r *http.Request) map[string][]string
- func RealIP(r *http.Request) string
- func Redirect(w http.ResponseWriter, code int, url string) error
- func SetMode(newMode string)
- type BindGetterFunc
- type Binder
- type BinderList
- type HTTPError
- func (e *HTTPError) Error() string
- func (e *HTTPError) Log(logger Logger) *HTTPError
- func (e *HTTPError) Marshal() []byte
- func (e *HTTPError) Set(data ...interface{}) *HTTPError
- func (e *HTTPError) SetErrors(errs []interface{}) *HTTPError
- func (e *HTTPError) SetInternal(err error) *HTTPError
- func (e *HTTPError) SetMessage(message string) *HTTPError
- func (e *HTTPError) Unwrap() error
- func (e *HTTPError) Write(w http.ResponseWriter) error
- type Health
- type HealthDatabase
- type HealthResponse
- type Logger
- type LoggerConfig
- type LoggerFields
- type LoggerLevel
- type LoggerWriterConfig
- type Swagger
Constants ¶
View Source
const ( PingURL = "/ping" HealthURL = "/health" StatusGreen = "green" StatusOrange = "orange" StatusRed = "red" )
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 MIMEApplicationYaml = "application/x-yaml" MIMEApplicationYamlCharsetUTF8 = MIMEApplicationYaml + "; " + 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 ( // 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" )
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" // 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" )
Headers
View Source
const ( WriterStderr = "stderr" WriterStdout = "stdout" )
View Source
const ( DevMode = "development" ProdMode = "production" TestMode = "test" )
View Source
const ( SwaggerYamlURL = "/swagger.yaml" SwaggerUIURL = "/swagger" SwaggerTemplate = `` /* 927-byte string literal not displayed */ )
Variables ¶
View Source
var ( QueryBinder = new(queryBinder) ParamBinder = new(paramBinder) HeaderBinder = new(headerBinder) ContextBinder = new(contextBinder) BodyBinder = new(bodyBinder) DefaultChainOfBinders = NewChain(QueryBinder, ParamBinder, HeaderBinder, ContextBinder, BodyBinder) ErrBindNoStruct = errors.New("binding element must be a struct") )
View Source
var ( ErrBadRequest = NewHTTPError(http.StatusBadRequest) ErrForbidden = NewHTTPError(http.StatusForbidden) ErrNotFound = NewHTTPError(http.StatusNotFound) ErrMethodNotAllowed = NewHTTPError(http.StatusMethodNotAllowed) ErrRequestTimeout = NewHTTPError(http.StatusRequestTimeout) ErrConflict = NewHTTPError(http.StatusConflict) ErrRequestEntityTooLarge = NewHTTPError(http.StatusRequestEntityTooLarge) ErrUnsupportedMediaType = NewHTTPError(http.StatusUnsupportedMediaType) ErrTeapot = NewHTTPError(http.StatusTeapot) ErrUnprocessableEntity = NewHTTPError(http.StatusUnprocessableEntity) ErrTooManyRequests = NewHTTPError(http.StatusTooManyRequests) ErrInternalServerError = NewHTTPError(http.StatusInternalServerError) ErrBadGateway = NewHTTPError(http.StatusBadGateway) ErrInvalidRedirectCode = errors.New("invalid redirect status code") )
Functions ¶
func BindGetter ¶
func BindGetter(destination interface{}, getter BindGetterFunc, tag string) error
func NewSwagger ¶
func OK ¶
func OK(w http.ResponseWriter, i interface{}) error
Types ¶
type BindGetterFunc ¶
type BindGetterFunc func(interface{}) (interface{}, bool)
type BinderList ¶
type BinderList struct {
// contains filtered or unexported fields
}
func NewChain ¶
func NewChain(binders ...Binder) *BinderList
func (*BinderList) Add ¶
func (b *BinderList) Add(binders ...Binder) *BinderList
type HTTPError ¶
type HTTPError struct { Internal error `json:"-"` StatusCode int `json:"-"` Code string `json:"code,omitempty"` Message string `json:"message"` DeveloperMessage string `json:"developer_message,omitempty"` Errors []interface{} `json:"errors,omitempty"` }
func NewHTTPError ¶
func (*HTTPError) SetInternal ¶
func (*HTTPError) SetMessage ¶
type Health ¶
type Health struct {
// contains filtered or unexported fields
}
func NewHealth ¶
func NewHealth(logger Logger, db HealthDatabase) *Health
type HealthDatabase ¶
type HealthDatabase interface {
Ping() error
}
type HealthResponse ¶
type Logger ¶
type Logger interface { Level() LoggerLevel WithField(key string, value interface{}) Logger WithFields(fields LoggerFields) Logger WithError(err error) Logger Printf(format string, args ...interface{}) Debugf(format string, args ...interface{}) Infof(format string, args ...interface{}) Warnf(format string, args ...interface{}) Errorf(format string, args ...interface{}) Fatalf(format string, args ...interface{}) Panicf(format string, args ...interface{}) Print(args ...interface{}) Debug(args ...interface{}) Info(args ...interface{}) Warn(args ...interface{}) Error(args ...interface{}) Fatal(args ...interface{}) Panic(args ...interface{}) }
func NewLogger ¶
func NewLogger(cfg LoggerConfig) Logger
type LoggerConfig ¶
type LoggerConfig struct { Level string `default:"info" yaml:"level" json:"level"` Formatter string `default:"text" yaml:"formatter" json:"formatter"` Fields LoggerFields `yaml:"fields" json:"fields"` Writers []LoggerWriterConfig `yaml:"writers" json:"writers"` }
type LoggerFields ¶
type LoggerFields map[string]interface{}
type LoggerLevel ¶
type LoggerLevel uint32
const ( PanicLevel LoggerLevel = iota FatalLevel ErrorLevel WarnLevel InfoLevel DebugLevel )
func ParseLevel ¶
func ParseLevel(lvl string) (LoggerLevel, error)
type LoggerWriterConfig ¶
Source Files ¶
Click to show internal directories.
Click to hide internal directories.