ginruntime

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Apr 12, 2024 License: MIT Imports: 27 Imported by: 0

Documentation

Index

Constants

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

func GetStack() (GoRoutine, []Frame)

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

func RecoveryMiddleware(c *gin.Context)

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

func StackTraceMarshaller(err error) any

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

type ApiError struct {
	Detail error
	Reason string
	Status int
}

Server response status code and associated error message

func BadRequest added in v0.3.0

func BadRequest(reason string) *ApiError

func FailedDependency added in v0.3.0

func FailedDependency(reason string) *ApiError

func Forbidden added in v0.3.0

func Forbidden(reason string) *ApiError

func InternalServerError added in v0.3.0

func InternalServerError(reason string) *ApiError

func Normalize added in v0.3.0

func Normalize(err error) *ApiError

Converts `err` to an `*ApiError` if it's not nil.

func NotFound added in v0.3.0

func NotFound(reason string) *ApiError

func NotImplemented added in v0.3.0

func NotImplemented(reason string) *ApiError

func Unauthorized added in v0.3.0

func Unauthorized(reason string) *ApiError

func UnprocessableEntity added in v0.3.0

func UnprocessableEntity(reason string) *ApiError

func (*ApiError) Error

func (this *ApiError) Error() string

type Frame added in v0.6.1

type Frame struct {
	File     string
	Line     string
	Function string
}

type GinEngine

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

func New added in v0.5.0

func New(ctx context.Context, options ...Option) *GinEngine

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 (e *GinEngine) LoadHTLMGlob(path string, funcMap template.FuncMap)

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 (e *GinEngine) OpenAPIEnabled() bool

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 (e *GinEngine) StaticDirectory(path string)

func (*GinEngine) TracingEnabled added in v0.5.0

func (e *GinEngine) TracingEnabled() bool

func (*GinEngine) Use added in v0.2.7

func (e *GinEngine) Use(middleware ...gin.HandlerFunc)

Adds middleware

type GoRoutine added in v0.6.1

type GoRoutine = string

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

func WithXRayTracing(
	service string,
) Option

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

type StackTrace struct {
	GoRoutine string
	Stack     []Frame
	Reason    any
}

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
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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