Documentation ¶
Index ¶
- Constants
- func ErrorHandler() gin.HandlerFunc
- func GetStack() (GoRoutine, []Frame)
- func IsRunningAsLambda() bool
- func RecoveryMiddleware(c *gin.Context)
- func StackTraceMarshaller(err error) any
- type ApiError
- func BadRequest(reason string) *ApiError
- func FailedDependency(reason string) *ApiError
- func Forbidden(reason string) *ApiError
- func InternalServerError(reason string) *ApiError
- func Normalize(err error) *ApiError
- func NotFound(reason string) *ApiError
- func NotImplemented(reason string) *ApiError
- func Unauthorized(reason string) *ApiError
- func UnprocessableEntity(reason string) *ApiError
- type Frame
- type GinEngine
- func (e *GinEngine) AddRoute(group *gin.RouterGroup, path string, method int, ...)
- func (e *GinEngine) LoadHTLMGlob(path string, funcMap template.FuncMap)
- func (e *GinEngine) NewGroup(path string, handlers ...gin.HandlerFunc) *gin.RouterGroup
- func (e *GinEngine) OnShutdown(f func())
- func (e *GinEngine) OpenAPIEnabled() bool
- func (e *GinEngine) ServerHttp(recorder *httptest.ResponseRecorder, request *http.Request)
- func (e *GinEngine) StartServer()
- func (e *GinEngine) StaticDirectory(path string)
- func (e *GinEngine) TracingEnabled() bool
- func (e *GinEngine) Use(middleware ...gin.HandlerFunc)
- type GoRoutine
- type OpenAPIOptions
- type Option
- type StackTrace
- type TracingOptions
Constants ¶
const ( GET = iota POST PUT PATCH DELETE )
Exporting constants to avoid hardcoding these all over, and ending up with a uppercase "POST" bug in the future.
Variables ¶
This section is empty.
Functions ¶
func ErrorHandler ¶
func ErrorHandler() gin.HandlerFunc
func GetStack ¶ added in v0.6.1
Extracts the current goroutine and stack. The stack includes the `GetStack` function call and its call to `debug.Stack()`.
func IsRunningAsLambda ¶ added in v0.6.1
func IsRunningAsLambda() bool
func RecoveryMiddleware ¶ added in v0.6.1
Gin middleware for recovering from panics and logging to zerolog. Assumes `StackTraceMarshaller` is being used.
Usage: ```go engine.Use(RecoveryMiddleware) ```
func StackTraceMarshaller ¶ added in v0.6.1
Extracts stack trace from a `StackTrace` error and returns it Usage: ```go zerolog.ErrorStackMarshaler = StackTraceMarshaller goroutine, stack := GetStack() stacktrace := StackTrace{GoRoutine: goroutine, Stack: stack, Reason: r} log.Info().Err(stacktrace).Msg("An error occurred") ```
Types ¶
type ApiError ¶
Server response status code and associated error message
func BadRequest ¶ added in v0.3.0
func FailedDependency ¶ added in v0.3.0
func InternalServerError ¶ added in v0.3.0
func NotImplemented ¶ added in v0.3.0
func Unauthorized ¶ added in v0.3.0
func UnprocessableEntity ¶ added in v0.3.0
type GinEngine ¶
type GinEngine struct {
// contains filtered or unexported fields
}
func (*GinEngine) AddRoute ¶
func (e *GinEngine) AddRoute(group *gin.RouterGroup, path string, method int, annotations openapi.Annotations, handler ...gin.HandlerFunc)
AddRoute Add a new endpoint mapping
func (*GinEngine) LoadHTLMGlob ¶ added in v0.5.1
func (*GinEngine) NewGroup ¶
func (e *GinEngine) NewGroup(path string, handlers ...gin.HandlerFunc) *gin.RouterGroup
func (*GinEngine) OnShutdown ¶ added in v0.5.0
func (e *GinEngine) OnShutdown(f func())
func (*GinEngine) OpenAPIEnabled ¶ added in v1.0.0
func (*GinEngine) ServerHttp ¶
func (e *GinEngine) ServerHttp(recorder *httptest.ResponseRecorder, request *http.Request)
Used for unit testing
func (*GinEngine) StartServer ¶
func (e *GinEngine) StartServer()
func (*GinEngine) StaticDirectory ¶ added in v0.5.1
func (*GinEngine) TracingEnabled ¶ added in v0.5.0
func (*GinEngine) Use ¶ added in v0.2.7
func (e *GinEngine) Use(middleware ...gin.HandlerFunc)
Adds middleware
type OpenAPIOptions ¶ added in v1.0.0
type OpenAPIOptions struct {
// contains filtered or unexported fields
}
type Option ¶ added in v1.0.0
type Option struct {
// contains filtered or unexported fields
}
func WithOpenAPI ¶ added in v1.0.0
func WithOpenAPI( service string, version string, description string, swaggerUiDistUrl string, middleware ...gin.HandlerFunc, ) Option
Enables OpenAPI endpoint `/openapi.json` and Swagger UI endpoint `/docs`.
Routes must be annotated with `openapi.Annotate` to be included in the OpenAPI spec.
The `/docs` endpoint uses `swaggerUiDistUrl` to load JavaScript and CSS for Swagger UI. See here for more information: https://github.com/swagger-api/swagger-ui/blob/master/docs/usage/installation.md
func WithTracing ¶ added in v1.0.0
func WithTracing( service string, tp *trace.TracerProvider, propagator propagation.TextMapPropagator, ) Option
Configures OpenTelemetry for tracing and adds a middleware that traces incoming requests.
func WithXRayTracing ¶ added in v1.0.0
Configures OpenTelemetry for tracing that integrates with AWS X-Ray and adds a middleware that traces incoming requests.
type StackTrace ¶ added in v0.6.1
func (StackTrace) Error ¶ added in v0.6.1
func (s StackTrace) Error() string
func (StackTrace) Skip ¶ added in v0.6.1
func (s StackTrace) Skip(n int) StackTrace
func (StackTrace) SkipFramesAfterPanic ¶ added in v0.6.1
func (s StackTrace) SkipFramesAfterPanic() StackTrace
type TracingOptions ¶ added in v1.0.0
type TracingOptions struct {
// contains filtered or unexported fields
}