web

package
v0.0.0-...-2e936b0 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2023 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddSpan

func AddSpan(ctx context.Context, spanName string, keyValues ...attribute.KeyValue) (context.Context, trace.Span)

AddSpan adds a OpenTelemetry span to the trace and context.

func Decode

func Decode(r *http.Request, val any) error

Decode reads the body of an HTTP request looking for a JSON document. The body is decoded into the provided value. If the provided value is a struct then it is checked for validation tags. If the value implements a validate function, it is executed.

func GetTime

func GetTime(ctx context.Context) time.Time

GetTime returns the time from the context.

func GetTraceID

func GetTraceID(ctx context.Context) string

GetTraceID returns the trace id from the context.

func IsShutdownError

func IsShutdownError(err error) bool

IsShutdownError checks to see if the shutdown error is contained in the specified error value.

func NewShutdownError

func NewShutdownError(message string) error

NewShutdownError returns an error that causes the framework to signal a graceful shutdown.

func Param

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

Param returns the web call parameters from the request.

func Respond

func Respond(ctx context.Context, w http.ResponseWriter, data any, statusCode int) error

Respond convert a struct go value to json and send it.

func SetStatusCode

func SetStatusCode(ctx context.Context, statusCode int)

SetStatusCode sets the status code back into the context.

func SetValues

func SetValues(ctx context.Context, v *Values) context.Context

SetValues set the specified values in the condext.

Types

type App

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

App is the entrypoint of out application.

func NewApp

func NewApp(shutdown chan os.Signal, tracer trace.Tracer, log *logger.Logger, mw ...Middleware) *App

NewApp creates new instance of our application.

func (*App) EnableCORS

func (a *App) EnableCORS(mw Middleware)

EnableCORS enables CORS preflight requests to work in the middleware. It prevents the MethodNotAllowedHandler from being called. This must be enabled for the CORS middleware to work.

func (*App) Handle

func (a *App) Handle(method string, group string, path string, handler Handler, mw ...Middleware)

Handle sets a handler function for a given HTTP method.

func (*App) ServeHTTP

func (a *App) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP implements the http.Handler interface.

func (*App) SignalShutdown

func (a *App) SignalShutdown()

SignalShutdown is used to gracefully shut down the app.

type Handler

type Handler func(ctx context.Context, w http.ResponseWriter, r *http.Request) error

Handler is a type that handles an HTTP request.

type MessageResponse

type MessageResponse struct {
	Msg string `json:"message"`
}

type Middleware

type Middleware func(Handler) Handler

Middleware is a function designed to run before and/or after some Handler.

type Values

type Values struct {
	TraceID    string
	Tracer     trace.Tracer
	Now        time.Time
	StatusCode int
}

Values represent state for each request.

func GetValues

func GetValues(ctx context.Context) *Values

GetValues returns the values from the context.

Jump to

Keyboard shortcuts

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