Documentation ¶
Index ¶
- Constants
- func DefaultBadRequestHandler(w http.ResponseWriter, _ *http.Request, err error)
- func DefaultCorsOption() cors.Options
- func DefaultMiddlewares() []func(next http.Handler) http.Handler
- func ReadJSON(r *http.Request, target interface{}) (int, error)
- func RequestLogger(logger *zap.Logger) func(http.Handler) http.Handler
- func RunHttpServer(ctx context.Context, createHandler func(router chi.Router) http.Handler, ...)
- func WriteError(w http.ResponseWriter, code int, message string)
- func WriteJSON(w http.ResponseWriter, code int, v interface{})
- func WriteMessage(w http.ResponseWriter, code string, message string)
- type Message
- type Option
Constants ¶
View Source
const ( DefaultGracefulShutdownSec = 5 DefaultPort = "8080" )
Variables ¶
This section is empty.
Functions ¶
func DefaultBadRequestHandler ¶
func DefaultBadRequestHandler(w http.ResponseWriter, _ *http.Request, err error)
func DefaultCorsOption ¶
func RunHttpServer ¶
func RunHttpServer(ctx context.Context, createHandler func(router chi.Router) http.Handler, options ...Option)
RunHttpServer starts a http server on given port. handler will be created when making the http.Server object. it will be a blocking call and will do gracefully shutdown the server when given context canceled. example:
gox.RunHttpServer(ctx, func(router chi.Router) http.Handler { return SetupRouter(router).Handler }, WithPort("9090"))
func WriteError ¶
func WriteError(w http.ResponseWriter, code int, message string)
func WriteJSON ¶
func WriteJSON(w http.ResponseWriter, code int, v interface{})
func WriteMessage ¶
func WriteMessage(w http.ResponseWriter, code string, message string)
Types ¶
type Option ¶
type Option func(*config) error
func WithAllowedHosts ¶
func WithCoreOptions ¶
func WithMiddlewares ¶
func WithZapLogger ¶
Click to show internal directories.
Click to hide internal directories.