1
0
mirror of https://github.com/kataras/iris.git synced 2026-01-21 02:45:59 +00:00

Add support for more than one listening server to one station, virtual and no virtual

This commit is contained in:
Makis Maropoulos
2016-07-06 20:24:34 +02:00
parent d76b73427b
commit 2cc75817b7
12 changed files with 674 additions and 390 deletions

View File

@@ -1,15 +1,11 @@
package config
import (
"github.com/imdario/mergo"
"github.com/valyala/fasthttp"
)
import "github.com/imdario/mergo"
// Default values for base Iris conf
const (
DefaultDisablePathCorrection = false
DefaultDisablePathEscape = false
DefaultMaxRequestBodySize = fasthttp.DefaultMaxRequestBodySize
)
type (
@@ -54,13 +50,6 @@ type (
// Default is false
DisableBanner bool
// MaxRequestBodySize Maximum request body size.
//
// The server rejects requests with bodies exceeding this limit.
//
// By default request body size is 4MB.
MaxRequestBodySize int64
// 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
@@ -135,13 +124,12 @@ func Default() Iris {
DisablePathCorrection: DefaultDisablePathCorrection,
DisablePathEscape: DefaultDisablePathEscape,
DisableBanner: false,
MaxRequestBodySize: DefaultMaxRequestBodySize,
ProfilePath: "",
Logger: DefaultLogger(),
Sessions: DefaultSessions(),
Render: DefaultRender(),
Websocket: DefaultWebsocket(),
Tester: Tester{Debug: false},
Tester: DefaultTester(),
}
}

View File

@@ -5,13 +5,17 @@ import (
"strconv"
"github.com/imdario/mergo"
"github.com/kataras/fasthttp"
)
// Default values for base Server conf
const (
// DefaultServerHostname returns the default hostname which is 127.0.0.1
DefaultServerHostname = "127.0.0.1"
// DefaultServerPort returns the default port which is 8080
DefaultServerPort = 8080
// DefaultMaxRequestBodySize is 4MB
DefaultMaxRequestBodySize = fasthttp.DefaultMaxRequestBodySize
)
var (
@@ -30,6 +34,12 @@ type Server struct {
KeyFile string
// Mode this is for unix only
Mode os.FileMode
// MaxRequestBodySize Maximum request body size.
//
// The server rejects requests with bodies exceeding this limit.
//
// By default request body size is 4MB.
MaxRequestBodySize int64
// RedirectTo, defaults to empty, set it in order to override the station's handler and redirect all requests to this address which is of form(HOST:PORT or :PORT)
//
// NOTE: the http status is 'StatusMovedPermanently', means one-time-redirect(the browser remembers the new addr and goes to the new address without need to request something from this server
@@ -43,7 +53,8 @@ type Server struct {
// DefaultServer returns the default configs for the server
func DefaultServer() Server {
return Server{ListeningAddr: DefaultServerAddr}
return Server{ListeningAddr: DefaultServerAddr,
MaxRequestBodySize: DefaultMaxRequestBodySize}
}
// Merge merges the default with the given config and returns the result
@@ -59,3 +70,12 @@ func (c Server) Merge(cfg []Server) (config Server) {
return
}
// MergeSingle merges the default with the given config and returns the result
func (c Server) MergeSingle(cfg Server) (config Server) {
config = cfg
mergo.Merge(&config, c)
return
}

View File

@@ -2,5 +2,12 @@ package config
// Tester configuration
type Tester struct {
Debug bool
Debug bool
ListeningAddr string
}
// DefaultTester returns the default configuration for a tester
// the ListeningAddr is used as virtual only when no running server is founded
func DefaultTester() Tester {
return Tester{Debug: false, ListeningAddr: "iris-go.com:1993"}
}