stub handling GET /.../messages

main
Bel LaPointe 2024-04-12 11:23:30 -06:00
parent 02331752fe
commit 6ca1f83727
2 changed files with 24 additions and 9 deletions

View File

@ -13,15 +13,17 @@ import (
) )
type Config struct { type Config struct {
Port int Port int
Debug bool Debug bool
InitializeSlack bool InitializeSlack bool
SlackToken string SlackToken string
SlackChannels string SlackChannels string
PostgresConn string PostgresConn string
storage Storage BasicAuthUser string
queue Queue BasicAuthPassword string
driver Driver storage Storage
queue Queue
driver Driver
} }
func newConfig(ctx context.Context) (Config, error) { func newConfig(ctx context.Context) (Config, error) {

13
main.go
View File

@ -51,6 +51,7 @@ func listenAndServe(ctx context.Context, cfg Config) chan error {
errc := make(chan error) errc := make(chan error)
go func() { go func() {
defer close(errc) defer close(errc)
log.Printf("listening on %s", s.Addr)
errc <- s.ListenAndServe() errc <- s.ListenAndServe()
}() }()
@ -61,6 +62,7 @@ func newHandler(cfg Config) http.HandlerFunc {
mux := http.NewServeMux() mux := http.NewServeMux()
mux.Handle("POST /api/v1/events/slack", http.HandlerFunc(newHandlerPostAPIV1EventsSlack(cfg))) 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) { return func(w http.ResponseWriter, r *http.Request) {
if cfg.Debug { 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 { func newHandlerPostAPIV1EventsSlack(cfg Config) http.HandlerFunc {
if cfg.InitializeSlack { if cfg.InitializeSlack {
return handlerPostAPIV1EventsSlackInitialize return handlerPostAPIV1EventsSlackInitialize