From c2833391c6df0f4f2250febebf6e7c465edb10cc Mon Sep 17 00:00:00 2001 From: b4b4r07 Date: Wed, 22 Nov 2017 03:24:53 +0900 Subject: [PATCH] Fix bug (all pathes are available) --- config.go | 13 +++++++++---- main.go | 6 +++++- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/config.go b/config.go index f72dcac..f49236f 100644 --- a/config.go +++ b/config.go @@ -4,6 +4,7 @@ import ( "encoding/json" "fmt" "io/ioutil" + neturl "net/url" "os" "os/exec" "path/filepath" @@ -81,13 +82,17 @@ func (cfg *Config) LoadFile(file string) error { return json.NewEncoder(f).Encode(cfg) } -func (cfg *Config) GetEnv(url string) (env Env) { +func (cfg *Config) GetEnv(url string) (env Env, err error) { + u, err := neturl.Parse(url) + if err != nil { + return + } for _, service := range cfg.Services { - if strings.Contains(service.URL, url) { - return service.Env + if strings.Contains(service.URL, u.Host) { + return service.Env, nil } } - return env + return } func (cfg *Config) GetURLs() (list []string) { diff --git a/main.go b/main.go index d34677a..0cfe4de 100644 --- a/main.go +++ b/main.go @@ -65,7 +65,11 @@ func run(args []string) int { return 1 } - env := cfg.GetEnv(args[0]) + env, err := cfg.GetEnv(args[0]) + if err != nil { + fmt.Fprintf(os.Stderr, "Error: %s\n", err.Error()) + return 1 + } if credentials == "" { credentials = env.Credentials }