diff --git a/config/basicauth.go b/config/basicauth.go index dc0a7103..fb444d62 100644 --- a/config/basicauth.go +++ b/config/basicauth.go @@ -7,7 +7,7 @@ import ( ) const ( - // DefaultBasicAuth is "Authorization Required" + // DefaultBasicAuthRealm is "Authorization Required" DefaultBasicAuthRealm = "Authorization Required" // DefaultBasicAuthContextKey is the "auth" // this key is used to do context.Set("auth", theUsernameFromBasicAuth) diff --git a/config/editor.go b/config/editor.go index 4b090a1c..fc3b84fa 100644 --- a/config/editor.go +++ b/config/editor.go @@ -2,6 +2,7 @@ package config import "github.com/imdario/mergo" +// Editor the configs for the Editor plugin type Editor struct { // Host if empty used the iris server's host Host string @@ -34,7 +35,7 @@ func (c Editor) Merge(cfg []Editor) (config Editor) { return } -// Merge MergeSingle the default with the given config and returns the result +// MergeSingle merges the default with the given config and returns the result func (c Editor) MergeSingle(cfg Editor) (config Editor) { config = cfg diff --git a/config/iris.go b/config/iris.go index 0180ea65..4056eda1 100644 --- a/config/iris.go +++ b/config/iris.go @@ -4,6 +4,7 @@ import ( "github.com/imdario/mergo" ) +// DefaultProfilePath is the default profile(http debug) path which is /debug/pprof const DefaultProfilePath = "/debug/pprof" type ( @@ -145,7 +146,7 @@ func (c Iris) Merge(cfg []Iris) (config Iris) { return } -// Merge MergeSingle the default with the given config and returns the result +// MergeSingle merges the default with the given config and returns the result func (c Iris) MergeSingle(cfg Iris) (config Iris) { config = cfg diff --git a/config/logger.go b/config/logger.go index 1aa47584..25e1f01f 100644 --- a/config/logger.go +++ b/config/logger.go @@ -13,6 +13,7 @@ var ( ) type ( + // Logger contains the configs for the Logger Logger struct { Out io.Writer Prefix string @@ -20,6 +21,7 @@ type ( } ) +// DefaultLogger returns the default configs for the Logger func DefaultLogger() Logger { return Logger{Out: os.Stdout, Prefix: "", Flag: 0} } diff --git a/config/sessions.go b/config/sessions.go index b802c5ee..f2299b44 100644 --- a/config/sessions.go +++ b/config/sessions.go @@ -14,7 +14,8 @@ var ( const ( // DefaultCookieName the secret cookie's name for sessions - DefaultCookieName = "irissessionid" + DefaultCookieName = "irissessionid" + // DefaultSessionGcDuration is the default Session Manager's GCDuration , which is 2 hours DefaultSessionGcDuration = time.Duration(2) * time.Hour // DefaultRedisNetwork the redis network option, "tcp" DefaultRedisNetwork = "tcp" @@ -97,7 +98,7 @@ func (c Sessions) Merge(cfg []Sessions) (config Sessions) { return } -// Merge MergeSingle the default with the given config and returns the result +// MergeSingle merges the default with the given config and returns the result func (c Sessions) MergeSingle(cfg Sessions) (config Sessions) { config = cfg @@ -135,7 +136,7 @@ func (c Redis) Merge(cfg []Redis) (config Redis) { return } -// Merge MergeSingle the default with the given config and returns the result +// MergeSingle merges the default with the given config and returns the result func (c Redis) MergeSingle(cfg Redis) (config Redis) { config = cfg diff --git a/context_renderer.go b/context_renderer.go index 7138a86c..554bb6db 100644 --- a/context_renderer.go +++ b/context_renderer.go @@ -43,7 +43,7 @@ func (ctx *Context) Render(name string, binding interface{}, layout ...string) e return ctx.HTML(StatusOK, name, binding, layout...) } -// RenderStrings accepts a template filename, its context data and returns the result of the parsed template (string) +// RenderString accepts a template filename, its context data and returns the result of the parsed template (string) func (ctx *Context) RenderString(name string, binding interface{}, layout ...string) (result string, err error) { return ctx.station.templates.RenderString(name, binding, layout...) } @@ -96,7 +96,7 @@ func (ctx *Context) ExecuteTemplate(tmpl *template.Template, pageContext interfa // receives three parameters, it's low-level function, instead you can use .ServeFile(string) // // You can define your own "Content-Type" header also, after this function call -func (ctx *Context) ServeContent(content io.ReadSeeker, filename string, modtime time.Time, gzipCompression bool) (err error) { +func (ctx *Context) ServeContent(content io.ReadSeeker, filename string, modtime time.Time, gzipCompression bool) error { if t, err := time.Parse(TimeFormat, ctx.RequestHeader(IfModifiedSince)); err == nil && modtime.Before(t.Add(1*time.Second)) { ctx.RequestCtx.Response.Header.Del(ContentType) ctx.RequestCtx.Response.Header.Del(ContentLength) @@ -119,7 +119,7 @@ func (ctx *Context) ServeContent(content io.ReadSeeker, filename string, modtime out = ctx.RequestCtx.Response.BodyWriter() } - _, err = io.Copy(out, content) + _, err := io.Copy(out, content) return ErrServeContent.With(err) } diff --git a/iris.go b/iris.go index 00dfcb09..d6644e52 100644 --- a/iris.go +++ b/iris.go @@ -59,8 +59,8 @@ var ( DefaultEngine = config.DefaultEngine // NoEngine conversion for config.NoEngine NoEngine = config.NoEngine - // - + // NoLayout to disable layout for a particular template file + // conversion for config.NoLayout NoLayout = config.NoLayout ) @@ -192,7 +192,7 @@ func (s *Iris) printBanner() { } }() - var i uint64 = 0 + var i uint64 printTicker.OnTick(func() { if len(banner) <= int(atomic.LoadUint64(&i)) { diff --git a/iris_singleton.go b/iris_singleton.go index 09876078..b66ad4f9 100644 --- a/iris_singleton.go +++ b/iris_singleton.go @@ -11,7 +11,7 @@ import ( ) // DefaultIris in order to use iris.Get(...,...) we need a default Iris on the package level -var DefaultIris *Iris = New() +var DefaultIris = New() // Listen starts the standalone http server // which listens to the addr parameter which as the form of diff --git a/party.go b/party.go index 1735a419..4e1f30a0 100644 --- a/party.go +++ b/party.go @@ -179,7 +179,8 @@ func (p *GardenParty) API(path string, controller HandlerAPI, middlewares ...Han } func(path string, typ reflect.Type, contextField reflect.StructField, methodFunc reflect.Value, method string) { - handlersFn := make([]HandlerFunc, 0) + var handlersFn []HandlerFunc + handlersFn = append(handlersFn, middlewares...) handlersFn = append(handlersFn, func(ctx *Context) { newController := reflect.New(typ).Elem() @@ -223,7 +224,8 @@ func (p *GardenParty) API(path string, controller HandlerAPI, middlewares ...Han } func(registedPath string, typ reflect.Type, contextField reflect.StructField, methodFunc reflect.Value, paramsLen int, method string) { - handlersFn := make([]HandlerFunc, 0) + var handlersFn []HandlerFunc + handlersFn = append(handlersFn, middlewares...) handlersFn = append(handlersFn, func(ctx *Context) { newController := reflect.New(typ).Elem() @@ -407,7 +409,7 @@ func (p *GardenParty) StaticHandlerFunc(systemPath string, stripSlashes int, com // * stripSlashes = 2, original path: "/foo/bar", result: "" func (p *GardenParty) Static(relative string, systemPath string, stripSlashes int) { if relative[len(relative)-1] != SlashByte { // if / then /*filepath, if /something then /something/*filepath - relative += "/" + relative += Slash } h := p.StaticHandlerFunc(systemPath, stripSlashes, false, false, nil) @@ -447,7 +449,6 @@ func (p *GardenParty) StaticFS(reqPath string, systemPath string, stripSlashes i // * stripSlashes = 1, original path: "/foo/bar", result: "/bar" // * stripSlashes = 2, original path: "/foo/bar", result: "" // * if you don't know what to put on stripSlashes just 1 - func (p *GardenParty) StaticWeb(reqPath string, systemPath string, stripSlashes int) { if reqPath[len(reqPath)-1] != SlashByte { // if / then /*filepath, if /something then /something/*filepath reqPath += "/" diff --git a/plugin.go b/plugin.go index 4d03d429..93940395 100644 --- a/plugin.go +++ b/plugin.go @@ -45,6 +45,7 @@ type ( // parameter is the Route PreHandle(IRoute) } + // PreHandleFunc implements the simple function listener for the PreHandle(IRoute) PreHandleFunc func(IRoute) // IPluginPostHandle implements the PostHandle(IRoute) method IPluginPostHandle interface { @@ -53,6 +54,7 @@ type ( // parameter is the Route PostHandle(IRoute) } + // PostHandleFunc implements the simple function listener for the PostHandle(IRoute) PostHandleFunc func(IRoute) // IPluginPreListen implements the PreListen(*Iris) method IPluginPreListen interface { @@ -61,6 +63,7 @@ type ( // parameter is the station PreListen(*Iris) } + // PreListenFunc implements the simple function listener for the PreListen(*Iris) PreListenFunc func(*Iris) // IPluginPostListen implements the PostListen(*Iris) method IPluginPostListen interface { @@ -68,6 +71,7 @@ type ( // parameter is the station PostListen(*Iris) } + // PostListenFunc implements the simple function listener for the PostListen(*Iris) PostListenFunc func(*Iris) // IPluginPreClose implements the PreClose(*Iris) method IPluginPreClose interface { @@ -77,6 +81,7 @@ type ( // The plugin is deactivated after this state PreClose(*Iris) } + // PreCloseFunc implements the simple function listener for the PreClose(*Iris) PreCloseFunc func(*Iris) // IPluginPreDownload It's for the future, not being used, I need to create @@ -91,6 +96,8 @@ type ( // must return a boolean, if false then the plugin is not permmited to download this file PreDownload(plugin IPlugin, downloadURL string) // bool } + + // PreDownloadFunc implements the simple function listener for the PreDownload(IPlugin,string) PreDownloadFunc func(IPlugin, string) // IPluginContainer is the interface which the PluginContainer should implements @@ -137,26 +144,46 @@ type ( // convert the functions to IPlugin +// PreHandle it's being called every time BEFORE a Route is registed to the Router +// +// parameter is the Route func (fn PreHandleFunc) PreHandle(route IRoute) { fn(route) } +// PostHandle it's being called every time AFTER a Route successfully registed to the Router +// +// parameter is the Route func (fn PostHandleFunc) PostHandle(route IRoute) { fn(route) } +// PreListen it's being called only one time, BEFORE the Server is started (if .Listen called) +// is used to do work at the time all other things are ready to go +// parameter is the station func (fn PreListenFunc) PreListen(station *Iris) { fn(station) } +// PostListen it's being called only one time, AFTER the Server is started (if .Listen called) +// parameter is the station func (fn PostListenFunc) PostListen(station *Iris) { fn(station) } +// PreClose it's being called only one time, BEFORE the Iris .Close method +// any plugin cleanup/clear memory happens here +// +// The plugin is deactivated after this state func (fn PreCloseFunc) PreClose(station *Iris) { fn(station) } +// PreDownload it's being called every time a plugin tries to download something +// +// first parameter is the plugin +// second parameter is the download url +// must return a boolean, if false then the plugin is not permmited to download this file func (fn PreDownloadFunc) PreDownload(pl IPlugin, downloadURL string) { fn(pl, downloadURL) } diff --git a/render/template/engine/amber/amber.go b/render/template/engine/amber/amber.go index a8e71be7..dea8033e 100644 --- a/render/template/engine/amber/amber.go +++ b/render/template/engine/amber/amber.go @@ -12,16 +12,19 @@ import ( "github.com/kataras/iris/config" ) +// Engine the amber template engine type Engine struct { Config *config.Template templateCache map[string]*template.Template mu sync.Mutex } +// New creates and returns a new amber engine func New(cfg config.Template) *Engine { return &Engine{Config: &cfg} } +// BuildTemplates builds the amber templates func (e *Engine) BuildTemplates() error { opt := amber.DirOptions{} opt.Recursive = true @@ -67,6 +70,7 @@ func (e *Engine) fromCache(relativeName string) *template.Template { return nil } +// ExecuteWriter executes a templates and write its results to the out writer func (e *Engine) ExecuteWriter(out io.Writer, name string, binding interface{}, layout string) error { if tmpl := e.fromCache(name); tmpl != nil { return tmpl.ExecuteTemplate(out, name, binding) diff --git a/render/template/engine/html/html.go b/render/template/engine/html/html.go index 880047db..f46786b7 100644 --- a/render/template/engine/html/html.go +++ b/render/template/engine/html/html.go @@ -14,6 +14,7 @@ import ( ) type ( + // Engine the html/template engine Engine struct { Config *config.Template Templates *template.Template diff --git a/render/template/engine/jade/jade.go b/render/template/engine/jade/jade.go index 362a7f51..bbf2c457 100644 --- a/render/template/engine/jade/jade.go +++ b/render/template/engine/jade/jade.go @@ -11,7 +11,7 @@ type Engine struct { *html.Engine } -// new creates and returns a new JadeEngine with its configs +// New creates and returns a new JadeEngine with its configs func New(cfg config.Template) *Engine { underline := &Engine{Engine: html.New(cfg)} diff --git a/render/template/engine/markdown/markdown.go b/render/template/engine/markdown/markdown.go index a56f8f65..5726d43b 100644 --- a/render/template/engine/markdown/markdown.go +++ b/render/template/engine/markdown/markdown.go @@ -16,7 +16,9 @@ import ( ) // Supports RAW markdown only, no context binding or layout, to use dynamic markdown with other template engine use the context.Markdown/MarkdownString + type ( + // Engine the jade engine Engine struct { Config *config.Template templateCache map[string][]byte @@ -29,6 +31,7 @@ func New(c config.Template) *Engine { return &Engine{Config: &c, templateCache: make(map[string][]byte)} } +// BuildTemplates builds the templates func (e *Engine) BuildTemplates() error { if e.Config.Asset == nil || e.Config.AssetNames == nil { return e.buildFromDir() @@ -140,7 +143,8 @@ func (e *Engine) fromCache(relativeName string) []byte { return nil } -// layout here is unnesecery +// ExecuteWriter executes a templates and write its results to the out writer +// layout here is useless func (e *Engine) ExecuteWriter(out io.Writer, name string, binding interface{}, layout string) error { if tmpl := e.fromCache(name); tmpl != nil { _, err := out.Write(tmpl) diff --git a/route.go b/route.go index 4951d43c..44e11701 100644 --- a/route.go +++ b/route.go @@ -24,7 +24,7 @@ type ( // // used to check arguments with the route's named parameters and return the correct url - // second parameter is false when the action cannot be done + // second return value is false when the action cannot be done Parse(...interface{}) (string, bool) // GetURI returns the GetDomain() + Parse(...optional named parameters if route is dynamic) @@ -169,6 +169,8 @@ func (r *Route) setHost(s string) { r.host = s } +// Parse used to check arguments with the route's named parameters and return the correct url +// second return value is false when the action cannot be done func (r *Route) Parse(args ...interface{}) (string, bool) { // check if arguments are not equal to the named parameters ( : = 1, * = all named parameters split to / ), if this happens then send not found err ///TODO: I'm thinking of making an option to disable these checks and just return a result, because they have cost when rendering an html/template, not too big compared to the render action but... we will see @@ -210,6 +212,8 @@ func (r *Route) Parse(args ...interface{}) (string, bool) { return fmt.Sprintf(r.formattedPath, args...), true } +// GetURI returns the GetDomain() + Parse(...optional named parameters if route is dynamic) +// instead of Parse it just returns an empty string if path parse is failed func (r *Route) GetURI(args ...interface{}) (uri string) { scheme := "http://" if r.isTLS { diff --git a/router.go b/router.go index 733594fc..d19d8349 100644 --- a/router.go +++ b/router.go @@ -219,7 +219,7 @@ func (r *router) optimize() { func (r *router) optimizeLookups() { // set the isTLS on all routes and the listening full host listeningHost := r.station.server.Listener().Addr().String() - for idx, _ := range r.lookups { + for idx := range r.lookups { theR := r.lookups[idx] theR.setTLS(r.station.server.IsSecure()) if theR.GetDomain() == "" { // means local, no subdomain diff --git a/sessions/providers/redis/register.go b/sessions/providers/redis/register.go index 9f031d95..63cdc7c6 100644 --- a/sessions/providers/redis/register.go +++ b/sessions/providers/redis/register.go @@ -13,6 +13,7 @@ func init() { } var ( + // Provider is the redis provider Provider = sessions.NewProvider("redis") // redis is the default redis service, you can set configs via this object redis = service.New() diff --git a/sessions/providers/redis/service/service.go b/sessions/providers/redis/service/service.go index 62801b74..4a60ea13 100644 --- a/sessions/providers/redis/service/service.go +++ b/sessions/providers/redis/service/service.go @@ -215,7 +215,7 @@ func dial(network string, addr string, pass string) (redis.Conn, error) { return nil, err } if pass != "" { - if _, err := c.Do("AUTH", pass); err != nil { + if _, err = c.Do("AUTH", pass); err != nil { c.Close() return nil, err } @@ -255,7 +255,7 @@ func (r *Service) Connect() { if err != nil { return nil, err } - if _, err := red.Do("SELECT", c.Database); err != nil { + if _, err = red.Do("SELECT", c.Database); err != nil { red.Close() return nil, err } diff --git a/tree.go b/tree.go index 83955cec..7e162892 100644 --- a/tree.go +++ b/tree.go @@ -132,7 +132,7 @@ func (_tree *tree) serve(reqCtx *fasthttp.RequestCtx, path string) bool { // response because older user agents may not understand 301/307. // Shouldn't send the response for POST or HEAD; that leaves GET. if _tree.method == MethodGet { - note := "Moved Permanently.\n" + note := "Moved Permanently.\n" ctx.Write(note) } _tree.pool.Put(ctx) diff --git a/utils/strings.go b/utils/strings.go index 2ce15c6d..ac56fd41 100644 --- a/utils/strings.go +++ b/utils/strings.go @@ -22,8 +22,8 @@ var htmlReplacer = strings.NewReplacer( "'", "'", ) -// HtmlEscape returns a string which has no valid html code -func HtmlEscape(s string) string { +// HTMLEscape returns a string which has no valid html code +func HTMLEscape(s string) string { return htmlReplacer.Replace(s) }