Documentation
¶
Index ¶
- Variables
- func H(h Handler) http.Handler
- func SafeRedirectPath(p string) string
- func Wrap(h Handler) http.Handler
- type App
- func (app *App) BeforeRender(m middleware.Middleware) *App
- func (app *App) Config(config Config) *App
- func (app *App) Global(key interface{}) interface{}
- func (app *App) Globals(globals Globals) *App
- func (app *App) GracefulShutdown() *GracefulShutdown
- func (app *App) Handler(h http.Handler) *App
- func (app *App) ListenAndServe(addr string) error
- func (app *App) ListenAndServeTLS(addr, certFile, keyFile string) error
- func (app *App) ParseConfig(data []byte) *App
- func (app *App) ParseConfigFile(filename string) *App
- func (app *App) Route(name string, params ...interface{}) string
- func (app *App) Routes(routes Routes) *App
- func (app *App) ServeHTTP(w http.ResponseWriter, r *http.Request)
- func (app *App) Template() *Template
- func (app *App) TemplateFuncs(funcs ...template.FuncMap) *App
- type Config
- type Context
- type ErrRouteNotFound
- type ErrTemplateDuplicate
- type ErrTemplateNotFound
- type Globals
- type GracefulShutdown
- func (gs *GracefulShutdown) Before(fn func()) *GracefulShutdown
- func (gs *GracefulShutdown) ListenAndServe(addr string) error
- func (gs *GracefulShutdown) ListenAndServeTLS(addr, certFile, keyFile string) error
- func (gs *GracefulShutdown) Notify(fn func()) *GracefulShutdown
- func (gs *GracefulShutdown) Timeout(d time.Duration) *GracefulShutdown
- func (gs *GracefulShutdown) Wait(d time.Duration) *GracefulShutdown
- type Handler
- type Param
- type Result
- type Routes
- type Template
- func (tp *Template) Component(filename ...string) *Template
- func (tp *Template) Delims(left, right string) *Template
- func (tp *Template) Dir(path string) *Template
- func (tp *Template) Funcs(funcs ...template.FuncMap) *Template
- func (tp *Template) Minify() *Template
- func (tp *Template) Parse(name string, filenames ...string) *Template
- func (tp *Template) Root(name string) *Template
Constants ¶
This section is empty.
Variables ¶
var (
ErrAppNotFound = errors.New("hime: app not found")
)
Errors
Functions ¶
func SafeRedirectPath ¶ added in v0.0.17
SafeRedirectPath filters domain out from path
Types ¶
type App ¶
type App struct { // TLSConfig overrides http.Server TLSConfig TLSConfig *tls.Config // ReadTimeout overrides http.Server ReadTimeout ReadTimeout time.Duration // ReadHeaderTimeout overrides http.Server ReadHeaderTimeout ReadHeaderTimeout time.Duration // WriteTimeout overrides http.Server WriteTimeout WriteTimeout time.Duration // IdleTimeout overrides http.Server IdleTimeout IdleTimeout time.Duration // MaxHeaderBytes overrides http.Server MaxHeaderBytes MaxHeaderBytes int // TLSNextProto overrides http.Server TLSNextProto TLSNextProto map[string]func(*http.Server, *tls.Conn, http.Handler) // ConnState overrides http.Server ConnState ConnState func(net.Conn, http.ConnState) // ErrorLog overrides http.Server ErrorLog ErrorLog *log.Logger // contains filtered or unexported fields }
App is the hime app
func (*App) BeforeRender ¶
func (app *App) BeforeRender(m middleware.Middleware) *App
BeforeRender runs given middleware for before render, ex. View, JSON, String, Bytes, CopyForm, etc
func (*App) Config ¶ added in v0.4.0
Config merges config into app's config
Example:
globals:
data1: test
routes:
index: / about: /about
templates:
- dir: view root: layout delims: ["{{", "}}"] minify: true components:
- comp/comp1.tmpl
- comp/comp2.tmpl list: main.tmpl:
- main.tmpl
- _layout.tmpl about.tmpl: [about.tmpl, _layout.tmpl]
server:
readTimeout: 10s readHeaderTimeout: 5s writeTimeout: 5s idleTimeout: 30s gracefulShutdown: timeout: 1m wait: 5s
func (*App) Global ¶ added in v0.0.11
func (app *App) Global(key interface{}) interface{}
Global gets value from global storage
func (*App) GracefulShutdown ¶
func (app *App) GracefulShutdown() *GracefulShutdown
GracefulShutdown returns graceful shutdown server
func (*App) ListenAndServe ¶
ListenAndServe starts web server
func (*App) ListenAndServeTLS ¶ added in v0.2.0
ListenAndServeTLS starts web server in tls mode
func (*App) ParseConfig ¶ added in v0.4.0
ParseConfig parses config data
func (*App) ParseConfigFile ¶ added in v0.4.0
ParseConfigFile parses config from file
type Config ¶ added in v0.3.0
type Config struct { Globals map[interface{}]interface{} `yaml:"globals" json:"globals"` Routes map[string]string `yaml:"routes" json:"routes"` Templates []struct { Dir string `yaml:"dir" json:"dir"` Root string `yaml:"root" json:"root"` Minify bool `yaml:"minify" json:"minify"` Components []string `yaml:"components" json:"components"` List map[string][]string `yaml:"list" json:"list"` Delims []string `yaml:"delims" json:"delims"` } `yaml:"templates" json:"templates"` Server struct { ReadTimeout string `yaml:"readTimeout" json:"readTimeout"` ReadHeaderTimeout string `yaml:"readHeaderTimeout" json:"readHeaderTimeout"` WriteTimeout string `yaml:"writeTimeout" json:"writeTimeout"` IdleTimeout string `yaml:"idleTimeout" json:"idleTimeout"` GracefulShutdown *struct { Timeout string `yaml:"timeout" json:"timeout"` Wait string `yaml:"wait" json:"wait"` } `yaml:"gracefulShutdown" json:"gracefulShutdown"` } `yaml:"server" json:"server"` }
Config is app's config
type Context ¶
type Context interface { context.Context WithContext(ctx context.Context) WithRequest(r *http.Request) WithResponseWriter(w http.ResponseWriter) WithValue(key interface{}, val interface{}) // Route gets route path from given name Route(name string, params ...interface{}) string // Global gets value from global storage Global(key interface{}) interface{} // Request returns http.Request from context Request() *http.Request // ResponseWrite returns http.ResponseWriter from context ResponseWriter() http.ResponseWriter // Status sets response status Status(code int) Context // Request functions ParseForm() error ParseMultipartForm(maxMemory int64) error Form() url.Values PostForm() url.Values // FromValue functions FormValue(key string) string FormValueTrimSpace(key string) string FormValueTrimSpaceComma(key string) string FormValueInt(key string) int FormValueInt64(key string) int64 FormValueFloat32(key string) float32 FormValueFloat64(key string) float64 PostFormValue(key string) string PostFormValueTrimSpace(key string) string PostFormValueTrimSpaceComma(key string) string PostFormValueInt(key string) int PostFormValueInt64(key string) int64 PostFormValueFloat32(key string) float32 PostFormValueFloat64(key string) float64 FormFile(key string) (multipart.File, *multipart.FileHeader, error) // FormFileNotEmpty calls r.FormFile but return http.ErrMissingFile if file empty FormFileNotEmpty(key string) (multipart.File, *multipart.FileHeader, error) MultipartForm() *multipart.Form MultipartReader() (*multipart.Reader, error) Method() string // Query returns ctx.Request().URL.Query() Query() url.Values Param(name string, value interface{}) *Param // Nothing does nothing Nothing() Result // Redirect redirects to given url Redirect(url string, params ...interface{}) Result // SafeRedirect extracts only path from url then redirect SafeRedirect(url string, params ...interface{}) Result // RedirectTo redirects to named route RedirectTo(name string, params ...interface{}) Result // RedirectToGet redirects to GET method with See Other status code on the current path RedirectToGet() Result // RedirectBack redirects back to previous URL RedirectBack(fallback string) Result // RedirectBackToGet redirects back to GET method with See Other status code to previous URL // or fallback to same URL like RedirectToGet RedirectBackToGet() Result // SafeRedirectBack redirects back to previous URL using SafeRedirect SafeRedirectBack(fallback string) Result // Error wraps http.Error Error(error string) Result // NotFound wraps http.NotFound NotFound() Result // NoContent renders empty body with http.StatusNoContent NoContent() Result // View renders template View(name string, data interface{}) Result // JSON renders json JSON(data interface{}) Result // String renders string with format String(format string, a ...interface{}) Result // StatusText renders String when http.StatusText StatusText() Result // CopyFrom copies source into response writer CopyFrom(src io.Reader) Result // Bytes renders bytes Bytes(b []byte) Result // File renders file File(name string) Result }
Context is the hime context
func NewContext ¶ added in v0.0.15
func NewContext(w http.ResponseWriter, r *http.Request) Context
NewContext creates new hime's context
type ErrRouteNotFound ¶ added in v0.0.15
type ErrRouteNotFound struct {
Route string
}
ErrRouteNotFound is the error for route not found
func (*ErrRouteNotFound) Error ¶ added in v0.0.15
func (err *ErrRouteNotFound) Error() string
type ErrTemplateDuplicate ¶ added in v0.0.15
type ErrTemplateDuplicate struct {
Name string
}
ErrTemplateDuplicate is the error for template duplicate
func (*ErrTemplateDuplicate) Error ¶ added in v0.0.15
func (err *ErrTemplateDuplicate) Error() string
type ErrTemplateNotFound ¶ added in v0.0.15
type ErrTemplateNotFound struct {
Name string
}
ErrTemplateNotFound is the error for template not found
func (*ErrTemplateNotFound) Error ¶ added in v0.0.15
func (err *ErrTemplateNotFound) Error() string
type Globals ¶ added in v0.0.11
type Globals map[interface{}]interface{}
Globals is the global const map
type GracefulShutdown ¶ added in v0.2.0
type GracefulShutdown struct { App *App // contains filtered or unexported fields }
GracefulShutdown is the app in graceful shutdown mode
func (*GracefulShutdown) Before ¶ added in v0.2.0
func (gs *GracefulShutdown) Before(fn func()) *GracefulShutdown
Before runs fn before start waiting to SIGTERM
func (*GracefulShutdown) ListenAndServe ¶ added in v0.2.0
func (gs *GracefulShutdown) ListenAndServe(addr string) error
ListenAndServe starts web server in graceful shutdown mode
func (*GracefulShutdown) ListenAndServeTLS ¶ added in v0.2.0
func (gs *GracefulShutdown) ListenAndServeTLS(addr, certFile, keyFile string) error
ListenAndServeTLS starts web server in graceful shutdown and tls mode
func (*GracefulShutdown) Notify ¶ added in v0.2.0
func (gs *GracefulShutdown) Notify(fn func()) *GracefulShutdown
Notify calls fn when receive terminate signal from os
func (*GracefulShutdown) Timeout ¶ added in v0.2.0
func (gs *GracefulShutdown) Timeout(d time.Duration) *GracefulShutdown
Timeout sets shutdown timeout for graceful shutdown, set to 0 to disable timeout
default is 0
func (*GracefulShutdown) Wait ¶ added in v0.2.0
func (gs *GracefulShutdown) Wait(d time.Duration) *GracefulShutdown
Wait sets wait time before shutdown
type Param ¶ added in v0.0.16
type Param struct { Name string Value interface{} }
Param is the query param when redirect
type Template ¶ added in v0.3.0
type Template struct {
// contains filtered or unexported fields
}
Template is template loader