web

package
v0.0.0-...-9e9b37c Latest Latest
Warning

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

Go to latest
Published: Mar 17, 2024 License: MIT Imports: 34 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var SingleServerSite = false

SingleServerSite can be set to true if you know you're never going to deploy to a cluster of multiple web servers (like during development). This will make startup faster as assets can be procssed ad-hoc instead of all up front.

Functions

func AssetCssPreprocessor

func AssetCssPreprocessor(assets *Assets, path string, content []byte) ([]byte, error)

func AssetSourceMapPreprocessor

func AssetSourceMapPreprocessor(assets *Assets, path string, content []byte) ([]byte, error)

func RemoveAssetsFilter

func RemoveAssetsFilter(events []logkit.Event) []logkit.Event

Types

type Action

type Action func(context *Context)

type Assets

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

func NewAssets

func NewAssets(baseURL string) *Assets

func (*Assets) AddDirectory

func (f *Assets) AddDirectory(directory string, virtualPath string, ignoreDirs ...string) error

func (*Assets) AddFile

func (f *Assets) AddFile(file string, virtualPath string)

func (*Assets) AddMinifyPreprocessors

func (f *Assets) AddMinifyPreprocessors(minifyCSS, minifyJavascript, minifySVG, minifyHTML, minifyTmpl bool)

func (*Assets) AddPreprocessor

func (f *Assets) AddPreprocessor(extension string, processor Preprocessor)

func (*Assets) ClearPreprocessors

func (f *Assets) ClearPreprocessors(extension string)

func (*Assets) Get

func (f *Assets) Get(virtualPath string) (*File, error)

func (*Assets) GetTemplate

func (f *Assets) GetTemplate(templatePathArr []string) (*template.Template, error)

func (*Assets) GetUrl

func (f *Assets) GetUrl(virtualPath string) (string, error)

func (*Assets) RenderNamedTemplate

func (f *Assets) RenderNamedTemplate(templatePathArr []string, name string, w http.ResponseWriter, data interface{}) error

func (*Assets) RenderNamedTemplateString

func (f *Assets) RenderNamedTemplateString(templatePathArr []string, name string, data interface{}) (string, error)

func (*Assets) RenderTemplate

func (f *Assets) RenderTemplate(templatePathArr []string, w http.ResponseWriter, data interface{}) error

func (*Assets) RenderTemplateString

func (f *Assets) RenderTemplateString(templatePathArr []string, data interface{}) (string, error)

func (*Assets) Serve

func (f *Assets) Serve(url string, w http.ResponseWriter, r *http.Request)

func (*Assets) SetTemplateFunc

func (f *Assets) SetTemplateFunc(name string, templateFunc interface{})

type Context

type Context struct {
	*logkit.Context
	Site  *Site
	Route *Route

	Request    *http.Request
	MasterFile string

	Form     formInputReader
	PostForm formInputReader
	Cookies  cookieInputReader
	// contains filtered or unexported fields
}

func CreateContext

func CreateContext(ctx *logkit.Context, site *Site, route *Route, w http.ResponseWriter, req *http.Request, params httprouter.Params) *Context

func (*Context) CheckErr

func (c *Context) CheckErr(err error)

func (*Context) ClientIP

func (c *Context) ClientIP() net.IP

ClientIP trys to get the ip of the client by inspecting common headers and the ip of remote endpoint of the tcp connection

func (*Context) Cookie

func (c *Context) Cookie(name string) (*http.Cookie, error)

func (*Context) Flush

func (c *Context) Flush()

func (*Context) GetData

func (c *Context) GetData(key string) (interface{}, bool)

func (*Context) Header

func (c *Context) Header() http.Header

func (*Context) Hijack

func (c *Context) Hijack() (net.Conn, *bufio.ReadWriter, error)

func (*Context) JSON

func (c *Context) JSON(data interface{}) error

func (*Context) NotFound

func (c *Context) NotFound()

func (*Context) Redirect

func (c *Context) Redirect(urlStr string)

