1
0
зеркало из https://git.ferricyanide.solutions/A_D/irc-webhooks.git synced 2026-03-18 17:07:21 +01:00
Этот коммит содержится в:
A_D
2018-11-16 21:31:45 +02:00
родитель 3138ae1fbe
Коммит 99afed6a1c
4 изменённых файлов: 41 добавлений и 3 удалений

30
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
}

5
config.json.example Обычный файл
Просмотреть файл

@@ -0,0 +1,5 @@
{
"secret": "superSecretSecretIsSecret",
"bind_host": "127.0.0.1",
"bind_port": "5000"
}

Просмотреть файл

@@ -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)
}