Documentation ¶
Index ¶
- Constants
- Variables
- func AddCustomTypeFuncs(customTypeFuncs []CustomTypeFunc) error
- func AddCustomValidators(customValidators []CustomValidator) error
- func AddProfilingEndpoints(r *gin.Engine)
- func AddStructValidators(structValidators []StructValidator) error
- func AddValidateAlias(aliases []ValidateAlias) error
- func Cors(config cfg.Config) gin.HandlerFunc
- func CreateDownloadHandler(handler HandlerWithStream) gin.HandlerFunc
- func CreateHandler(handler HandlerWithoutInput) gin.HandlerFunc
- func CreateJsonHandler(handler HandlerWithInput) gin.HandlerFunc
- func CreateMultiPartFormHandler(handler HandlerWithInput) gin.HandlerFunc
- func CreateMultipleBindingsHandler(handler HandlerWithMultipleBindings) gin.HandlerFunc
- func CreateQueryHandler(handler HandlerWithInput) gin.HandlerFunc
- func CreateRawHandler(handler HandlerWithoutInput) gin.HandlerFunc
- func CreateReaderHandler(handler HandlerWithoutInput) gin.HandlerFunc
- func CreateSseHandler(handler HandlerWithStream) gin.HandlerFunc
- func CreateStreamHandler(handler HandlerWithStream) gin.HandlerFunc
- func GetStringFromRequest(request *Request, name string) (*string, bool)
- func GetUintFromRequest(request *Request, name string) (*uint, bool)
- func HttpTest(method string, path string, requestPath string, body string, ...) *httptest.ResponseRecorder
- func LoggingMiddleware(logger log.Logger, settings LoggingSettings) gin.HandlerFunc
- func New(definer Definer) kernel.ModuleFactory
- func NewApiHealthCheck() kernel.ModuleFactory
- func NewCountingBodyReader(reader io.ReadCloser) (io.ReadCloser, *int)
- func NewCountingBodyWriter(writer gin.ResponseWriter) (gin.ResponseWriter, *int)
- func NewGZipBodyReader(body io.ReadCloser) (io.ReadCloser, *int, error)
- func NewMetricMiddleware() (gin.HandlerFunc, func(definitions []Definition))
- func NewProfiling() kernel.ModuleFactory
- func RecoveryWithSentry(logger log.Logger) gin.HandlerFunc
- func WithCustomModifier(modifier Modifier)
- func WithErrorHandler(handler ErrorHandler)
- type ApiHealthCheck
- type ApiHealthCheckSettings
- type ApiServer
- type CompressionExcludeSettings
- type CompressionSettings
- type CustomTypeFunc
- type CustomValidator
- type Definer
- type Definition
- type Definitions
- func (d *Definitions) DELETE(relativePath string, handlers ...gin.HandlerFunc)
- func (d *Definitions) GET(relativePath string, handlers ...gin.HandlerFunc)
- func (d *Definitions) Group(relativePath string) *Definitions
- func (d *Definitions) Handle(httpMethod, relativePath string, handlers ...gin.HandlerFunc)
- func (d *Definitions) OPTIONS(relativePath string, handlers ...gin.HandlerFunc)
- func (d *Definitions) POST(relativePath string, handlers ...gin.HandlerFunc)
- func (d *Definitions) PUT(relativePath string, handlers ...gin.HandlerFunc)
- func (d *Definitions) Use(middleware ...gin.HandlerFunc)
- type ErrorHandler
- type HandlerMetadata
- type HandlerWithInput
- type HandlerWithMultipleBindings
- type HandlerWithStream
- type HandlerWithoutInput
- type LoggingSettings
- type Modifier
- type Profiling
- type ProfilingSettings
- type Request
- type Response
- type ResponseBodyWriterError
- type Settings
- type StructValidator
- type TimeoutSettings
- type ValidateAlias
Constants ¶
const ( ApiViewKey = "X-Api-View" ContentTypeHtml = "text/html; charset=utf-8" ContentTypeJson = "application/json; charset=utf-8" )
const ( MetricApiRequestCount = "ApiRequestCount" MetricApiRequestResponseTime = "ApiRequestResponseTime" )
const ( BaseProfiling = "/debug/profiling" CmdLine = "/cmdline" Profile = "/profile" Symbol = "/symbol" Trace = "/trace" Allocs = "/allocs" Block = "/block" GoRoutine = "/goroutine" Heap = "/heap" Mutex = "/mutex" ThreadCreate = "/threadcreate" )
Variables ¶
var ErrAccessForbidden = errors.New("cant access resource")
Functions ¶
func AddCustomTypeFuncs ¶
func AddCustomTypeFuncs(customTypeFuncs []CustomTypeFunc) error
func AddCustomValidators ¶
func AddCustomValidators(customValidators []CustomValidator) error
func AddProfilingEndpoints ¶
func AddStructValidators ¶
func AddStructValidators(structValidators []StructValidator) error
func AddValidateAlias ¶
func AddValidateAlias(aliases []ValidateAlias) error
func CreateDownloadHandler ¶
func CreateDownloadHandler(handler HandlerWithStream) gin.HandlerFunc
func CreateHandler ¶
func CreateHandler(handler HandlerWithoutInput) gin.HandlerFunc
func CreateJsonHandler ¶
func CreateJsonHandler(handler HandlerWithInput) gin.HandlerFunc
func CreateMultiPartFormHandler ¶
func CreateMultiPartFormHandler(handler HandlerWithInput) gin.HandlerFunc
func CreateMultipleBindingsHandler ¶
func CreateMultipleBindingsHandler(handler HandlerWithMultipleBindings) gin.HandlerFunc
func CreateQueryHandler ¶
func CreateQueryHandler(handler HandlerWithInput) gin.HandlerFunc
func CreateRawHandler ¶
func CreateRawHandler(handler HandlerWithoutInput) gin.HandlerFunc
func CreateReaderHandler ¶
func CreateReaderHandler(handler HandlerWithoutInput) gin.HandlerFunc
func CreateSseHandler ¶
func CreateSseHandler(handler HandlerWithStream) gin.HandlerFunc
func CreateStreamHandler ¶
func CreateStreamHandler(handler HandlerWithStream) gin.HandlerFunc
func GetStringFromRequest ¶
func HttpTest ¶
func HttpTest(method string, path string, requestPath string, body string, handler gin.HandlerFunc, requestOptions ...func(r *http.Request)) *httptest.ResponseRecorder
func LoggingMiddleware ¶
func LoggingMiddleware(logger log.Logger, settings LoggingSettings) gin.HandlerFunc
func New ¶
func New(definer Definer) kernel.ModuleFactory
func NewApiHealthCheck ¶
func NewApiHealthCheck() kernel.ModuleFactory
func NewCountingBodyReader ¶
func NewCountingBodyReader(reader io.ReadCloser) (io.ReadCloser, *int)
func NewCountingBodyWriter ¶
func NewCountingBodyWriter(writer gin.ResponseWriter) (gin.ResponseWriter, *int)
func NewGZipBodyReader ¶
func NewGZipBodyReader(body io.ReadCloser) (io.ReadCloser, *int, error)
func NewMetricMiddleware ¶
func NewMetricMiddleware() (gin.HandlerFunc, func(definitions []Definition))
func NewProfiling ¶
func NewProfiling() kernel.ModuleFactory
func RecoveryWithSentry ¶
func RecoveryWithSentry(logger log.Logger) gin.HandlerFunc
func WithCustomModifier ¶
func WithCustomModifier(modifier Modifier)
func WithErrorHandler ¶
func WithErrorHandler(handler ErrorHandler)
Types ¶
type ApiHealthCheck ¶
type ApiHealthCheck struct { kernel.BackgroundModule kernel.ServiceStage // contains filtered or unexported fields }
func NewApiHealthCheckWithInterfaces ¶
func NewApiHealthCheckWithInterfaces(logger log.Logger, router *gin.Engine, healthChecker kernel.HealthChecker, settings *ApiHealthCheckSettings) *ApiHealthCheck
type ApiHealthCheckSettings ¶
type ApiServer ¶
type ApiServer struct { kernel.EssentialModule kernel.ServiceStage // contains filtered or unexported fields }
func NewWithInterfaces ¶
type CompressionExcludeSettings ¶
type CompressionExcludeSettings struct { Extension []string `cfg:"extension"` Path []string `cfg:"path"` PathRegex []string `cfg:"path_regex"` }
CompressionExcludeSettings allow enabling of gzip support.
type CompressionSettings ¶
type CompressionSettings struct { Level string `cfg:"level" default:"default" validate:"oneof=none default best fast 0 1 2 3 4 5 6 7 8 9"` Decompression bool `cfg:"decompression" default:"true"` // Exclude files by path, extension, or regular expression from being considered for compression. Useful if you are serving a format unknown to Gosoline. Exclude CompressionExcludeSettings `cfg:"exclude"` }
CompressionSettings control gzip support for requests and responses. By default, compressed requests are accepted and compressed responses are returned (if accepted by the client).
type CustomTypeFunc ¶
type CustomTypeFunc struct { Func validator.CustomTypeFunc Types []interface{} }
A CustomTypeFunc allows you to convert one type to another type before validation. This allows you to validate custom types with the built-in functions for, e.g., integers or strings.
type CustomValidator ¶
type CustomValidator struct { Name string Validator validator.Func }
A CustomValidator allows you to validate single fields with custom rules. If you need to validate a whole struct, you need to use a StructValidator. See https://github.com/go-playground/validator/issues/470 for more details.
type Definition ¶
type Definition struct {
// contains filtered or unexported fields
}
type Definitions ¶
type Definitions struct {
// contains filtered or unexported fields
}
func (*Definitions) DELETE ¶
func (d *Definitions) DELETE(relativePath string, handlers ...gin.HandlerFunc)
func (*Definitions) GET ¶
func (d *Definitions) GET(relativePath string, handlers ...gin.HandlerFunc)
func (*Definitions) Group ¶
func (d *Definitions) Group(relativePath string) *Definitions
func (*Definitions) Handle ¶
func (d *Definitions) Handle(httpMethod, relativePath string, handlers ...gin.HandlerFunc)
func (*Definitions) OPTIONS ¶
func (d *Definitions) OPTIONS(relativePath string, handlers ...gin.HandlerFunc)
func (*Definitions) POST ¶
func (d *Definitions) POST(relativePath string, handlers ...gin.HandlerFunc)
func (*Definitions) PUT ¶
func (d *Definitions) PUT(relativePath string, handlers ...gin.HandlerFunc)
func (*Definitions) Use ¶
func (d *Definitions) Use(middleware ...gin.HandlerFunc)
type ErrorHandler ¶
func GetErrorHandler ¶
func GetErrorHandler() ErrorHandler
type HandlerMetadata ¶
type HandlerMetadata struct { // Method is the route method of this Handler. Method string `json:"method"` // Path is the route path ot this handler. Path string `json:"path"` }
HandlerMetadata stores the Path and Method of this Handler.
type HandlerWithInput ¶
type HandlerWithInput interface { HandlerWithoutInput GetInput() interface{} }
type HandlerWithMultipleBindings ¶
type HandlerWithMultipleBindings interface { HandlerWithInput GetBindings() []binding.Binding }
type HandlerWithStream ¶
type HandlerWithoutInput ¶
type LoggingSettings ¶ added in v0.11.3
type Profiling ¶
type Profiling struct { kernel.BackgroundModule kernel.ServiceStage // contains filtered or unexported fields }
type ProfilingSettings ¶
type ProfilingSettings struct {
Port int `cfg:"port" default:"8091"`
}
type Response ¶
type Response struct { Body interface{} ContentType *string // might be nil Header http.Header StatusCode int }
Don't create a response directly, use New*Response instead
func NewHtmlResponse ¶
func NewHtmlResponse(body interface{}) *Response
func NewJsonResponse ¶
func NewJsonResponse(body interface{}) *Response
func NewRedirectResponse ¶
func NewResponse ¶
func NewStatusResponse ¶
func (*Response) WithContentType ¶
type ResponseBodyWriterError ¶
type ResponseBodyWriterError struct {
Err error
}
func (ResponseBodyWriterError) Error ¶
func (e ResponseBodyWriterError) Error() string
func (ResponseBodyWriterError) Is ¶
func (e ResponseBodyWriterError) Is(err error) bool
func (ResponseBodyWriterError) Unwrap ¶
func (e ResponseBodyWriterError) Unwrap() error
type Settings ¶
type Settings struct { // Port the API listens to. Port string `cfg:"port" default:"8080"` // Mode is either debug, release, test. Mode string `cfg:"mode" default:"release" validate:"oneof=release debug test"` // Compression settings. Compression CompressionSettings `cfg:"compression"` // Timeout settings. Timeout TimeoutSettings `cfg:"timeout"` // Logging settings Logging LoggingSettings `cfg:"logging"` }
Settings structure for an API server.
type StructValidator ¶
type StructValidator struct { Struct interface{} Validator validator.StructLevelFunc }
A StructValidator validates every instance of a struct type with the given validation. It is a little bit unfortunate because you now can't have different validation rules for a struct at different places.
type TimeoutSettings ¶
type TimeoutSettings struct { // You need to give at least 1s as timeout. // Read timeout is the maximum duration for reading the entire request, including the body. Read time.Duration `cfg:"read" default:"60s" validate:"min=1000000000"` // Write timeout is the maximum duration before timing out writes of the response. Write time.Duration `cfg:"write" default:"60s" validate:"min=1000000000"` // Idle timeout is the maximum amount of time to wait for the next request when keep-alives are enabled Idle time.Duration `cfg:"idle" default:"60s" validate:"min=1000000000"` }
TimeoutSettings configures IO timeouts.
type ValidateAlias ¶
A ValidateAlias allows you to map one or more tags to a different name, making your validation rules easier to read.