route

package
v8.1.0+incompatible Latest Latest
Warning

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

Go to latest
Published: Apr 2, 2019 License: MIT Imports: 8 Imported by: 1

Documentation

Index

Constants

View Source
const (
	SessionHeaderKey = "X-Shield-Session"
	SessionCookieKey = "shield7"
)

Variables

This section is empty.

Functions

func SessionID

func SessionID(req *http.Request) string

Types

type Error

type Error struct {
	Diagnostic string   `json:"diagnostic,omitempty"`
	Message    string   `json:"error,omitempty"`
	Missing    []string `json:"missing,omitempty"`
	// contains filtered or unexported fields
}

func Bad

func Bad(e error, msg string, args ...interface{}) Error

func Errorf

func Errorf(code int, e error, msg string, args ...interface{}) Error

func Forbidden

func Forbidden(e error, msg string, args ...interface{}) Error

func NotFound

func NotFound(e error, msg string, args ...interface{}) Error

func Oops

func Oops(e error, msg string, args ...interface{}) Error

func Unauthorized

func Unauthorized(e error, msg string, args ...interface{}) Error

func (Error) Error

func (e Error) Error() string

func (*Error) ProvideDiagnostic

func (e *Error) ProvideDiagnostic()

type Handler

type Handler func(r *Request)

type Request

type Request struct {
	Req  *http.Request
	Args []string
	// contains filtered or unexported fields
}

func NewRequest

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

NewRequest initializes and returns a new request object. Setting debug to true will cause errors to be logged.

func (*Request) ClearCookie

func (r *Request) ClearCookie(name, path string)

func (*Request) ClearSession

func (r *Request) ClearSession()

func (*Request) Done

func (r *Request) Done() bool

func (*Request) Fail

func (r *Request) Fail(e Error)

func (*Request) Missing

func (r *Request) Missing(params ...string) bool

func (*Request) OK

func (r *Request) OK(resp interface{})

func (*Request) Param

func (r *Request) Param(name, def string) string

func (*Request) ParamDate

func (r *Request) ParamDate(name string) *time.Time

func (*Request) ParamDuration

func (r *Request) ParamDuration(name string) *time.Duration

ParamDuration parses a duration string, example: "1m30s" that will be 1 minute and 30 seconds

func (*Request) ParamIs

func (r *Request) ParamIs(name, want string) bool

func (*Request) Payload

func (r *Request) Payload(v interface{}) bool

Payload unmarshals the JSON body of this request into the given interface. Returns true if successful and false otherwise.

func (*Request) Redirect

func (r *Request) Redirect(code int, to string)

func (*Request) RemoteIP

func (r *Request) RemoteIP() string

func (*Request) Respond

func (r *Request) Respond(code int, typ, msg string, args ...interface{})

func (*Request) SessionID

func (r *Request) SessionID() string

func (*Request) SetCookie

func (r *Request) SetCookie(name, val, path string)

func (*Request) SetSession

func (r *Request) SetSession(id string)

func (*Request) String

func (r *Request) String() string

func (*Request) Success

func (r *Request) Success(msg string, args ...interface{})

func (*Request) Upgrade

func (r *Request) Upgrade() *WebSocket

func (*Request) UserAgent

func (r *Request) UserAgent() string

type Router

type Router struct {
	Debug bool
	// contains filtered or unexported fields
}

func (*Router) Dispatch

func (r *Router) Dispatch(match string, handler Handler)

func (*Router) ServeHTTP

func (r *Router) ServeHTTP(w http.ResponseWriter, req *http.Request)

type WebSocket

type WebSocket struct {
	// contains filtered or unexported fields
}

func (*WebSocket) Discard

func (ws *WebSocket) Discard()

func (*WebSocket) Write

func (ws *WebSocket) Write(b []byte) error

Jump to

Keyboard shortcuts

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