Documentation ¶
Index ¶
- func AddCommonMiddleware(r chi.Router, isDev bool)
- func BadRequest(w http.ResponseWriter, r *http.Request, err error) (interface{}, error)
- func BadRequestWithMessage(w http.ResponseWriter, r *http.Request, msg string) (interface{}, error)
- func DBConnect(ctx context.Context, dbName string, dbURL string, dbDriver string, ...) (*sqlx.DB, error)
- func DBConnectJson(ctx context.Context, dbName string, dbURL string) (*mongo.Database, error)
- func Forbidden(w http.ResponseWriter, r *http.Request) (interface{}, error)
- func Health(w http.ResponseWriter, r *http.Request)
- func HtmlHandler(inner SimpleHandlerFunc) http.HandlerFunc
- func InternalServerError(w http.ResponseWriter, r *http.Request, err error) (interface{}, error)
- func NoContent(w http.ResponseWriter, r *http.Request) (interface{}, error)
- func NotAcceptableError(w http.ResponseWriter, r *http.Request, msg string) (interface{}, error)
- func NotFound(w http.ResponseWriter, r *http.Request) (interface{}, error)
- func NotFoundWithMessage(w http.ResponseWriter, r *http.Request, msg string) (interface{}, error)
- func ReadBody(r *http.Request, limit64 uint64) ([]byte, error)
- func SimpleHandler(inner SimpleHandlerFunc) http.HandlerFunc
- func TooManyRequests(w http.ResponseWriter, r *http.Request, retryAfter time.Duration) (interface{}, error)
- func Unauthorized(w http.ResponseWriter, r *http.Request, msg string) (interface{}, error)
- func Unmarshal(r io.ReadCloser, v interface{}) error
- type ErrResp
- type Server
- type ServerConfig
- type SimpleHandlerFunc
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AddCommonMiddleware ¶
func AddCommonMiddleware(r chi.Router, isDev bool)
func BadRequest ¶
func BadRequestWithMessage ¶
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 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 HtmlHandler ¶
func HtmlHandler(inner SimpleHandlerFunc) http.HandlerFunc
func InternalServerError ¶
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 ¶
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 NotFoundWithMessage ¶
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 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 ¶
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 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)
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)