From 6ca1f83727c0d25ef2d65b3277e9ed43ee86f2a6 Mon Sep 17 00:00:00 2001 From: Bel LaPointe <153096461+breel-render@users.noreply.github.com> Date: Fri, 12 Apr 2024 11:23:30 -0600 Subject: [PATCH] stub handling GET /.../messages --- config.go | 20 +++++++++++--------- main.go | 13 +++++++++++++ 2 files changed, 24 insertions(+), 9 deletions(-) diff --git a/config.go b/config.go index adb518b..6f11611 100644 --- a/config.go +++ b/config.go @@ -13,15 +13,17 @@ import ( ) type Config struct { - Port int - Debug bool - InitializeSlack bool - SlackToken string - SlackChannels string - PostgresConn string - storage Storage - queue Queue - driver Driver + Port int + Debug bool + InitializeSlack bool + SlackToken string + SlackChannels string + PostgresConn string + BasicAuthUser string + BasicAuthPassword string + storage Storage + queue Queue + driver Driver } func newConfig(ctx context.Context) (Config, error) { diff --git a/main.go b/main.go index 48bb7aa..acbc279 100644 --- a/main.go +++ b/main.go @@ -51,6 +51,7 @@ func listenAndServe(ctx context.Context, cfg Config) chan error { errc := make(chan error) go func() { defer close(errc) + log.Printf("listening on %s", s.Addr) errc <- s.ListenAndServe() }() @@ -61,6 +62,7 @@ func newHandler(cfg Config) http.HandlerFunc { mux := http.NewServeMux() mux.Handle("POST /api/v1/events/slack", http.HandlerFunc(newHandlerPostAPIV1EventsSlack(cfg))) + mux.Handle("GET /api/v1/messages", http.HandlerFunc(newHandlerGetAPIV1Message(cfg))) return func(w http.ResponseWriter, r *http.Request) { if cfg.Debug { @@ -73,6 +75,17 @@ func newHandler(cfg Config) http.HandlerFunc { } } +func newHandlerGetAPIV1Message(cfg Config) http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + if u, p, _ := r.BasicAuth(); u != cfg.BasicAuthUser || p != cfg.BasicAuthPassword { + http.Error(w, "shoo", http.StatusForbidden) + return + } + + http.Error(w, "not impl", http.StatusNotImplemented) + } +} + func newHandlerPostAPIV1EventsSlack(cfg Config) http.HandlerFunc { if cfg.InitializeSlack { return handlerPostAPIV1EventsSlackInitialize