https
This commit is contained in:
@@ -14,9 +14,12 @@ rest:
|
|||||||
- ipv4: 0.0.0.0
|
- ipv4: 0.0.0.0
|
||||||
ipv6:
|
ipv6:
|
||||||
port: 3030
|
port: 3030
|
||||||
- ipv4:
|
- ipv4: 0.0.0.0
|
||||||
ipv6: ::0
|
ipv6:
|
||||||
port: 6060
|
port: 8443
|
||||||
|
schema: https
|
||||||
|
certFile: /usr/local/omc/etc/certs/tsa-omc.pem
|
||||||
|
keyFile: /usr/local/omc/etc/certs/tsa-omc_pri.pem
|
||||||
|
|
||||||
database:
|
database:
|
||||||
type: mysql
|
type: mysql
|
||||||
|
|||||||
@@ -32,9 +32,12 @@ type YamlConfig struct {
|
|||||||
} `yaml:"logger"`
|
} `yaml:"logger"`
|
||||||
|
|
||||||
Rest []struct {
|
Rest []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"`
|
||||||
|
CertFile string `yaml:"certFile"`
|
||||||
|
KeyFile string `yaml:"keyFile"`
|
||||||
} `yaml:"rest"`
|
} `yaml:"rest"`
|
||||||
|
|
||||||
Database DbConfig `yaml:"database"`
|
Database DbConfig `yaml:"database"`
|
||||||
|
|||||||
@@ -14,9 +14,12 @@ rest:
|
|||||||
- ipv4: 0.0.0.0
|
- ipv4: 0.0.0.0
|
||||||
ipv6:
|
ipv6:
|
||||||
port: 3040
|
port: 3040
|
||||||
- ipv4:
|
- ipv4: 0.0.0.0
|
||||||
ipv6: ::0
|
ipv6:
|
||||||
port: 6070
|
port: 8443
|
||||||
|
schema: https
|
||||||
|
certFile: /usr/local/omc/etc/certs/tsa-omc.pem
|
||||||
|
keyFile: /usr/local/omc/etc/certs/tsa-omc_pri.pem
|
||||||
|
|
||||||
database:
|
database:
|
||||||
type: mysql
|
type: mysql
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"ems.agt/lib/dborm"
|
"ems.agt/lib/dborm"
|
||||||
"ems.agt/lib/global"
|
"ems.agt/lib/global"
|
||||||
@@ -70,6 +71,14 @@ func HttpListen(addr string, router http.Handler) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func HttpListenTLS(addr, certFile, keyFile string, router http.Handler) {
|
||||||
|
err := http.ListenAndServeTLS(addr, certFile, keyFile, router)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println("ListenAndServeTLS err:", err)
|
||||||
|
os.Exit(6)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
conf := config.GetYamlConfig()
|
conf := config.GetYamlConfig()
|
||||||
|
|
||||||
@@ -117,12 +126,21 @@ 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))
|
||||||
go HttpListen(listen, router)
|
if strings.ToLower(rest.Schema) == "https" {
|
||||||
|
go HttpListenTLS(listen, rest.CertFile, rest.KeyFile, router)
|
||||||
|
} else {
|
||||||
|
go HttpListen(listen, router)
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
// 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))
|
||||||
go HttpListen(listenv6, router)
|
if strings.ToLower(rest.Schema) == "https" {
|
||||||
|
go HttpListenTLS(listenv6, rest.CertFile, rest.KeyFile, router)
|
||||||
|
} else {
|
||||||
|
go HttpListen(listenv6, router)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user