gsk

package
v0.5.13 Latest Latest
Warning

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

Go to latest
Published: Jul 9, 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
	GetPath() string

	// get data from request
	GetStatusCode() int
	GetParam(key string) string
	GetQueryParam(key string) string
	DecodeJSONBody(v interface{}) error

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

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

	// logger
	Logger() *logrus.Logger
	// contains filtered or unexported methods
}

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 Params added in v0.5.6

type Params interface {
	ByName(string) string
}

type RouteGroup added in v0.5.5

type RouteGroup interface {
	Use(middleware Middleware)

	Get(path string, handler HandlerFunc)
	Post(path string, handler HandlerFunc)
	Put(path string, handler HandlerFunc)
	Delete(path string, handler HandlerFunc)
	Patch(path string, handler HandlerFunc)
	Handle(method string, path string, handler HandlerFunc)

	RouteGroup(path string) RouteGroup
}

type Router added in v0.5.6

type Router interface {
	ServeFiles(string, http.FileSystem)
	ServeHTTP(http.ResponseWriter, *http.Request)
	HandlerFunc(method string, path string, handler http.HandlerFunc)
	ParamsFromContext(context.Context) Params

	Router() *httprouter.Router
}

type Server

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

	// HTTP methods
	Get(path string, handler HandlerFunc)
	Post(path string, handler HandlerFunc)
	Put(path string, handler HandlerFunc)
	Delete(path string, handler HandlerFunc)
	Patch(path string, handler HandlerFunc)
	// Handle arbitrary HTTP methods
	Handle(method string, path string, handler HandlerFunc)

	// Other Server methods
	Static(string, string)

	// Helpers
	Test(method string, path string, body io.Reader, params ...TestParams) (httptest.ResponseRecorder, error)
}

func New added in v0.5.3

func New(userconfig ...*ServerConfig) Server

New creates a new server instance Configurations can be passed as a parameter and It's optional If no configurations are passed, default values are used

type ServerConfig

type ServerConfig struct {
	Port   string
	Logger *logrus.Logger
	// Input
	BodySizeLimit int64
}

type TestParams added in v0.5.4

type TestParams struct {
	Cookies []*http.Cookie
	Headers map[string]string
}

Jump to

Keyboard shortcuts

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