config for scheme and subrouter
This commit is contained in:
@@ -268,11 +268,21 @@ func NewRouter() *mux.Router {
|
|||||||
r.Use(midware.ArrowIPAddr)
|
r.Use(midware.ArrowIPAddr)
|
||||||
|
|
||||||
for _, router := range routers {
|
for _, router := range routers {
|
||||||
r.Methods(router.Method).
|
// r.Methods(router.Method).
|
||||||
Path(router.Pattern).
|
// Path(router.Pattern).
|
||||||
Handler(router.Handler)
|
// Handler(router.Handler)
|
||||||
|
// if router.Middleware != nil {
|
||||||
|
// r.Use(router.Middleware)
|
||||||
|
// }
|
||||||
|
// if router.Middleware != nil {
|
||||||
|
// r.HandleFunc(router.Pattern, router.Handler).Methods(router.Method).Subrouter().Use(router.Middleware)
|
||||||
|
// } else {
|
||||||
|
// r.HandleFunc(router.Pattern, router.Handler).Methods(router.Method)
|
||||||
|
// }
|
||||||
|
rt := r.Methods(router.Method).Subrouter()
|
||||||
|
rt.HandleFunc(router.Pattern, router.Handler)
|
||||||
if router.Middleware != nil {
|
if router.Middleware != nil {
|
||||||
r.Use(router.Middleware)
|
rt.Use(router.Middleware)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ type YamlConfig struct {
|
|||||||
IPv4 string `yaml:"ipv4"`
|
IPv4 string `yaml:"ipv4"`
|
||||||
IPv6 string `yaml:"ipv6"`
|
IPv6 string `yaml:"ipv6"`
|
||||||
Port uint16 `yaml:"port"`
|
Port uint16 `yaml:"port"`
|
||||||
Schema string `yaml:"schema"`
|
Scheme string `yaml:"scheme"`
|
||||||
CaFile string `yaml:"caFile"`
|
CaFile string `yaml:"caFile"`
|
||||||
CertFile string `yaml:"certFile"`
|
CertFile string `yaml:"certFile"`
|
||||||
KeyFile string `yaml:"keyFile"`
|
KeyFile string `yaml:"keyFile"`
|
||||||
@@ -46,7 +46,7 @@ type YamlConfig struct {
|
|||||||
RootDir string `yaml:"rootDir"`
|
RootDir string `yaml:"rootDir"`
|
||||||
Listen []struct {
|
Listen []struct {
|
||||||
Addr string `yaml:"addr"`
|
Addr string `yaml:"addr"`
|
||||||
Schema string `yaml:"schema"`
|
Scheme string `yaml:"scheme"`
|
||||||
CaFile string `yaml:"caFile"`
|
CaFile string `yaml:"caFile"`
|
||||||
CertFile string `yaml:"certFile"`
|
CertFile string `yaml:"certFile"`
|
||||||
KeyFile string `yaml:"keyFile"`
|
KeyFile string `yaml:"keyFile"`
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ rest:
|
|||||||
- ipv4: 0.0.0.0
|
- ipv4: 0.0.0.0
|
||||||
ipv6:
|
ipv6:
|
||||||
port: 4443
|
port: 4443
|
||||||
schema: https
|
scheme: https
|
||||||
caFile: ./etc/certs/rootca.crt
|
caFile: ./etc/certs/rootca.crt
|
||||||
certFile: ./etc/certs/tsa-omc.crt
|
certFile: ./etc/certs/tsa-omc.crt
|
||||||
keyFile: ./etc/certs/tsa-omc_pri.key
|
keyFile: ./etc/certs/tsa-omc_pri.key
|
||||||
@@ -29,7 +29,7 @@ webServer:
|
|||||||
- addr: :8080
|
- addr: :8080
|
||||||
schema: http
|
schema: http
|
||||||
- addr: :8443
|
- addr: :8443
|
||||||
schema: https
|
scheme: https
|
||||||
caFile: ./etc/certs/rootca.crt
|
caFile: ./etc/certs/rootca.crt
|
||||||
certFile: ./etc/certs/tsa-omc.crt
|
certFile: ./etc/certs/tsa-omc.crt
|
||||||
keyFile: ./etc/certs/tsa-omc_pri.key
|
keyFile: ./etc/certs/tsa-omc_pri.key
|
||||||
|
|||||||
@@ -173,7 +173,7 @@ func main() {
|
|||||||
// ipv4 goroutines
|
// ipv4 goroutines
|
||||||
if rest.IPv4 != "" {
|
if rest.IPv4 != "" {
|
||||||
listen := rest.IPv4 + ":" + strconv.Itoa(int(rest.Port))
|
listen := rest.IPv4 + ":" + strconv.Itoa(int(rest.Port))
|
||||||
if strings.ToLower(rest.Schema) == "https" {
|
if strings.ToLower(rest.Scheme) == "https" {
|
||||||
go HttpListenTLS(listen, rest.CertFile, rest.KeyFile, router)
|
go HttpListenTLS(listen, rest.CertFile, rest.KeyFile, router)
|
||||||
} else {
|
} else {
|
||||||
go HttpListen(listen, router)
|
go HttpListen(listen, router)
|
||||||
@@ -183,7 +183,7 @@ func main() {
|
|||||||
// ipv6 goroutines
|
// ipv6 goroutines
|
||||||
if rest.IPv6 != "" {
|
if rest.IPv6 != "" {
|
||||||
listenv6 := "[" + rest.IPv6 + "]" + ":" + strconv.Itoa(int(rest.Port))
|
listenv6 := "[" + rest.IPv6 + "]" + ":" + strconv.Itoa(int(rest.Port))
|
||||||
if strings.ToLower(rest.Schema) == "https" {
|
if strings.ToLower(rest.Scheme) == "https" {
|
||||||
go HttpListenTLS(listenv6, rest.CertFile, rest.KeyFile, router)
|
go HttpListenTLS(listenv6, rest.CertFile, rest.KeyFile, router)
|
||||||
} else {
|
} else {
|
||||||
go HttpListen(listenv6, router)
|
go HttpListen(listenv6, router)
|
||||||
@@ -195,7 +195,7 @@ func main() {
|
|||||||
fs := http.FileServer(http.Dir(conf.WebServer.RootDir))
|
fs := http.FileServer(http.Dir(conf.WebServer.RootDir))
|
||||||
http.Handle("/", fs)
|
http.Handle("/", fs)
|
||||||
for _, listen := range conf.WebServer.Listen {
|
for _, listen := range conf.WebServer.Listen {
|
||||||
if strings.ToLower(listen.Schema) == "https" {
|
if strings.ToLower(listen.Scheme) == "https" {
|
||||||
go HttpListenWebServerTLS(listen.Addr, listen.CertFile, listen.KeyFile)
|
go HttpListenWebServerTLS(listen.Addr, listen.CertFile, listen.KeyFile)
|
||||||
} else {
|
} else {
|
||||||
go HttpListenWebServer(listen.Addr)
|
go HttpListenWebServer(listen.Addr)
|
||||||
|
|||||||
Reference in New Issue
Block a user