From f1eb4962060267458883f86bb5f4093b9b1afc47 Mon Sep 17 00:00:00 2001 From: Silvan Jegen Date: Sat, 18 Feb 2017 08:22:36 +0100 Subject: Sanitize port and prefix --- input/http/http.go | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) (limited to 'input/http/http.go') diff --git a/input/http/http.go b/input/http/http.go index fcac066..87ec0f9 100644 --- a/input/http/http.go +++ b/input/http/http.go @@ -4,6 +4,8 @@ import ( "fmt" "io/ioutil" "net/http" + "os" + "strings" "github.com/Shugyousha/stasher/input" "github.com/Shugyousha/stasher/registry" @@ -23,14 +25,22 @@ type HTTPInput struct { func New(conf map[string]string) input.Input { prefix := conf["prefix"] if prefix == "" { - fmt.Printf("Need a prefix when setting up http input\n") - return nil + fmt.Fprintf(os.Stderr, "Need a prefix when setting up http input. Exiting.\n") + os.Exit(1) } + prefix = strings.Replace(prefix, "\"", "", -1) + port := conf["port"] if port == "" { - fmt.Printf("Need a port number when setting up http input\n") - return nil + fmt.Fprintf(os.Stderr, "Need a port number when setting up http input. Exiting.\n") + os.Exit(1) + } + port = strings.Replace(port, "\"", "", -1) + + if port[0] != ':' { + port = ":" + port } + return &HTTPInput{prefix: prefix, port: port} } -- cgit v1.2.1-18-gbd029