web

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Jul 19, 2020 License: MIT Imports: 29 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ErrorHandler

func ErrorHandler(app *App) http.Handler

Types

type App

type App struct {
	http.Handler
	// contains filtered or unexported fields
}

func NewApp

func NewApp(opts ...Option) *App

func (*App) Any added in v0.0.2

func (app *App) Any(path string, routeHandler RouteHandler) *App

func (*App) Delete

func (app *App) Delete(path string, routeHandler RouteHandler) *App

func (*App) Get

func (app *App) Get(path string, routeHandler RouteHandler) *App

func (*App) HandleError

func (app *App) HandleError(res http.ResponseWriter, req *http.Request, err error)

HandleError recovers from panics gracefully and calls

func (*App) HandleMethod

func (app *App) HandleMethod(methods []string, path string, routeHandler RouteHandler) *App

func (*App) Patch

func (app *App) Patch(path string, routeHandler RouteHandler) *App

func (*App) Post

func (app *App) Post(path string, routeHandler RouteHandler) *App

func (*App) Put

func (app *App) Put(path string, routeHandler RouteHandler) *App

func (*App) Resource added in v0.0.2

func (app *App) Resource(path string, resource Resource) *App

func (*App) ServeHTTP

func (app *App) ServeHTTP(w http.ResponseWriter, r *http.Request)

func (*App) Start

func (app *App) Start()

type Context

type Context interface {
	context.Context
	Request() *http.Request
	Response() http.ResponseWriter
	Params() map[string]string
	Set(string, interface{})
	SetStatus(status int) Context
	Render(template string) error
	RenderJson(data interface{}) error
	Redirect(url string) error
	Logger() logger.Logger
	Broker() *broker.Broker
	Cookies() *Cookies
	Session() *Session
}

type Cookies

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

func (*Cookies) Delete

func (c *Cookies) Delete(name string)

Delete a cookie

func (*Cookies) Get

func (c *Cookies) Get(name string) (string, error)

Get a cookie from name

func (*Cookies) Set

func (c *Cookies) Set(name, value string, maxAge time.Duration)

Set a cookie on the response, which will expire after the given duration.

func (*Cookies) SetWithExpirationTime

func (c *Cookies) SetWithExpirationTime(name, value string, expires time.Time)

SetWithExpirationTime sets a cookie that will expire at a specific time.

func (*Cookies) SetWithPath

func (c *Cookies) SetWithPath(name, value, path string)

SetWithPath sets a cookie path on the server in which the cookie will be available on.

type DefaultContext

type DefaultContext struct {
	context.Context
	// contains filtered or unexported fields
}

func NewDefaultContext

func NewDefaultContext() *DefaultContext

func (*DefaultContext) Broker

func (d *DefaultContext) Broker() *broker.Broker

Broker is the broker instance from zepto

func (*DefaultContext) Cookies

func (d *DefaultContext) Cookies() *Cookies

Retrieve request session instance

func (*DefaultContext) Logger

func (d *DefaultContext) Logger() logger.Logger

Logger is the logger instance from zepto

func (*DefaultContext) Params

func (d *DefaultContext) Params() map[string]string

Retrieve a map of URL parameters

func (*DefaultContext) Redirect added in v0.0.2

func (d *DefaultContext) Redirect(url string) error

Redirect to url

func (*DefaultContext) Render

func (d *DefaultContext) Render(template string) error

Render a template

func (*DefaultContext) RenderJson

func (d *DefaultContext) RenderJson(data interface{}) error

Render a json

func (*DefaultContext) Request added in v0.0.2

func (d *DefaultContext) Request() *http.Request

Request is the http request

func (*DefaultContext) Response added in v0.0.2

func (d *DefaultContext) Response() http.ResponseWriter

Response is the http response writer

func (*DefaultContext) Session

func (d *DefaultContext) Session() *Session

Retrieve request session instance

func (*DefaultContext) Set

func (d *DefaultContext) Set(key string, value interface{})

Set a value to context. The values defined here are accessible in the template

func (*DefaultContext) SetStatus

func (d *DefaultContext) SetStatus(s int) Context

SetStatus set a http status code before render

func (*DefaultContext) Value

func (d *DefaultContext) Value(key interface{}) interface{}

Value returns a value from context

type Interceptor

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

func (*Interceptor) Header

func (i *Interceptor) Header() http.Header

func (*Interceptor) Write

func (i *Interceptor) Write(b []byte) (int, error)

func (*Interceptor) WriteHeader

func (i *Interceptor) WriteHeader(rc int)

type MuxHandler

type MuxHandler func(w http.ResponseWriter, r *http.Request)

type Option

type Option func(*Options)

func Broker

func Broker(b *broker.Broker) Option

Zepto Broker

func Env

func Env(e string) Option

Zepto Env

func Logger

func Logger(l logger.Logger) Option

Zepto Logger

func SessionName

func SessionName(name string) Option

SessionName - Set the session name

func SessionStore

func SessionStore(store sessions.Store) Option

SessionStore - Set the session name

func TemplateEngine

func TemplateEngine(tmplEngine renderer.Engine) Option

TemplateEngine - Change the template engine implementation

func WebpackEnabled

func WebpackEnabled(enabled bool) Option

type Options

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

type Resource added in v0.0.2

type Resource interface {
	List(Context) error
	Show(Context) error
	Create(Context) error
	Update(Context) error
	Destroy(Context) error
}

type RouteHandler

type RouteHandler func(ctx Context) error

type Session

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

func (*Session) Clear

func (s *Session) Clear()

func (*Session) Delete

func (s *Session) Delete(key interface{})

func (*Session) Get

func (s *Session) Get(key interface{}) interface{}

func (*Session) Save

func (s *Session) Save() error

func (*Session) Set

func (s *Session) Set(key, value interface{})

type TestHandlerRequestOptions added in v0.0.4

type TestHandlerRequestOptions struct {
	Handler        RouteHandler
	Method         string
	Target         string
	Body           io.Reader
	InitialSession map[string]string
}

type TestHandlerRequestResult added in v0.0.4

type TestHandlerRequestResult struct {
	Ctx    *DefaultContext
	Status int
	Header http.Header
	Body   string
	// contains filtered or unexported fields
}

func (*TestHandlerRequestResult) AssertBodyContains added in v0.0.4

func (tr *TestHandlerRequestResult) AssertBodyContains(str string)

func (*TestHandlerRequestResult) AssertBodyEquals added in v0.0.4

func (tr *TestHandlerRequestResult) AssertBodyEquals(str string)

func (*TestHandlerRequestResult) AssertHeaderValue added in v0.0.4

func (tr *TestHandlerRequestResult) AssertHeaderValue(key string, value string)

func (*TestHandlerRequestResult) AssertSessionValue added in v0.0.4

func (tr *TestHandlerRequestResult) AssertSessionValue(key string, value string)

func (*TestHandlerRequestResult) AssertStatusCode added in v0.0.4

func (tr *TestHandlerRequestResult) AssertStatusCode(status int)

type ZeptoTest added in v0.0.4

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

func NewZeptoTest added in v0.0.4

func NewZeptoTest(t *testing.T, app *App) *ZeptoTest

func (*ZeptoTest) TestHandlerRequest added in v0.0.4

func (zt *ZeptoTest) TestHandlerRequest(opts TestHandlerRequestOptions) (TestHandlerRequestResult, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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