Documentation
¶
Index ¶
- Variables
- func Compatible() *tls.Config
- func Global(ctx context.Context, key any) any
- func Modern() *tls.Config
- func Restricted() *tls.Config
- func Route(ctx context.Context, name string, params ...any) string
- func SafeRedirectPath(p string) string
- func StartHTTPSRedirectServer(addr string) error
- type App
- func (app *App) Address(addr string)
- func (app *App) Clone() *App
- func (app *App) Config(config AppConfig)
- func (app *App) Global(key any) any
- func (app *App) Globals(globals Globals)
- func (app *App) Handler(h http.Handler)
- func (app *App) ListenAndServe() error
- func (app *App) ParseConfig(data []byte)
- func (app *App) ParseConfigFile(filename string)
- func (app *App) Route(name string, params ...any) string
- func (app *App) Routes(routes Routes)
- func (app *App) SelfSign(s SelfSign)
- func (app *App) Serve(l net.Listener) error
- func (app *App) ServeHTTP(w http.ResponseWriter, r *http.Request)
- func (app *App) ServeHandler(h http.Handler) http.Handler
- func (app *App) Server() *parapet.Server
- func (app *App) SetServer(srv *parapet.Server)
- func (app *App) Shutdown() error
- func (app *App) TLS(certFile, keyFile string)
- func (app *App) Template() *Template
- func (app *App) TemplateFunc(name string, f any)
- func (app *App) TemplateFuncs(funcs ...template.FuncMap)
- type AppConfig
- type Context
- func (ctx *Context) AddCookie(name string, value string, opts *CookieOptions)
- func (ctx *Context) AddHeader(key, value string)
- func (ctx *Context) AddHeaderIfNotExists(key, value string)
- func (ctx *Context) BindJSON(v any) error
- func (ctx *Context) Bytes(b []byte) error
- func (ctx *Context) Component(name string, data any) error
- func (ctx *Context) CookieValue(name string) string
- func (ctx *Context) CopyFrom(src io.Reader) error
- func (ctx *Context) Deadline() (deadline time.Time, ok bool)
- func (ctx *Context) DelCookie(name string, opts *CookieOptions)
- func (ctx *Context) DelHeader(key string)
- func (ctx *Context) Done() <-chan struct{}
- func (ctx *Context) ETag(enable bool) *Context
- func (ctx *Context) Err() error
- func (ctx *Context) Error(error string) error
- func (ctx *Context) File(name string) error
- func (ctx *Context) FormFileHeader(key string) (*multipart.FileHeader, error)
- func (ctx *Context) FormFileHeaderNotEmpty(key string) (*multipart.FileHeader, error)
- func (ctx *Context) FormFileNotEmpty(key string) (multipart.File, *multipart.FileHeader, error)
- func (ctx *Context) FormValueFloat32(key string) float32
- func (ctx *Context) FormValueFloat64(key string) float64
- func (ctx *Context) FormValueInt(key string) int
- func (ctx *Context) FormValueInt64(key string) int64
- func (ctx *Context) FormValueTrimSpace(key string) string
- func (ctx *Context) FormValueTrimSpaceComma(key string) string
- func (ctx *Context) Global(key any) any
- func (ctx *Context) HTML(data string) error
- func (ctx *Context) Handle(h http.Handler) error
- func (ctx *Context) JSON(data any) error
- func (ctx *Context) NoContent() error
- func (ctx *Context) NotFound() error
- func (ctx *Context) Param(name string, value any) *Param
- func (ctx *Context) PostFormValueFloat32(key string) float32
- func (ctx *Context) PostFormValueFloat64(key string) float64
- func (ctx *Context) PostFormValueInt(key string) int
- func (ctx *Context) PostFormValueInt64(key string) int64
- func (ctx *Context) PostFormValueTrimSpace(key string) string
- func (ctx *Context) PostFormValueTrimSpaceComma(key string) string
- func (ctx *Context) Redirect(url string, params ...any) error
- func (ctx *Context) RedirectBack(fallback string) error
- func (ctx *Context) RedirectBackToGet() error
- func (ctx *Context) RedirectTo(name string, params ...any) error
- func (ctx *Context) RedirectToGet() error
- func (ctx *Context) Render(tmpl string, data any) error
- func (ctx *Context) ResponseWriter() http.ResponseWriter
- func (ctx *Context) Route(name string, params ...any) string
- func (ctx *Context) SafeRedirect(url string, params ...any) error
- func (ctx *Context) SafeRedirectBack(fallback string) error
- func (ctx *Context) SetHeader(key, value string)
- func (ctx *Context) Status(code int) *Context
- func (ctx *Context) StatusText() error
- func (ctx *Context) String(format string, a ...any) error
- func (ctx *Context) Value(key any) any
- func (ctx *Context) View(name string, data any) error
- func (ctx *Context) WithContext(nctx context.Context) *Context
- func (ctx *Context) WithRequest(r *http.Request) *Context
- func (ctx *Context) WithResponseWriter(w http.ResponseWriter) *Context
- func (ctx *Context) WithValue(key any, val any) *Context
- type CookieOptions
- type ErrComponentDuplicate
- type ErrComponentNotFound
- type ErrRouteNotFound
- type ErrTemplateDuplicate
- type ErrTemplateNotFound
- type Globals
- type HTTPSRedirect
- type Handler
- type Param
- type Routes
- type SelfSign
- type TLS
- type Template
- func (tp *Template) Component(ts ...*template.Template)
- func (tp *Template) Config(cfg TemplateConfig)
- func (tp *Template) Delims(left, right string)
- func (tp *Template) Dir(path string)
- func (tp *Template) FS(fs fs.FS)
- func (tp *Template) Func(name string, f any)
- func (tp *Template) Funcs(funcs ...template.FuncMap)
- func (tp *Template) Minify()
- func (tp *Template) MinifyWith(cfg TemplateMinifyConfig)
- func (tp *Template) Parse(name string, text string)
- func (tp *Template) ParseComponent(name string, text string)
- func (tp *Template) ParseComponentFile(name string, filename string)
- func (tp *Template) ParseConfig(data []byte)
- func (tp *Template) ParseConfigFile(filename string)
- func (tp *Template) ParseFiles(name string, filenames ...string)
- func (tp *Template) ParseGlob(name string, pattern string)
- func (tp *Template) Preload(filename ...string)
- func (tp *Template) Root(name string)
- type TemplateConfig
- type TemplateMinifyConfig
Constants ¶
This section is empty.
Variables ¶
var (
ErrAppNotFound = errors.New("hime: app not found")
)
Errors
Functions ¶
func SafeRedirectPath ¶
SafeRedirectPath filters domain out from path
func StartHTTPSRedirectServer ¶
StartHTTPSRedirectServer starts http to https redirect server
Types ¶
type App ¶
type App struct {
ETag bool
// contains filtered or unexported fields
}
App is the hime app
func (*App) Config ¶
Config merges config into app's config
Example:
globals:
data1: test
routes:
index: / about: /about
templates:
- dir: view root: layout delims: ["{{", "}}"] minify: true preload:
- comp/comp1.tmpl
- comp/comp2.tmpl list: main.tmpl:
- main.tmpl
- _layout.tmpl about.tmpl: [about.tmpl, _layout.tmpl]
func (*App) ListenAndServe ¶
ListenAndServe starts web server
func (*App) ParseConfigFile ¶
ParseConfigFile parses config from file
func (*App) TemplateFunc ¶
TemplateFunc registers an app's level template func
func (*App) TemplateFuncs ¶
TemplateFuncs registers app's level template funcs
type AppConfig ¶
type AppConfig struct {
Globals Globals `yaml:"globals" json:"globals"`
Routes Routes `yaml:"routes" json:"routes"`
Templates []TemplateConfig `yaml:"templates" json:"templates"`
}
AppConfig is hime app's config
type Context ¶
Context is hime context
func NewAppContext ¶
NewAppContext creates new hime's context with given app
func NewContext ¶
func NewContext(w http.ResponseWriter, r *http.Request) *Context
NewContext creates new hime's context
func (*Context) AddCookie ¶
func (ctx *Context) AddCookie(name string, value string, opts *CookieOptions)
func (*Context) AddHeaderIfNotExists ¶
AddHeaderIfNotExists adds a header to response if not exists
func (*Context) CookieValue ¶
func (*Context) DelCookie ¶
func (ctx *Context) DelCookie(name string, opts *CookieOptions)
func (*Context) FormFileHeader ¶
func (ctx *Context) FormFileHeader(key string) (*multipart.FileHeader, error)
FormFileHeader returns file header for given key without open file
func (*Context) FormFileHeaderNotEmpty ¶
func (ctx *Context) FormFileHeaderNotEmpty(key string) (*multipart.FileHeader, error)
FormFileHeaderNotEmpty returns file header if not empty, or http.ErrMissingFile if file is empty
This function will be deprecated after drop go1.10 support, since go1.11 bring back old behavior
func (*Context) FormFileNotEmpty ¶
FormFileNotEmpty returns file from r.FormFile only when file size is not empty, or return http.ErrMissingFile if file is empty
func (*Context) FormValueFloat32 ¶
FormValueFloat32 converts form value to float32
func (*Context) FormValueFloat64 ¶
FormValueFloat64 converts form value to float64
func (*Context) FormValueInt ¶
FormValueInt converts form value to int
func (*Context) FormValueInt64 ¶
FormValueInt64 converts form value to int64
func (*Context) FormValueTrimSpace ¶
FormValueTrimSpace trims space from form value
func (*Context) FormValueTrimSpaceComma ¶
FormValueTrimSpaceComma trims space and remove comma from form value
func (*Context) PostFormValueFloat32 ¶
PostFormValueFloat32 converts post form value to flost32
func (*Context) PostFormValueFloat64 ¶
PostFormValueFloat64 converts post form value to flost64
func (*Context) PostFormValueInt ¶
PostFormValueInt converts post form value to int
func (*Context) PostFormValueInt64 ¶
PostFormValueInt64 converts post form value to int64
func (*Context) PostFormValueTrimSpace ¶
PostFormValueTrimSpace trims space from post form value
func (*Context) PostFormValueTrimSpaceComma ¶
PostFormValueTrimSpaceComma trims space and remove comma from post form value
func (*Context) RedirectBack ¶
RedirectBack redirects to referer or fallback if referer not exists
func (*Context) RedirectBackToGet ¶
RedirectBackToGet redirects to referer or fallback with same url
func (*Context) RedirectTo ¶
RedirectTo redirects to route name
func (*Context) RedirectToGet ¶
RedirectToGet redirects to same url back to Get
func (*Context) ResponseWriter ¶
func (ctx *Context) ResponseWriter() http.ResponseWriter
ResponseWriter returns response writer
func (*Context) SafeRedirect ¶
SafeRedirect extracts only path from url then redirect
func (*Context) SafeRedirectBack ¶
SafeRedirectBack safe redirects to referer
func (*Context) StatusText ¶
StatusText writes status text from seted status code tnto response writer
func (*Context) WithContext ¶
WithContext returns new context with new request with given context
func (*Context) WithRequest ¶
WithRequest returns new context with given request
func (*Context) WithResponseWriter ¶
func (ctx *Context) WithResponseWriter(w http.ResponseWriter) *Context
WithResponseWriter returns new context with given response writer
type CookieOptions ¶
type ErrComponentDuplicate ¶
type ErrComponentDuplicate struct {
Name string
}
ErrComponentDuplicate is the error for component duplicate
func (*ErrComponentDuplicate) Error ¶
func (err *ErrComponentDuplicate) Error() string
type ErrComponentNotFound ¶
type ErrComponentNotFound struct {
Name string
}
ErrComponentNotFound is the error for component not found
func (*ErrComponentNotFound) Error ¶
func (err *ErrComponentNotFound) Error() string
type ErrRouteNotFound ¶
type ErrRouteNotFound struct {
Route string
}
ErrRouteNotFound is the error for route not found
func (*ErrRouteNotFound) Error ¶
func (err *ErrRouteNotFound) Error() string
type ErrTemplateDuplicate ¶
type ErrTemplateDuplicate struct {
Name string
}
ErrTemplateDuplicate is the error for template duplicate
func (*ErrTemplateDuplicate) Error ¶
func (err *ErrTemplateDuplicate) Error() string
type ErrTemplateNotFound ¶
type ErrTemplateNotFound struct {
Name string
}
ErrTemplateNotFound is the error for template not found
func (*ErrTemplateNotFound) Error ¶
func (err *ErrTemplateNotFound) Error() string
type HTTPSRedirect ¶
type HTTPSRedirect struct {
Addr string `json:"addr"`
}
HTTPSRedirect type
func (*HTTPSRedirect) ServeHTTP ¶
func (s *HTTPSRedirect) ServeHTTP(w http.ResponseWriter, r *http.Request)
func (HTTPSRedirect) Server ¶
func (s HTTPSRedirect) Server() *http.Server
Server generates https redirect server
type SelfSign ¶
type SelfSign struct {
Key struct {
Algo string `yaml:"algo" json:"algo"`
Size int `yaml:"size" json:"size"`
} `yaml:"key" json:"key"`
CN string `yaml:"cn" json:"cn"`
Hosts []string `yaml:"host" json:"host"`
}
SelfSign type
type TLS ¶
type TLS struct {
SelfSign *SelfSign `yaml:"selfSign" json:"selfSign"`
CertFile string `yaml:"certFile" json:"certFile"`
KeyFile string `yaml:"keyFile" json:"keyFile"`
Profile string `yaml:"profile" json:"profile"`
MinVersion string `yaml:"minVersion" json:"minVersion"`
MaxVersion string `yaml:"maxVersion" json:"maxVersion"`
Curves []string `yaml:"curves" json:"curves"`
}
TLS type
type Template ¶
type Template struct {
// contains filtered or unexported fields
}
Template is template loader
func (*Template) Config ¶
func (tp *Template) Config(cfg TemplateConfig)
Config loads template config
func (*Template) Minify ¶
func (tp *Template) Minify()
Minify enables minify when render html, css, js, must call before parse
func (*Template) MinifyWith ¶
func (tp *Template) MinifyWith(cfg TemplateMinifyConfig)
MinifyWith enables minify with custom options, must call before parse
func (*Template) ParseComponent ¶
ParseComponent parses component from text
func (*Template) ParseComponentFile ¶
ParseComponentFile loads component from file
func (*Template) ParseConfig ¶
ParseConfig parses template config data
func (*Template) ParseConfigFile ¶
ParseConfigFile parses template config from file
func (*Template) ParseFiles ¶
ParseFiles loads template from file
type TemplateConfig ¶
type TemplateConfig struct {
Dir string `yaml:"dir" json:"dir"`
Root string `yaml:"root" json:"root"`
Minify bool `yaml:"minify" json:"minify"`
Preload []string `yaml:"preload" json:"preload"`
List map[string][]string `yaml:"list" json:"list"`
Delims []string `yaml:"delims" json:"delims"`
}
TemplateConfig is template config