mirror of
https://git.ferricyanide.solutions/A_D/irc-webhooks.git
synced 2024-12-22 13:47:03 +00:00
added config
This commit is contained in:
parent
3138ae1fbe
commit
99afed6a1c
30
config.go
Normal file
30
config.go
Normal file
@ -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
|
||||
}
|
5
config.json.example
Normal file
5
config.json.example
Normal file
@ -0,0 +1,5 @@
|
||||
{
|
||||
"secret": "superSecretSecretIsSecret",
|
||||
"bind_host": "127.0.0.1",
|
||||
"bind_port": "5000"
|
||||
}
|
3
main.go
3
main.go
@ -1,5 +1,6 @@
|
||||
package main
|
||||
|
||||
func main() {
|
||||
ListenForWebhook()
|
||||
config := getConfig()
|
||||
ListenForWebHook(config)
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user