mirror of
https://github.com/kataras/iris.git
synced 2026-01-07 12:07:28 +00:00
Publish the new version ✈️ | Look description please!
# FAQ ### Looking for free support? http://support.iris-go.com https://kataras.rocket.chat/channel/iris ### Looking for previous versions? https://github.com/kataras/iris#version ### Should I upgrade my Iris? Developers are not forced to upgrade if they don't really need it. Upgrade whenever you feel ready. > Iris uses the [vendor directory](https://docs.google.com/document/d/1Bz5-UB7g2uPBdOx-rw5t9MxJwkfpx90cqG9AFL0JAYo) feature, so you get truly reproducible builds, as this method guards against upstream renames and deletes. **How to upgrade**: Open your command-line and execute this command: `go get -u github.com/kataras/iris`. For further installation support, please click [here](http://support.iris-go.com/d/16-how-to-install-iris-web-framework). ### About our new home page http://iris-go.com Thanks to [Santosh Anand](https://github.com/santoshanand) the http://iris-go.com has been upgraded and it's really awesome! [Santosh](https://github.com/santoshanand) is a freelancer, he has a great knowledge of nodejs and express js, Android, iOS, React Native, Vue.js etc, if you need a developer to find or create a solution for your problem or task, please contact with him. The amount of the next two or three donations you'll send they will be immediately transferred to his own account balance, so be generous please! Read more at https://github.com/kataras/iris/blob/master/HISTORY.md Former-commit-id: eec2d71bbe011d6b48d2526eb25919e36e5ad94e
This commit is contained in:
@@ -1,21 +0,0 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2016-2017 Gerasimos Maropoulos
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
@@ -1,3 +1,7 @@
|
||||
// Copyright 2017 Gerasimos Maropoulos, ΓΜ. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package logger
|
||||
|
||||
// Config are the options of the logger middlweare
|
||||
@@ -16,6 +20,6 @@ type Config struct {
|
||||
}
|
||||
|
||||
// DefaultConfig returns an options which all properties are true except EnableColors
|
||||
func DefaultConfig() Config {
|
||||
func DefaultConfigurationReadOnly() Config {
|
||||
return Config{true, true, true, true}
|
||||
}
|
||||
|
||||
@@ -1,21 +1,25 @@
|
||||
// Copyright 2017 Gerasimos Maropoulos, ΓΜ. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
// Package loger provides request logging via middleware. See _examples/beginner/request-logger
|
||||
package logger
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"gopkg.in/kataras/iris.v6"
|
||||
"github.com/kataras/iris/context"
|
||||
)
|
||||
|
||||
type loggerMiddleware struct {
|
||||
type requestLoggerMiddleware struct {
|
||||
config Config
|
||||
}
|
||||
|
||||
// Serve serves the middleware
|
||||
func (l *loggerMiddleware) Serve(ctx *iris.Context) {
|
||||
func (l *requestLoggerMiddleware) ServeHTTP(ctx context.Context) {
|
||||
//all except latency to string
|
||||
var date, status, ip, method, path string
|
||||
var status, ip, method, path string
|
||||
var latency time.Duration
|
||||
var startTime, endTime time.Time
|
||||
path = ctx.Path()
|
||||
@@ -26,11 +30,10 @@ func (l *loggerMiddleware) Serve(ctx *iris.Context) {
|
||||
ctx.Next()
|
||||
//no time.Since in order to format it well after
|
||||
endTime = time.Now()
|
||||
date = endTime.Format("01/02 - 15:04:05")
|
||||
latency = endTime.Sub(startTime)
|
||||
|
||||
if l.config.Status {
|
||||
status = strconv.Itoa(ctx.ResponseWriter.StatusCode())
|
||||
status = strconv.Itoa(ctx.GetStatusCode())
|
||||
}
|
||||
|
||||
if l.config.IP {
|
||||
@@ -45,18 +48,21 @@ func (l *loggerMiddleware) Serve(ctx *iris.Context) {
|
||||
path = ""
|
||||
}
|
||||
|
||||
//finally print the logs
|
||||
ctx.Log(iris.DevMode, fmt.Sprintf("%s %v %4v %s %s %s \n", date, status, latency, ip, method, path))
|
||||
//finally print the logs, no new line, the framework's logger is responsible how to render each log.
|
||||
ctx.Application().Log("%v %4v %s %s %s", status, latency, ip, method, path)
|
||||
}
|
||||
|
||||
// New returns the logger middleware
|
||||
// receives optional configs(logger.Config)
|
||||
func New(cfg ...Config) iris.HandlerFunc {
|
||||
c := DefaultConfig()
|
||||
// New creates and returns a new request logger middleware.
|
||||
// Do not confuse it with the framework's Logger.
|
||||
// This is for the http requests.
|
||||
//
|
||||
// Receives an optional configuation.
|
||||
func New(cfg ...Config) context.Handler {
|
||||
c := DefaultConfigurationReadOnly()
|
||||
if len(cfg) > 0 {
|
||||
c = cfg[0]
|
||||
}
|
||||
l := &loggerMiddleware{config: c}
|
||||
l := &requestLoggerMiddleware{config: c}
|
||||
|
||||
return l.Serve
|
||||
return l.ServeHTTP
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user