gsk

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Jul 3, 2023 License: MIT Imports: 11 Imported by: 23

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidJSON    = errors.New("invalid_json")
	ErrInternalServer = errors.New("internal_server_error")
	ErrBodyTooLarge   = errors.New("request_body_too_large")
)

Functions

func NormalizePort

func NormalizePort(val string) string

Types

type Context

type Context interface {
	// http objects
	GetRequest() *http.Request
	GetWriter() http.ResponseWriter

	// get data from request
	GetParam(key string) string
	GetQueryParam(key string) string
	GetAllowedOrigins() []string
	DecodeJSONBody(v interface{}) error

	// set data for response
	Status(status int) Context
	SetHeader(string, string)
	RawResponse(raw []byte)
	JSONResponse(data interface{})

	// cookies
	SetCookie(cookie *http.Cookie)
	GetCookie(name string) (*http.Cookie, error)

	// logger
	Logger() *logrus.Logger
}

type HandlerFunc

type HandlerFunc func(Context)

type Map

type Map map[string]interface{}

type Middleware

type Middleware func(HandlerFunc) HandlerFunc

This implementation of middleware will enable middleware chaining

type Server

type Server interface {
	// Start and Stop
	Start()
	Shutdown() error
	// Middleware
	Use(Middleware)

	// HTTP methods
	Get(string, HandlerFunc)
	Post(string, HandlerFunc)
	Put(string, HandlerFunc)
	Delete(string, HandlerFunc)
	Patch(string, HandlerFunc)

	// GetRouter
	GetRouter() *httprouter.Router
}

func NewServer

func NewServer(config *ServerConfig) Server

NewServer creates a new server instance

type ServerConfig

type ServerConfig struct {
	Port           string
	RequestLogging bool
	AllowedOrigins []string
	Logger         *logrus.Logger
}

Jump to

Keyboard shortcuts

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