diff --git a/tools/component/component.go b/tools/component/component.go index 04c6ba9a5..df5849b51 100644 --- a/tools/component/component.go +++ b/tools/component/component.go @@ -22,7 +22,6 @@ import ( "net" "net/url" "os" - "strings" "time" "github.com/minio/minio-go/v7" @@ -117,16 +116,24 @@ func main() { os.Exit(1) } -func exactIP(urll string) string { - u, _ := url.Parse(urll) - host, _, err := net.SplitHostPort(u.Host) - if err != nil { - host = u.Host - } - if strings.HasSuffix(host, ":") { - host = host[0 : len(host)-1] +func checkMinioIP() error { + for _, i := range []string{config.Config.Object.ApiURL, config.Config.Object.Minio.SignEndpoint} { + u, err := url.Parse(i) + if err != nil { + return utils.Wrap(err, "api format error,please check config file apiURL or Minio SignEndpoint") + } + if u.Scheme == "https" { + continue + } + host, _, err := net.SplitHostPort(u.Host) + if err != nil { + host = u.Host + } + if host == "127.0.0.1" { + return ErrConfig.Wrap("apiURL or Minio SignEndpoint endpoint contain 127.0.0.1,please modify it") + } } - return host + return nil } func checkMysql() error { @@ -205,8 +212,8 @@ func checkMinio() error { return ErrComponentStart.Wrap("Minio server is offline") } } - if exactIP(config.Config.Object.ApiURL) == "127.0.0.1" || exactIP(config.Config.Object.Minio.SignEndpoint) == "127.0.0.1" { - return ErrConfig.Wrap("apiURL or Minio SignEndpoint endpoint contain 127.0.0.1") + if checkMinioIP() != nil { + return checkMinioIP() } } return nil