summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSilvan Jegen <s.jegen@gmail.com>2017-02-18 08:22:36 +0100
committerSilvan Jegen <s.jegen@gmail.com>2017-02-18 08:22:36 +0100
commitf1eb4962060267458883f86bb5f4093b9b1afc47 (patch)
tree7c00b861fe760a2c94c8cb5313c8f87085f7ac82
parent86ade00db6aa419b6df56fdbe82da9ce33da2314 (diff)
Sanitize port and prefix
-rw-r--r--input/http/http.go18
1 files changed, 14 insertions, 4 deletions
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}
}