Init commit, base struct and redis connection

This commit is contained in:
Schrody
2026-01-29 17:55:14 +01:00
parent 58164d4b10
commit 9ae5696aec
10 changed files with 206 additions and 0 deletions

36
cmd/main.go Normal file
View File

@@ -0,0 +1,36 @@
package main
import (
"fmt"
"net/http"
"io"
"context"
"uebucch/manager"
)
func main() {
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "UeBucch!")
})
http.HandleFunc("/webhook", func(w http.ResponseWriter, r *http.Request) {
webHookName := r.URL.Query().Get("name")
redisClient := manager.NewRedisClient()
body, _ := io.ReadAll(r.Body)
res := redisClient.LPush(context.Background(), webHookName, body)
if res.Err() != nil {
fmt.Fprintf(w, "Error: %s", res.Err())
return
}
fmt.Fprintf(w, "Webhook created!")
})
http.HandleFunc("/webhooks", func(w http.ResponseWriter, r *http.Request) {
webHooks, err := manager.GetWebhooks(context.Background(), manager.NewRedisClient())
if err != nil {
fmt.Fprintf(w, "Error: %s", err)
return
}
for _, webHook := range webHooks {
fmt.Fprintf(w, "Webhook: %s", webHook)
}
})
http.ListenAndServe(":8080", nil)
}