http

package
v1.24.0 Latest Latest
Warning

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

Go to latest
Published: Oct 14, 2024 License: Apache-2.0 Imports: 17 Imported by: 17

Documentation

Overview

Package http provides a set of utilities for handling HTTP requests and responses within the GoFr framework.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ErrorEntityAlreadyExist added in v1.8.1

type ErrorEntityAlreadyExist struct {
}

ErrorEntityAlreadyExist represents an error for when entity is already present in the storage and we are trying to make duplicate entry.

func (ErrorEntityAlreadyExist) Error added in v1.8.1

func (ErrorEntityAlreadyExist) StatusCode added in v1.8.1

func (ErrorEntityAlreadyExist) StatusCode() int

type ErrorEntityNotFound added in v1.7.0

type ErrorEntityNotFound struct {
	Name  string
	Value string
}

ErrorEntityNotFound represents an error for when an entity is not found in the system.

func (ErrorEntityNotFound) Error added in v1.7.0

func (e ErrorEntityNotFound) Error() string

func (ErrorEntityNotFound) StatusCode added in v1.7.0

func (ErrorEntityNotFound) StatusCode() int

type ErrorInvalidParam added in v1.7.0

type ErrorInvalidParam struct {
	Params []string `json:"param,omitempty"` // Params contains the list of invalid parameter names.
}

ErrorInvalidParam represents an error for invalid parameter values.

func (ErrorInvalidParam) Error added in v1.7.0

func (e ErrorInvalidParam) Error() string

func (ErrorInvalidParam) StatusCode added in v1.7.0

func (ErrorInvalidParam) StatusCode() int

type ErrorInvalidRoute added in v1.7.0

type ErrorInvalidRoute struct{}

ErrorInvalidRoute represents an error for invalid route in a request.

func (ErrorInvalidRoute) Error added in v1.7.0

func (ErrorInvalidRoute) Error() string

func (ErrorInvalidRoute) StatusCode added in v1.7.0

func (ErrorInvalidRoute) StatusCode() int

type ErrorMissingParam added in v1.7.0

type ErrorMissingParam struct {
	Params []string `json:"param,omitempty"`
}

ErrorMissingParam represents an error for missing parameters in a request.

func (ErrorMissingParam) Error added in v1.7.0

func (e ErrorMissingParam) Error() string

func (ErrorMissingParam) StatusCode added in v1.7.0

func (ErrorMissingParam) StatusCode() int

type ErrorPanicRecovery added in v1.10.0

type ErrorPanicRecovery struct{}

ErrorPanicRecovery represents an error for request which panicked.

func (ErrorPanicRecovery) Error added in v1.10.0

func (ErrorPanicRecovery) Error() string

func (ErrorPanicRecovery) StatusCode added in v1.10.0

func (ErrorPanicRecovery) StatusCode() int

type ErrorRequestTimeout added in v1.10.0

type ErrorRequestTimeout struct{}

ErrorRequestTimeout represents an error for request which timed out.

func (ErrorRequestTimeout) Error added in v1.10.0

func (ErrorRequestTimeout) Error() string

func (ErrorRequestTimeout) StatusCode added in v1.10.0

func (ErrorRequestTimeout) StatusCode() int

type Metrics added in v0.3.0

type Metrics interface {
	IncrementCounter(ctx context.Context, name string, labels ...string)
}

Metrics represents an interface for registering the default metrics in GoFr framework.

type Middleware added in v1.5.0

type Middleware func(handler http.Handler) http.Handler

type Request

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

Request is an abstraction over the underlying http.Request. This abstraction is useful because it allows us to create applications without being aware of the transport. cmd.Request is another such abstraction.

func NewRequest

func NewRequest(r *http.Request) *Request

NewRequest creates a new GoFr Request instance from the given http.Request.

func (*Request) Bind

func (r *Request) Bind(i interface{}) error

Bind parses the request body and binds it to the provided interface.

func (*Request) Context

func (r *Request) Context() context.Context

Context returns the context of the request.

func (*Request) HostName

func (r *Request) HostName() string

HostName retrieves the hostname from the request.

func (*Request) Param

func (r *Request) Param(key string) string

Param returns the query parameter with the given key.

func (*Request) Params added in v1.16.0

func (r *Request) Params(key string) []string

Params returns a slice of strings containing the values associated with the given query parameter key. If the parameter is not present, an empty slice is returned.

func (*Request) PathParam

func (r *Request) PathParam(key string) string

PathParam retrieves a path parameter from the request.

type Responder

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

Responder encapsulates an http.ResponseWriter and is responsible for crafting structured responses.

func NewResponder

func NewResponder(w http.ResponseWriter, method string) *Responder

NewResponder creates a new Responder instance from the given http.ResponseWriter..

func (Responder) Respond

func (r Responder) Respond(data interface{}, err error)

Respond sends a response with the given data and handles potential errors, setting appropriate status codes and formatting responses as JSON or raw data as needed.

type Router

type Router struct {
	mux.Router
	RegisteredRoutes *[]string
}

Router is responsible for routing HTTP request.

func NewRouter

func NewRouter() *Router

NewRouter creates a new Router instance.

func (*Router) Add

func (rou *Router) Add(method, pattern string, handler http.Handler)

Add adds a new route with the given HTTP method, pattern, and handler, wrapping the handler with OpenTelemetry instrumentation.

func (*Router) AddStaticFiles added in v1.12.0

func (rou *Router) AddStaticFiles(endpoint, dirName string)

func (*Router) UseMiddleware added in v1.5.0

func (rou *Router) UseMiddleware(mws ...Middleware)

UseMiddleware registers middlewares to the router.

Directories

Path Synopsis
Package middleware provides a collection of middleware functions that handles various aspects of request handling, such as authentication, logging, tracing, and metrics collection.
Package middleware provides a collection of middleware functions that handles various aspects of request handling, such as authentication, logging, tracing, and metrics collection.

Jump to

Keyboard shortcuts

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