func (*Context) RedirectPermanent

func (c *Context) RedirectPermanent(urlStr string)

func (*Context) RemoveData

func (c *Context) RemoveData(key string)

func (*Context) Render

func (c *Context) Render(data interface{})

func (*Context) RenderTemplate

func (c *Context) RenderTemplate(templatePath string, data interface{}) error

func (*Context) RouteArg

func (c *Context) RouteArg(name string) string

func (*Context) RouteArgInt64

func (c *Context) RouteArgInt64(name string) (int64, error)

func (*Context) ServerError

func (c *Context) ServerError(err string, code int)

func (*Context) SetData

func (c *Context) SetData(key string, value interface{})

func (*Context) Write

func (c *Context) Write(data []byte) (int, error)

func (*Context) WriteHeader

func (c *Context) WriteHeader(statusCode int)

func (*Context) WriteString

func (c *Context) WriteString(value string) (int, error)

type File

type File struct {
	Content        []byte
	ContentGZipped []byte
	Hash           []byte
	HashString     string
	ContentType    string
	// contains filtered or unexported fields
}

type InputReader

type InputReader interface {
	String(name string, fallback string) string
	Bool(name string, fallback bool) bool
	Int(name string, min, max, fallback int) int
}

InputReader makes it easy to read input

type Middleware

type Middleware func(next Action) Action

type Preprocessor

type Preprocessor func(assets *Assets, path string, content []byte) (result []byte, err error)

type Route

type Route struct {
	Path             string
	Action           Action
	Handler          http.Handler
	HttpRouterHandle httprouter.Handle
	Template         string
	MasterTemplate   string
	NoGZip           bool
}

type Site

type Site struct {
	NoRequestLogkitOperation bool
	Development              bool
	DefaultMasterFile        string
	TemplateDataWrapper      TemplateDataWrapper
	Assets                   *Assets
	NotFound                 Route
	ServerError              Route
	PanicHandler             func(c *Context, err interface{}) bool

	RedirectTrailingSlash bool

	BufferedEventsFilter logkit.BufferedEventsFilter
	// contains filtered or unexported fields
}

func NewSite

func NewSite(development bool, assetPath string) *Site

func (*Site) AddMiddleware

func (s *Site) AddMiddleware(middleware Middleware)

func (*Site) AddRoute

func (s *Site) AddRoute(route Route)

func (*Site) ListenAndServe

func (s *Site) ListenAndServe(addr string) error

func (*Site) ServeHTTP

func (s *Site) ServeHTTP(w http.ResponseWriter, req *http.Request)

type TemplateDataWrapper

type TemplateDataWrapper func(c *Context, data interface{}) (interface{}, error)

type TestSession

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

TestSession represents a test session for a single user

func NewTestSession

func NewTestSession(t *testing.T, site *Site) *TestSession

func (*TestSession) Action

func (s *TestSession) Action(action Action, req *http.Request) *TestSessionResponse

func (*TestSession) Get

func (s *TestSession) Get(url string) *TestSessionResponse

func (*TestSession) Post

func (s *TestSession) Post(url string, bodyType string, body io.Reader) *TestSessionResponse

func (*TestSession) PostAction

func (s *TestSession) PostAction(url string, data url.Values, action Action) *TestSessionResponse

func (*TestSession) PostForm

func (s *TestSession) PostForm(url string, data url.Values) *TestSessionResponse

func (*TestSession) Request

func (s *TestSession) Request(req *http.Request) *TestSessionResponse

type TestSessionResponse

type TestSessionResponse struct {
	Code      int           // the HTTP response code from WriteHeader
	HeaderMap http.Header   // the HTTP response headers
	Body      *bytes.Buffer // if non-nil, the bytes.Buffer to append written data to
	// contains filtered or unexported fields
}

func (*TestSessionResponse) AssertBodyEquals

func (r *TestSessionResponse) AssertBodyEquals(comparision string) *TestSessionResponse

Jump to

Keyboard shortcuts

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