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

@ -19,6 +19,8 @@ type Config struct {
SlackToken string SlackToken string
SlackChannels string SlackChannels string
PostgresConn string PostgresConn string
BasicAuthUser string
BasicAuthPassword string
storage Storage storage Storage
queue Queue queue Queue
driver Driver driver Driver

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