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) Address(addr string) *App
- func (app *App) BeforeRender(m middleware.Middleware) *App
- func (app *App) Config(config AppConfig) *App
- func (app *App) Global(key interface{}) interface{}
- func (app *App) Globals(globals Globals) *App
- func (app *App) GracefulShutdown() *GracefulShutdownApp
- func (app *App) Handler(h http.Handler) *App
- func (app *App) ListenAndServe() error
- func (app *App) ListenAndServeTLS(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) TemplateFunc(name string, f interface{}) *App
- func (app *App) TemplateFuncs(funcs ...template.FuncMap) *App
- type AppConfig
- type Apps
- type Context
- type ErrRouteNotFound
- type ErrTemplateDuplicate
- type ErrTemplateNotFound
- type Globals
- type GracefulShutdownApp
- func (gs *GracefulShutdownApp) Address(addr string) *GracefulShutdownApp
- func (gs *GracefulShutdownApp) ListenAndServe() error
- func (gs *GracefulShutdownApp) ListenAndServeTLS(certFile, keyFile string) error
- func (gs *GracefulShutdownApp) Notify(fn func()) *GracefulShutdownApp
- func (gs *GracefulShutdownApp) OnShutdown(fn func()) *GracefulShutdownApp
- func (gs *GracefulShutdownApp) Timeout(d time.Duration) *GracefulShutdownApp
- func (gs *GracefulShutdownApp) Wait(d time.Duration) *GracefulShutdownApp
- type GracefulShutdownApps
- type Handler
- type Param
- type Result
- type Routes
- type Template
- func (tp *Template) Component(filename ...string) *Template
- func (tp *Template) Config(cfg TemplateConfig) *Template
- func (tp *Template) Delims(left, right string) *Template
- func (tp *Template) Dir(path string) *Template
- func (tp *Template) Func(name string, f interface{}) *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) ParseConfig(data []byte) *Template
- func (tp *Template) ParseConfigFile(filename string) *Template
- func (tp *Template) Root(name string) *Template
- type TemplateConfig
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 { // Addr is server address Addr string // 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() *GracefulShutdownApp
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
func (*App) ServeHTTP ¶ added in v0.2.0
func (app *App) ServeHTTP(w http.ResponseWriter, r *http.Request)
func (*App) TemplateFunc ¶ added in v0.4.2
TemplateFunc registers an app's level template func
type AppConfig ¶ added in v0.4.2
type AppConfig struct { Globals map[interface{}]interface{} `yaml:"globals" json:"globals"` Routes map[string]string `yaml:"routes" json:"routes"` Templates []TemplateConfig `yaml:"templates" json:"templates"` Server struct { Addr string `yaml:"addr" json:"addr"` 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"` }
AppConfig is hime app's config
type Apps ¶ added in v0.5.0
type Apps struct {
// contains filtered or unexported fields
}
Apps is the collection of App to start together
func (*Apps) GracefulShutdown ¶ added in v0.5.0
func (apps *Apps) GracefulShutdown() *GracefulShutdownApps
GracefulShutdown changes apps to graceful shutdown mode
func (*Apps) ListenAndServe ¶ added in v0.5.0
ListenAndServe starts web servers
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 GracefulShutdownApp ¶ added in v0.0.19
type GracefulShutdownApp struct { App *App // contains filtered or unexported fields }
GracefulShutdownApp is the app in graceful shutdown mode
func (*GracefulShutdownApp) Address ¶ added in v0.5.0
func (gs *GracefulShutdownApp) Address(addr string) *GracefulShutdownApp
Address sets server address
func (*GracefulShutdownApp) ListenAndServe ¶ added in v0.0.19
func (gs *GracefulShutdownApp) ListenAndServe() error
ListenAndServe starts web server in graceful shutdown mode
func (*GracefulShutdownApp) ListenAndServeTLS ¶ added in v0.5.0
func (gs *GracefulShutdownApp) ListenAndServeTLS(certFile, keyFile string) error
ListenAndServeTLS starts web server in graceful shutdown and tls mode
func (*GracefulShutdownApp) Notify ¶ added in v0.0.20
func (gs *GracefulShutdownApp) Notify(fn func()) *GracefulShutdownApp
Notify calls fn when receive terminate signal from os
func (*GracefulShutdownApp) OnShutdown ¶ added in v0.5.0
func (gs *GracefulShutdownApp) OnShutdown(fn func()) *GracefulShutdownApp
OnShutdown calls server.RegisterOnShutdown(fn)
func (*GracefulShutdownApp) Timeout ¶ added in v0.0.19
func (gs *GracefulShutdownApp) Timeout(d time.Duration) *GracefulShutdownApp
Timeout sets shutdown timeout for graceful shutdown, set to 0 to disable timeout
default is 0
func (*GracefulShutdownApp) Wait ¶ added in v0.0.19
func (gs *GracefulShutdownApp) Wait(d time.Duration) *GracefulShutdownApp
Wait sets wait time before shutdown
type GracefulShutdownApps ¶ added in v0.5.0
type GracefulShutdownApps struct { Apps *Apps // contains filtered or unexported fields }
GracefulShutdownApps is the apps in graceful shutdown mode
func (*GracefulShutdownApps) ListenAndServe ¶ added in v0.5.0
func (gs *GracefulShutdownApps) ListenAndServe() error
ListenAndServe starts web servers in graceful shutdown mode
func (*GracefulShutdownApps) Notify ¶ added in v0.5.0
func (gs *GracefulShutdownApps) Notify(fn func()) *GracefulShutdownApps
Notify calls fn when receive terminate signal from os
func (*GracefulShutdownApps) Timeout ¶ added in v0.5.0
func (gs *GracefulShutdownApps) Timeout(d time.Duration) *GracefulShutdownApps
Timeout sets shutdown timeout for graceful shutdown, set to 0 to disable timeout
default is 0
func (*GracefulShutdownApps) Wait ¶ added in v0.5.0
func (gs *GracefulShutdownApps) Wait(d time.Duration) *GracefulShutdownApps
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
func (*Template) Config ¶ added in v0.4.2
func (tp *Template) Config(cfg TemplateConfig) *Template
Config loads template config
func (*Template) ParseConfig ¶ added in v0.4.2
ParseConfig parses template config data
func (*Template) ParseConfigFile ¶ added in v0.4.2
ParseConfigFile parses template config from file
type TemplateConfig ¶ added in v0.4.2
type TemplateConfig 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"` }
TemplateConfig is template config