Init commit, base struct and redis connection
This commit is contained in:
36
cmd/main.go
Normal file
36
cmd/main.go
Normal 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)
|
||||
}
|
||||
Reference in New Issue
Block a user