diff --git a/config.go b/config.go new file mode 100644 index 0000000..49c00b8 --- /dev/null +++ b/config.go @@ -0,0 +1,30 @@ +package main + +import ( + "encoding/json" + "io/ioutil" + "os" +) + +type Config struct { + Secret string + BindHost string + BindPort string +} + +func getConfig() Config { + f, err := os.Open("config.json") + if err != nil { + panic(err) + } + + defer f.Close() + out := Config{} + data, err := ioutil.ReadAll(f) + if err != nil { + panic(err) + } + + json.Unmarshal(data, &out) + return out +} diff --git a/config.json.example b/config.json.example new file mode 100644 index 0000000..ced6099 --- /dev/null +++ b/config.json.example @@ -0,0 +1,5 @@ +{ + "secret": "superSecretSecretIsSecret", + "bind_host": "127.0.0.1", + "bind_port": "5000" +} diff --git a/main.go b/main.go index 0c10f4d..68db2f1 100644 --- a/main.go +++ b/main.go @@ -1,5 +1,6 @@ package main func main() { - ListenForWebhook() + config := getConfig() + ListenForWebHook(config) } diff --git a/webhooks.go b/webhooks.go index 46c0e66..ee28148 100644 --- a/webhooks.go +++ b/webhooks.go @@ -81,7 +81,7 @@ type Person struct { Username string `json:"username"` } -func ListenForWebhook() { +func ListenForWebHook(config Config) { http.HandleFunc( "/", func(writer http.ResponseWriter, request *http.Request) { data, err := ioutil.ReadAll(request.Body) @@ -97,7 +97,9 @@ func ListenForWebhook() { request.Body.Close() }, ) - err := http.ListenAndServe("0.0.0.0:5000", nil) + + err := http.ListenAndServe(config.BindHost + ":" + config.BindPort, nil) + if err != nil { fmt.Println(err) }