mirror of
https://github.com/kataras/iris.git
synced 2025-01-23 02:31:04 +01:00
Update to 4.1.7. Logger changes, read HISTORY.md
This commit is contained in:
parent
eacc04406a
commit
1a7c79db66
|
@ -2,6 +2,14 @@
|
|||
|
||||
**How to upgrade**: remove your `$GOPATH/src/github.com/kataras/iris` folder, open your command-line and execute this command: `go get -u github.com/kataras/iris/iris`.
|
||||
|
||||
## 4.1.6 -> 4.1.7
|
||||
|
||||
- **CHANGED**: Use of the standard `log.Logger` instead of the `iris-contrib/logger`(colorful logger), these changes are reflects some middleware, examples and plugins, I updated all of them, so don't worry.
|
||||
|
||||
So, [iris-contrib/middleware/logger](https://github.com/iris-contrib/middleware/tree/master/logger) will now NO need to pass other Logger instead, instead of: `iris.Use(logger.New(iris.Logger))` use -> `iris.Use(logger.New())` which will use the iris/instance's Logger.
|
||||
|
||||
- **ADDED**: `context.Framework()` which returns your Iris instance (typeof `*iris.Framework`), useful for the future(Iris will give you, soon, the ability to pass custom options inside an iris instance).
|
||||
|
||||
## 4.1.5 -> 4.1.6
|
||||
|
||||
- Align with [go-sessions](https://github.com/kataras/go-sessions), no front-end changes, however I think that the best time to make an upgrade to your local Iris is right now.
|
||||
|
|
83
README.md
83
README.md
|
@ -3,31 +3,68 @@
|
|||
|
||||
<a href="https://www.gitbook.com/book/kataras/iris/details"><img width="600" src="https://raw.githubusercontent.com/iris-contrib/website/gh-pages/assets/book/cover_6_flat_alpha.png"></a>
|
||||
|
||||
<br/>
|
||||
<br/><br/>
|
||||
|
||||
<a href="https://travis-ci.org/kataras/iris"><img src="https://img.shields.io/travis/kataras/iris.svg?style=flat-square" alt="Build Status"></a>
|
||||
|
||||
<a href="https://github.com/kataras/iris/blob/master/LICENSE"><img src="https://img.shields.io/badge/%20license-MIT%20%20License%20-E91E63.svg?style=flat-square" alt="License"></a>
|
||||
<a href="https://github.com/avelino/awesome-go"><img src="https://img.shields.io/badge/awesome-%E2%9C%93-ff69b4.svg?style=flat-square" alt="https://cdn.rawgit.com/sindresorhus/awesome/d7305f38d29fed78fa85652e3a63e154dd8e8829/media/badge.svg"></a>
|
||||
|
||||
<a href="https://github.com/kataras/iris/releases"><img src="https://img.shields.io/badge/%20release%20-%20v4.1.6%20-blue.svg?style=flat-square" alt="Releases"></a>
|
||||
<a href="#"><img src="https://img.shields.io/badge/platform-Any-ec2eb4.svg?style=flat-square" alt="Platforms"></a>
|
||||
|
||||
<a href="https://www.gitbook.com/book/kataras/iris/details"><img src="https://img.shields.io/badge/%20docs-reference-5272B4.svg?style=flat-square" alt="Practical Guide/Docs"></a><br/>
|
||||
|
||||
<a href="https://github.com/iris-contrib/examples"><img src="https://img.shields.io/badge/%20examples-repository-3362c2.svg?style=flat-square" alt="Examples"></a>
|
||||
|
||||
<a href="https://kataras.rocket.chat/channel/iris"><img src="https://img.shields.io/badge/%20community-chat-00BCD4.svg?style=flat-square" alt="Build Status"></a>
|
||||
<a href="https://github.com/kataras/iris/blob/master/LICENSE"><img src="https://img.shields.io/badge/%20license-MIT-E91E63.svg?style=flat-square" alt="License"></a>
|
||||
|
||||
<a href="https://golang.org"><img src="https://img.shields.io/badge/powered_by-Go-3362c2.svg?style=flat-square" alt="Built with GoLang"></a>
|
||||
|
||||
<a href="#"><img src="https://img.shields.io/badge/platform-Any--OS-yellow.svg?style=flat-square" alt="Platforms"></a>
|
||||
<br/><br/>
|
||||
<img alt="Benchmark Wizzard July 21, 2016- Processing Time Horizontal Grap" src="https://raw.githubusercontent.com/smallnest/go-web-framework-benchmark/4db507a22c964c9bc9774c5b31afdc199a0fe8b7/benchmark.png" />
|
||||
<br/><br/>
|
||||
<br/>
|
||||
|
||||
|
||||
<a href="https://github.com/kataras/iris/releases"><img src="https://img.shields.io/badge/%20version%20-%204.1.7%20-blue.svg?style=flat-square" alt="Releases"></a>
|
||||
|
||||
<a href="https://github.com/iris-contrib/examples"><img src="https://img.shields.io/badge/%20examples-repository-3362c2.svg?style=flat-square" alt="Examples"></a>
|
||||
|
||||
<a href="https://www.gitbook.com/book/kataras/iris/details"><img src="https://img.shields.io/badge/%20docs-reference-5272B4.svg?style=flat-square" alt="Practical Guide/Docs"></a>
|
||||
|
||||
<a href="https://kataras.rocket.chat/channel/iris"><img src="https://img.shields.io/badge/%20community-chat-00BCD4.svg?style=flat-square" alt="Chat"></a><br/><br/>
|
||||
|
||||
|
||||
The <a href="https://github.com/kataras/iris#benchmarks">fastest</a> backend web framework for Go. Easy to <a href="https://www.gitbook.com/book/kataras/iris/details">learn</a>, while it's highly customizable. <br/>
|
||||
Ideally suited for both experienced and novice <b>Developers</b>.
|
||||
<br/>
|
||||
|
||||
The <a href="https://github.com/kataras/iris#benchmarks">fastest</a> backend web framework, written entirely in Go. <br/>Easy to <a href="https://www.gitbook.com/book/kataras/iris/details">learn</a>, while it's highly customizable. <br/>
|
||||
Ideally suited for both experienced and novice Developers. <br/>
|
||||
</p>
|
||||
|
||||
|
||||
|
||||
Quick look
|
||||
------------
|
||||
|
||||
```go
|
||||
package main
|
||||
|
||||
import "github.com/kataras/iris"
|
||||
|
||||
func main() {
|
||||
iris.Favicon("./favicon.ico")
|
||||
|
||||
iris.Get("/", func(ctx *iris.Context) {
|
||||
ctx.Render("index.html")
|
||||
})
|
||||
|
||||
iris.Get("/login", func(ctx *iris.Context) {
|
||||
ctx.Render("login.html", iris.Map{"Title": "Login Page"})
|
||||
})
|
||||
|
||||
iris.Post("/login", func(ctx *iris.Context) {
|
||||
secret := ctx.PostValue("secret")
|
||||
ctx.Session().Set("secret", secret)
|
||||
|
||||
ctx.Redirect("/user")
|
||||
})
|
||||
|
||||
iris.Listen(":8080")
|
||||
}
|
||||
```
|
||||
|
||||
Installation
|
||||
------------
|
||||
The only requirement is the [Go Programming Language](https://golang.org/dl), at least v1.7.
|
||||
|
@ -141,18 +178,26 @@ I recommend writing your API tests using this new library, [httpexpect](https://
|
|||
Versioning
|
||||
------------
|
||||
|
||||
Current: **v4.1.6**
|
||||
Current: **v4.1.7**
|
||||
|
||||
> Iris is an active project
|
||||
|
||||
Read more about Semantic Versioning 2.0.0
|
||||
|
||||
- http://semver.org/
|
||||
- https://en.wikipedia.org/wiki/Software_versioning
|
||||
- https://wiki.debian.org/UpstreamGuide#Releases_and_Versions
|
||||
|
||||
Todo
|
||||
------------
|
||||
- [x] Use of the standard `log.Logger` instead of the `iris-contrib/logger`(colorful logger), make these changes to all middleware, examples and plugins.
|
||||
- [ ] Implement, even, a better way to manage configuration/options, devs will be able to set their own custom options inside there. ` I'm thinking of something the last days, but it will have breaking changes. `
|
||||
- [ ] Implement an internal updater, as requested [here](https://github.com/kataras/iris/issues/401).
|
||||
|
||||
Iris is a community-driven project, waiting for your suggestions and feature requests to add some items here!
|
||||
Iris is a **Community-Driven** Project, waiting for your suggestions and [feature requests](https://github.com/kataras/iris/issues?utf8=%E2%9C%93&q=label%3A%22feature%20request%22)!
|
||||
|
||||
|
||||
If you're **willing to donate** click [here](DONATIONS.md)!
|
||||
I, as the author of this package, am working full time on this package, no time to any other job, so
|
||||
if you're **willing to donate** and you can **afford it** please click [here](DONATIONS.md), thank you!
|
||||
|
||||
People
|
||||
------------
|
||||
|
@ -176,7 +221,7 @@ License can be found [here](LICENSE).
|
|||
[Travis]: http://travis-ci.org/kataras/iris
|
||||
[License Widget]: https://img.shields.io/badge/license-MIT%20%20License%20-E91E63.svg?style=flat-square
|
||||
[License]: https://github.com/kataras/iris/blob/master/LICENSE
|
||||
[Release Widget]: https://img.shields.io/badge/release-v4.1.6-blue.svg?style=flat-square
|
||||
[Release Widget]: https://img.shields.io/badge/release-v4.1.7-blue.svg?style=flat-square
|
||||
[Release]: https://github.com/kataras/iris/releases
|
||||
[Chat Widget]: https://img.shields.io/badge/community-chat-00BCD4.svg?style=flat-square
|
||||
[Chat]: https://kataras.rocket.chat/channel/iris
|
||||
|
|
|
@ -1,6 +1,9 @@
|
|||
package config
|
||||
|
||||
import (
|
||||
"io"
|
||||
"os"
|
||||
|
||||
"github.com/imdario/mergo"
|
||||
)
|
||||
|
||||
|
@ -9,6 +12,11 @@ const (
|
|||
DefaultDisablePathCorrection = false
|
||||
DefaultDisablePathEscape = false
|
||||
DefaultCharset = "UTF-8"
|
||||
DefaultLoggerPreffix = "[IRIS] "
|
||||
)
|
||||
|
||||
var (
|
||||
DefaultLoggerOut = os.Stdout
|
||||
)
|
||||
|
||||
type (
|
||||
|
@ -42,6 +50,15 @@ type (
|
|||
// Default is false
|
||||
DisableBanner bool
|
||||
|
||||
// LoggerOut is the destination for output
|
||||
//
|
||||
// defaults to os.Stdout
|
||||
LoggerOut io.Writer
|
||||
// LoggerOut is the logger's prefix to write at beginning of each line
|
||||
//
|
||||
// Defaults to [IRIS]
|
||||
LoggerPreffix string
|
||||
|
||||
// ProfilePath a the route path, set it to enable http pprof tool
|
||||
// Default is empty, if you set it to a $path, these routes will handled:
|
||||
// $path/cmdline
|
||||
|
@ -106,6 +123,8 @@ func Default() Iris {
|
|||
DisablePathCorrection: DefaultDisablePathCorrection,
|
||||
DisablePathEscape: DefaultDisablePathEscape,
|
||||
DisableBanner: false,
|
||||
LoggerOut: DefaultLoggerOut,
|
||||
LoggerPreffix: DefaultLoggerPreffix,
|
||||
DisableTemplateEngines: false,
|
||||
IsDevelopment: false,
|
||||
Charset: DefaultCharset,
|
||||
|
|
|
@ -568,7 +568,9 @@ func (ctx *Context) Render(name string, binding interface{}, options ...map[stri
|
|||
func (ctx *Context) MustRender(name string, binding interface{}, options ...map[string]interface{}) {
|
||||
if err := ctx.Render(name, binding, options...); err != nil {
|
||||
ctx.Panic()
|
||||
ctx.framework.Logger.Dangerf("MustRender panics for client with IP: %s On template: %s.Trace: %s\n", ctx.RemoteAddr(), name, err)
|
||||
if ctx.framework.Config.IsDevelopment {
|
||||
ctx.framework.Logger.Printf("MustRender panics for client with IP: %s On template: %s.Trace: %s\n", ctx.RemoteAddr(), name, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -978,3 +980,8 @@ func (ctx *Context) SessionDestroy() {
|
|||
func (ctx *Context) Log(format string, a ...interface{}) {
|
||||
ctx.framework.Logger.Printf(format, a...)
|
||||
}
|
||||
|
||||
// Framework returns the Iris instance, containing the configuration and all other fields
|
||||
func (ctx *Context) Framework() *Framework {
|
||||
return ctx.framework
|
||||
}
|
||||
|
|
7
http.go
7
http.go
|
@ -13,8 +13,9 @@ import (
|
|||
"sync"
|
||||
"time"
|
||||
|
||||
"log"
|
||||
|
||||
"github.com/iris-contrib/letsencrypt"
|
||||
"github.com/iris-contrib/logger"
|
||||
"github.com/kataras/go-errors"
|
||||
"github.com/kataras/iris/config"
|
||||
"github.com/kataras/iris/utils"
|
||||
|
@ -1336,7 +1337,7 @@ type (
|
|||
|
||||
api *muxAPI
|
||||
errorHandlers map[int]Handler
|
||||
logger *logger.Logger
|
||||
logger *log.Logger
|
||||
// the main server host's name, ex: localhost, 127.0.0.1, 0.0.0.0, iris-go.com
|
||||
hostname string
|
||||
// if any of the trees contains not empty subdomain
|
||||
|
@ -1351,7 +1352,7 @@ type (
|
|||
}
|
||||
)
|
||||
|
||||
func newServeMux(logger *logger.Logger) *serveMux {
|
||||
func newServeMux(logger *log.Logger) *serveMux {
|
||||
mux := &serveMux{
|
||||
lookups: make([]*route, 0),
|
||||
errorHandlers: make(map[int]Handler, 0),
|
||||
|
|
83
iris.go
83
iris.go
|
@ -52,8 +52,19 @@ package iris // import "github.com/kataras/iris"
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"os"
|
||||
"path"
|
||||
"reflect"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/gavv/httpexpect"
|
||||
"github.com/iris-contrib/logger"
|
||||
"github.com/iris-contrib/response/data"
|
||||
"github.com/iris-contrib/response/json"
|
||||
"github.com/iris-contrib/response/jsonp"
|
||||
|
@ -69,21 +80,11 @@ import (
|
|||
"github.com/kataras/iris/context"
|
||||
"github.com/kataras/iris/utils"
|
||||
"github.com/valyala/fasthttp"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"os"
|
||||
"path"
|
||||
"reflect"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
const (
|
||||
// Version of the iris
|
||||
Version = "4.1.6"
|
||||
Version = "4.1.7"
|
||||
|
||||
banner = ` _____ _
|
||||
|_ _| (_)
|
||||
|
@ -97,7 +98,7 @@ const (
|
|||
var (
|
||||
Default *Framework
|
||||
Config *config.Iris
|
||||
Logger *logger.Logger
|
||||
Logger *log.Logger // if you want colors in your console then you should use this https://github.com/iris-contrib/logger instead.
|
||||
Plugins PluginContainer
|
||||
Websocket *WebsocketServer
|
||||
// Look ssh.go for this field's configuration
|
||||
|
@ -169,7 +170,7 @@ type (
|
|||
// Implements the FrameworkAPI
|
||||
Framework struct {
|
||||
*muxAPI
|
||||
contextPool *sync.Pool
|
||||
contextPool sync.Pool
|
||||
Config *config.Iris
|
||||
sessions sessions.Sessions
|
||||
responses *responseEngines
|
||||
|
@ -178,7 +179,7 @@ type (
|
|||
// the last added server is the main server
|
||||
Servers *ServerList
|
||||
// configuration by instance.Logger.Config
|
||||
Logger *logger.Logger
|
||||
Logger *log.Logger
|
||||
Plugins PluginContainer
|
||||
Websocket *WebsocketServer
|
||||
SSH *SSHServer
|
||||
|
@ -200,7 +201,9 @@ func New(cfg ...config.Iris) *Framework {
|
|||
// we always use 's' no 'f' because 's' is easier for me to remember because of 'station'
|
||||
// some things never change :)
|
||||
s := &Framework{
|
||||
Config: &c,
|
||||
Config: &c,
|
||||
// set the Logger
|
||||
Logger: log.New(c.LoggerOut, c.LoggerPreffix, log.LstdFlags),
|
||||
responses: &responseEngines{},
|
||||
Available: make(chan bool),
|
||||
SSH: &SSHServer{},
|
||||
|
@ -208,10 +211,11 @@ func New(cfg ...config.Iris) *Framework {
|
|||
sessions: sessions.New(sessions.Config(c.Sessions)),
|
||||
}
|
||||
{
|
||||
|
||||
s.contextPool.New = func() interface{} {
|
||||
return &Context{framework: s}
|
||||
}
|
||||
///NOTE: set all with s.Config pointer
|
||||
// set the Logger
|
||||
s.Logger = logger.New(logger.DefaultConfig())
|
||||
|
||||
// set the plugin container
|
||||
s.Plugins = newPluginContainer(s.Logger)
|
||||
// set the templates
|
||||
|
@ -219,9 +223,6 @@ func New(cfg ...config.Iris) *Framework {
|
|||
"url": s.URL,
|
||||
"urlpath": s.Path,
|
||||
})
|
||||
s.contextPool = &sync.Pool{New: func() interface{} {
|
||||
return &Context{framework: s}
|
||||
}}
|
||||
// set the websocket server
|
||||
s.Websocket = NewWebsocketServer(s.Config.Websocket)
|
||||
// set the servemux, which will provide us the public API also, with its context pool
|
||||
|
@ -292,29 +293,6 @@ func (s *Framework) initialize() {
|
|||
}
|
||||
}
|
||||
|
||||
/* not used anymore, we had 2% performance reduce
|
||||
func (s *Framework) acquireCtx(reqCtx *fasthttp.RequestCtx) *Context {
|
||||
v := s.contextPool.Get()
|
||||
if v == nil {
|
||||
return &Context{
|
||||
RequestCtx: reqCtx,
|
||||
framework: s,
|
||||
}
|
||||
}
|
||||
ctx := v.(*Context)
|
||||
ctx.Params = ctx.Params[0:0]
|
||||
ctx.RequestCtx = reqCtx
|
||||
ctx.middleware = nil
|
||||
ctx.session = nil
|
||||
return ctx
|
||||
}
|
||||
|
||||
func (s *Framework) releaseCtx(ctx *Context) {
|
||||
s.contextPool.Put(ctx)
|
||||
}
|
||||
// so .New() is better because of internal .Get() pins
|
||||
*/
|
||||
|
||||
// Go starts the iris station, listens to all registered servers, and prepare only if Virtual
|
||||
func Go() error {
|
||||
return Default.Go()
|
||||
|
@ -327,12 +305,14 @@ func (s *Framework) Go() error {
|
|||
// build the fasthttp handler to bind it to the servers
|
||||
h := s.mux.Handler()
|
||||
reqHandler := func(reqCtx *fasthttp.RequestCtx) {
|
||||
ctx := s.contextPool.Get().(*Context)
|
||||
ctx.Params = ctx.Params[0:0]
|
||||
ctx := s.contextPool.Get().(*Context) // Changed to use the pool's New 09/07/2016, ~ -4k nanoseconds(9 bench tests) per requests (better performance)
|
||||
ctx.RequestCtx = reqCtx
|
||||
|
||||
h(ctx)
|
||||
|
||||
ctx.Params = ctx.Params[0:0]
|
||||
ctx.middleware = nil
|
||||
ctx.session = nil
|
||||
h(ctx)
|
||||
s.contextPool.Put(ctx)
|
||||
}
|
||||
if firstErr := s.Servers.OpenAll(reqHandler); firstErr != nil {
|
||||
|
@ -348,9 +328,12 @@ func (s *Framework) Go() error {
|
|||
hosts[i] = srv.Host()
|
||||
}
|
||||
|
||||
bannerMessage := time.Now().Format(config.TimeFormat) + ": Running at " + strings.Join(hosts, ", ")
|
||||
s.Logger.PrintBanner(banner, "\n"+bannerMessage)
|
||||
bannerMessage := fmt.Sprintf("%s: Running at %s", time.Now().Format(config.TimeFormat), strings.Join(hosts, ", "))
|
||||
// we don't print it via Logger because:
|
||||
// 1. The banner is only 'useful' when the developer logs to terminal and no file
|
||||
// 2. Prefix & LstdFlags options of the default s.Logger
|
||||
|
||||
fmt.Printf("%s\n\n%s\n", banner, bannerMessage)
|
||||
}
|
||||
|
||||
s.Plugins.DoPostListen(s)
|
||||
|
|
|
@ -3,9 +3,9 @@ package iris
|
|||
import (
|
||||
"sync"
|
||||
|
||||
"github.com/kataras/go-errors"
|
||||
"log"
|
||||
|
||||
"github.com/iris-contrib/logger"
|
||||
"github.com/kataras/go-errors"
|
||||
"github.com/kataras/go-fs"
|
||||
)
|
||||
|
||||
|
@ -224,12 +224,12 @@ type pluginContainer struct {
|
|||
activatedPlugins []Plugin
|
||||
customEvents map[string][]func()
|
||||
downloader *pluginDownloadManager
|
||||
logger *logger.Logger
|
||||
logger *log.Logger
|
||||
mu sync.Mutex
|
||||
}
|
||||
|
||||
// newPluginContainer receives a logger and returns a new PluginContainer
|
||||
func newPluginContainer(l *logger.Logger) PluginContainer {
|
||||
func newPluginContainer(l *log.Logger) PluginContainer {
|
||||
return &pluginContainer{logger: l}
|
||||
}
|
||||
|
||||
|
|
7
ssh.go
7
ssh.go
|
@ -43,7 +43,8 @@ import (
|
|||
"text/template"
|
||||
"time"
|
||||
|
||||
"github.com/iris-contrib/logger"
|
||||
"log"
|
||||
|
||||
"github.com/kardianos/osext"
|
||||
"github.com/kardianos/service"
|
||||
"github.com/kataras/go-errors"
|
||||
|
@ -423,8 +424,8 @@ type SSHServer struct {
|
|||
Commands Commands // Commands{Command{Name: "restart", Description:"restarts & rebuild the server", Action: func(ssh.Channel){}}}
|
||||
// note for Commands field:
|
||||
// the default Iris's commands are defined at the end of this file, I tried to make this file as standalone as I can, because it will be used for Iris web framework also.
|
||||
Shell bool // Set it to true to enable execute terminal's commands(system commands) via ssh if no other command is found from the Commands field. Defaults to false for security reasons
|
||||
Logger *logger.Logger // log.New(...)/ $qinstance.Logger, fill it when you want to receive debug and info/warnings messages
|
||||
Shell bool // Set it to true to enable execute terminal's commands(system commands) via ssh if no other command is found from the Commands field. Defaults to false for security reasons
|
||||
Logger *log.Logger // log.New(...)/ $qinstance.Logger, fill it when you want to receive debug and info/warnings messages
|
||||
}
|
||||
|
||||
// Enabled returns true if SSH can be started, if Host != ""
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
package iris
|
||||
|
||||
import (
|
||||
"github.com/iris-contrib/logger"
|
||||
"log"
|
||||
|
||||
irisWebsocket "github.com/iris-contrib/websocket"
|
||||
"github.com/kataras/go-websocket"
|
||||
"github.com/kataras/iris/config"
|
||||
|
@ -38,7 +39,7 @@ func NewWebsocketServer(c *config.Websocket) *WebsocketServer {
|
|||
|
||||
// RegisterWebsocketServer registers the handlers for the websocket server
|
||||
// it's a bridge between station and websocket server
|
||||
func RegisterWebsocketServer(station FrameworkAPI, server *WebsocketServer, logger *logger.Logger) {
|
||||
func RegisterWebsocketServer(station FrameworkAPI, server *WebsocketServer, logger *log.Logger) {
|
||||
c := server.Config
|
||||
if c.Endpoint == "" {
|
||||
return
|
||||
|
|
Loading…
Reference in New Issue
Block a user