easyroute

package module
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Jul 25, 2023 License: MIT Imports: 10 Imported by: 0

README

easyroute

GoDoc

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Logger

type Logger struct {
	LogI loggerFunc
	LogE loggerFunc
	LogD loggerFunc
}

type Request

type Request struct {
	UserUuid    string
	SessionInfo map[string]interface{}
	// contains filtered or unexported fields
}

func NewRequest

func NewRequest(w http.ResponseWriter, r *http.Request) Request

Create a new router.Request based on an http Request and ResponseWriter

func (*Request) Body

func (r *Request) Body(v interface{}) error

Gets request body for PUT/POST requests and reads into the provided pointer. If the request header indicates a json body, decode the body as JSON into provided pointer.

func (*Request) Json

func (r *Request) Json(status int, v interface{})

Json sends json representation of the interface v with the provided status code to the client.

func (*Request) Origin

func (r *Request) Origin() string

Origin returns the host where the request originated.

func (*Request) ParamValue

func (r *Request) ParamValue(key string) string

ParamValue returns the first value of the given url param.

func (*Request) Params

func (r *Request) Params() map[string][]string

Params returns Url Params for the request.

func (*Request) Path

func (r *Request) Path() string

Path returns Url Path for the request.

func (*Request) Redirect

func (r *Request) Redirect(forwardTo string)

Redirect forwards the request to the path provided by forwardTo

func (*Request) Request

func (r *Request) Request() *http.Request

Request returns an http.Request object for the request.

func (*Request) SendFile

func (r *Request) SendFile(file string)

SendFile forwards the file at the provided path to the client.

func (*Request) SessionValue

func (r *Request) SessionValue(key string) interface{}

SessionValue gets a key from the SessionInfo map.

func (*Request) SetSessionValue

func (r *Request) SetSessionValue(key string, value interface{})

SetSessionValue allows us to set a value in the SessionInfo map. Initializes map if not already done.

func (*Request) Vars

func (r *Request) Vars() map[string]string

Vars returns route variables for the request.

func (*Request) Writer

func (r *Request) Writer() http.ResponseWriter

Writer returns an http.ResponseWriter for the request. Can be used to output templated html and the like.

type Router

type Router struct {
	// Inherit a mux router
	*muxtrace.Router
	// contains filtered or unexported fields
}

func NewRouter

func NewRouter(beforeFn beforeHandlerFunc, logger Logger, ddServiceName string) Router

NewRouter creates a new easyroute Router object with the provided before handler and logger struct

func (*Router) ActivateProfiling

func (g *Router) ActivateProfiling()

func (*Router) Delete

func (g *Router) Delete(path string, handler handlerFunc)

func (*Router) EnableAirbrake

func (g *Router) EnableAirbrake(airbrakeId int64, airbrakeKey string)

func (*Router) Get

func (g *Router) Get(path string, handler handlerFunc)

func (*Router) Post

func (g *Router) Post(path string, handler handlerFunc)

func (*Router) Put

func (g *Router) Put(path string, handler handlerFunc)

func (*Router) SubRoute

func (g *Router) SubRoute(prefix string) Router

SubRoute creates a new easyroute Router off the base router with provided prefix. This preserves the same before handler.

func (*Router) SubRouteC

func (g *Router) SubRouteC(prefix string, beforeFn beforeHandlerFunc) Router

SubRouteC creates a new easyroute Router off the base router with provided prefix and an additional before handler. The routes in this router will now run through first the parent(base) router's before handler and then this router's before handler.

Jump to

Keyboard shortcuts

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