gof

package module
v1.0.5 Latest Latest
Warning

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

Go to latest
Published: Apr 12, 2021 License: MIT Imports: 17 Imported by: 0

README

GOF

Documentation

Index

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)
	ErrUnauthorized          = NewHTTPError(http.StatusUnauthorized)
	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)
	ErrServiceUnavailable    = NewHTTPError(http.StatusServiceUnavailable)
	ErrInvalidRedirectCode   = errors.New("invalid redirect status code")
)

Functions

func BindData

func BindData(destination interface{}, data map[string][]string, tag string) error

func BindGetter

func BindGetter(destination interface{}, getter BindGetterFunc, tag string) error

func GetMode

func GetMode() string

func GetPostForm

func GetPostForm(r *http.Request, key string) (string, bool)

func GetPostFormArray

func GetPostFormArray(r *http.Request, key string) ([]string, bool)

func GetQuery

func GetQuery(r *http.Request, key string) (string, bool)

func GetQueryArray

func GetQueryArray(r *http.Request, key string) ([]string, bool)

func IsDevMode

func IsDevMode() bool

func JSON

func JSON(w http.ResponseWriter, code int, i interface{}) error

func NewSwagger

func NewSwagger(logger Logger, specFilepath, uiTitle string) *swagger

func OK

func OK(w http.ResponseWriter, i interface{}) error

func PostForm

func PostForm(r *http.Request, key string) string

func PostFormArray

func PostFormArray(r *http.Request) map[string][]string

func Query

func Query(r *http.Request, key string) string

func QueryArray

func QueryArray(r *http.Request) map[string][]string

func RealIP

func RealIP(r *http.Request) string

func Redirect

func Redirect(w http.ResponseWriter, code int, url string) error

func SetMode

func SetMode(newMode string)

Types

type BindGetterFunc

type BindGetterFunc func(interface{}) (interface{}, bool)

type Binder

type Binder interface {
	Bind(r *http.Request, i interface{}) error
}

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

func (*BinderList) Bind

func (b *BinderList) Bind(r *http.Request, i interface{}) error

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 NewHTTPError(statusCode int, data ...interface{}) *HTTPError

func (*HTTPError) Error

func (e *HTTPError) Error() string

func (*HTTPError) Log

func (e *HTTPError) Log(logger Logger) *HTTPError

func (*HTTPError) Marshal

func (e *HTTPError) Marshal() []byte

func (*HTTPError) Set

func (e *HTTPError) Set(data ...interface{}) *HTTPError

func (*HTTPError) SetErrors

func (e *HTTPError) SetErrors(errs []interface{}) *HTTPError

func (*HTTPError) SetInternal

func (e *HTTPError) SetInternal(err error) *HTTPError

func (*HTTPError) SetMessage

func (e *HTTPError) SetMessage(message string) *HTTPError

func (*HTTPError) Unwrap

func (e *HTTPError) Unwrap() error

func (*HTTPError) Write

func (e *HTTPError) Write(w http.ResponseWriter) error

type Health

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

func NewHealth

func NewHealth(logger Logger, db HealthDatabase) *Health

func (*Health) Health

func (h *Health) Health(w http.ResponseWriter, _ *http.Request)

func (*Health) Ping

func (h *Health) Ping(w http.ResponseWriter, _ *http.Request)

func (*Health) Register

func (h *Health) Register(router *mux.Router)

type HealthDatabase

type HealthDatabase interface {
	Ping() error
}

type HealthResponse

type HealthResponse struct {
	Health   string `json:"health"`
	Database string `json:"database,omitempty"`
}

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

type LoggerWriterConfig struct {
	Name   string   `default:"logs/app.log" required:"true"` // file, stderr, stdout
	Levels []string `yaml:"levels" json:"levels"`
}

type Swagger

type Swagger interface {
	Register(*mux.Router)
	SwaggerYaml(http.ResponseWriter, *http.Request)
	SwaggerUI(http.ResponseWriter, *http.Request)
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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