update: support ipv6 (#2288)

This commit is contained in:
yuyulei
2021-03-10 20:19:58 +08:00
committed by GitHub
parent b5aee82ca9
commit 8e25f13201
7 changed files with 25 additions and 21 deletions

View File

@@ -15,7 +15,6 @@
package server
import (
"fmt"
"net"
"net/http"
"time"
@@ -32,7 +31,7 @@ var (
httpServerWriteTimeout = 10 * time.Second
)
func (svr *Service) RunDashboardServer(addr string, port int) (err error) {
func (svr *Service) RunDashboardServer(address string) (err error) {
// url router
router := mux.NewRouter()
@@ -58,14 +57,13 @@ func (svr *Service) RunDashboardServer(addr string, port int) (err error) {
http.Redirect(w, r, "/static/", http.StatusMovedPermanently)
})
address := fmt.Sprintf("%s:%d", addr, port)
server := &http.Server{
Addr: address,
Handler: router,
ReadTimeout: httpServerReadTimeout,
WriteTimeout: httpServerWriteTimeout,
}
if address == "" {
if address == "" || address == ":" {
address = ":http"
}
ln, err := net.Listen("tcp", address)