chassis

package
v0.0.0-...-f16744b Latest Latest
Warning

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

Go to latest
Published: Jun 9, 2024 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddCommonMiddleware

func AddCommonMiddleware(r chi.Router, isDev bool)

func BadRequest

func BadRequest(w http.ResponseWriter, r *http.Request, err error) (interface{}, error)

func BadRequestWithMessage

func BadRequestWithMessage(w http.ResponseWriter, r *http.Request, msg string) (interface{}, error)

func DBConnect

func DBConnect(ctx context.Context, dbName string, dbURL string, dbDriver string,
	asset assetFunc, assetDir assetDirFunc) (*sqlx.DB, error)

DBConnect creates a new database connection.

func DBConnectJson

func DBConnectJson(ctx context.Context, dbName string, dbURL string) (*mongo.Database, error)

func Forbidden

func Forbidden(w http.ResponseWriter, r *http.Request) (interface{}, error)

Forbidden sets up an HTTP 403 Forbidden and returns the (nil, nil) pair used by SimpleHandler to signal that the response has been dealt with.

func Health

func Health(w http.ResponseWriter, r *http.Request)

func HtmlHandler

func HtmlHandler(inner SimpleHandlerFunc) http.HandlerFunc

func InternalServerError

func InternalServerError(w http.ResponseWriter, r *http.Request, err error) (interface{}, error)

BadRequest sets up an HTTP 400 Bad Request with a given error message and returns the (nil, nil) pair used by SimpleHandler to signal that the response has been dealt with.

func NoContent

func NoContent(w http.ResponseWriter, r *http.Request) (interface{}, error)

NoContent sets up an HTTP 204 No Content and returns the (nil, nil) pair used by SimpleHandler to signal that the response has been dealt with.

func NotAcceptableError

func NotAcceptableError(w http.ResponseWriter, r *http.Request, msg string) (interface{}, error)

NotAcceptableError This response is sent when the web server, after performing server-driven content negotiation, doesn't find any content that conforms to the criteria given by the user agent.

func NotFound

func NotFound(w http.ResponseWriter, r *http.Request) (interface{}, error)

func NotFoundWithMessage

func NotFoundWithMessage(w http.ResponseWriter, r *http.Request, msg string) (interface{}, error)

NotFoundWithMessage sets up an HTTP 404 Not Found with a given error message and returns the (nil, nil) pair used by SimpleHandler to signal that the response has been dealt with.

func ReadBody

func ReadBody(r *http.Request, limit64 uint64) ([]byte, error)

ReadBody reads a request body, limiting to a maximum size.

func SimpleHandler

func SimpleHandler(inner SimpleHandlerFunc) http.HandlerFunc

func TooManyRequests

func TooManyRequests(w http.ResponseWriter, r *http.Request, retryAfter time.Duration) (interface{}, error)

TooManyRequests sets up an HTTP 429 Too Many Requests and returns the (nil, nil) pair used by SimpleHandler to signal that the response has been dealt with.

func Unauthorized

func Unauthorized(w http.ResponseWriter, r *http.Request, msg string) (interface{}, error)

Unauthorized sets up an HTTP 401 StatusUnauthorized and returns the (nil, nil) pair used by SimpleHandler to signal that the response has been dealt with.

func Unmarshal

func Unmarshal(r io.ReadCloser, v interface{}) error

Unmarshal does JSON unmarshalling disallowing unknown fields and limiting the permitted body size.

Types

type ErrResp

type ErrResp struct {
	Message string `json:"message"`
}

type Server

type Server struct {
	AppName string
	Ctx     context.Context
	Srv     *http.Server
	// contains filtered or unexported fields
}

func (*Server) AddAtExit

func (s *Server) AddAtExit(fn func())

AddAtExit adds an exit handler function.

func (*Server) Init

func (s *Server) Init(cfg *ServerConfig, r chi.Router)

func (*Server) Serve

func (s *Server) Serve()

type ServerConfig

type ServerConfig struct {
	AppName        string
	Project        string `env:"PROJECT_ID,default=dev"`
	Port           int    `env:"PORT,default=9002"`
	Credentials    string `env:"CREDENTIALS_PATH"`
	SentryDSN      string `env:"SENTRY_DSN"`
	SentryTracing  bool   `env:"SENTRY_TRACING,default=false"`
	Environment    string `env:"ENVIRONMENT,default=dev"`
	MaxConnections int    `env:"MAX_CONNECTIONS,default=50"`
	Release        string
}

type SimpleHandlerFunc

type SimpleHandlerFunc func(w http.ResponseWriter, r *http.Request) (interface{}, error)

Jump to

Keyboard shortcuts

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