rest

package
v0.1.10 Latest Latest
Warning

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

Go to latest
Published: May 22, 2023 License: MIT Imports: 14 Imported by: 0

Documentation

Index

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 DefaultCorsOption() cors.Options

func DefaultMiddlewares

func DefaultMiddlewares() []func(next http.Handler) http.Handler

func ReadJSON

func ReadJSON(r *http.Request, target interface{}) (int, error)

func RequestLogger

func RequestLogger(logger *zap.Logger) func(http.Handler) http.Handler

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 Message

type Message struct {
	Code    string `json:"code"`
	Message string `json:"message"`
}

Message defines a general model for server messages

type Option

type Option func(*config) error

func WithAllowedHosts

func WithAllowedHosts(allowedHosts []string) Option

func WithCoreOptions

func WithCoreOptions(corsOptions cors.Options) Option

func WithMiddlewares

func WithMiddlewares(middlewares []func(next http.Handler) http.Handler) Option

func WithPort

func WithPort(port string) Option

func WithZapLogger

func WithZapLogger(logger *zap.Logger) Option

Jump to

Keyboard shortcuts

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