stub handling GET /.../messages
parent
02331752fe
commit
6ca1f83727
20
config.go
20
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) {
|
||||
|
|
|
|||
13
main.go
13
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
|
||||
|
|
|
|||
Loading…
Reference in New Issue