mirror of
https://github.com/kataras/iris.git
synced 2025-01-23 18:51:03 +01:00
Introduce default hostname and default port for any case
This commit is contained in:
parent
2dac93104a
commit
dde7ce31d5
|
@ -2,13 +2,21 @@ package config
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
||||||
|
"strconv"
|
||||||
|
|
||||||
"github.com/imdario/mergo"
|
"github.com/imdario/mergo"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
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
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
// DefaultServerAddr the default server addr which is: 127.0.0.1:8080
|
// DefaultServerAddr the default server addr which is: 127.0.0.1:8080
|
||||||
DefaultServerAddr = "127.0.0.1:8080"
|
DefaultServerAddr = DefaultServerHostname + ":" + strconv.Itoa(DefaultServerPort)
|
||||||
)
|
)
|
||||||
|
|
||||||
// ServerName the response header of the 'Server' value when writes to the client
|
// ServerName the response header of the 'Server' value when writes to the client
|
||||||
|
|
4
http.go
4
http.go
|
@ -303,6 +303,8 @@ func (s *Server) VirtualHostname() (hostname string) {
|
||||||
hostname = s.Config.ListeningAddr
|
hostname = s.Config.ListeningAddr
|
||||||
if idx := strings.IndexByte(hostname, ':'); idx > 1 { // at least after second char
|
if idx := strings.IndexByte(hostname, ':'); idx > 1 { // at least after second char
|
||||||
hostname = hostname[0:idx]
|
hostname = hostname[0:idx]
|
||||||
|
} else {
|
||||||
|
hostname = config.DefaultServerHostname
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -378,7 +380,7 @@ func (s *Server) Open() error {
|
||||||
//check if contains hostname, we need the full host, :8080 should be : 127.0.0.1:8080
|
//check if contains hostname, we need the full host, :8080 should be : 127.0.0.1:8080
|
||||||
if portIdx := strings.IndexByte(a, ':'); portIdx == 0 {
|
if portIdx := strings.IndexByte(a, ':'); portIdx == 0 {
|
||||||
// then the : is the first letter, so we dont have setted a hostname, lets set it
|
// then the : is the first letter, so we dont have setted a hostname, lets set it
|
||||||
s.Config.ListeningAddr = "127.0.0.1" + a
|
s.Config.ListeningAddr = config.DefaultServerHostname + a
|
||||||
}
|
}
|
||||||
|
|
||||||
if s.Config.Mode > 0 {
|
if s.Config.Mode > 0 {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user