Created CLI flag and stubbed out simple webhook endpoint.

This commit is contained in:
Patrick Connolly
2018-10-29 23:37:42 +08:00
parent 7712eb5687
commit 3d6f6ebe61
2 changed files with 36 additions and 0 deletions

View File

@@ -0,0 +1,28 @@
package webhook
import (
"net/http"
"github.com/labstack/echo"
"github.com/labstack/echo/middleware"
)
func Serve() {
e := echo.New()
e.Use(middleware.Logger())
e.POST("/reload", reloadConfig)
e.Logger.Fatal(e.Start(":1323"))
}
var (
secretToken = "1234567890"
)
func reloadConfig(c echo.Context) error {
providedToken := c.QueryParam("token")
if providedToken != secretToken {
return c.String(http.StatusUnauthorized, "Unauthorized")
}
return c.String(http.StatusAccepted, "Accepted")
}

View File

@@ -8,6 +8,7 @@ import (
"github.com/42wim/matterbridge/bridge/config"
"github.com/42wim/matterbridge/gateway"
"github.com/42wim/matterbridge/gateway/webhook"
"github.com/google/gops/agent"
prefixed "github.com/matterbridge/logrus-prefixed-formatter"
log "github.com/sirupsen/logrus"
@@ -25,6 +26,7 @@ func main() {
flagDebug := flag.Bool("debug", false, "enable debug")
flagVersion := flag.Bool("version", false, "show version")
flagGops := flag.Bool("gops", false, "enable gops agent")
flagWebhook := flag.Bool("webhook", false, "run webhook serve mode")
flag.Parse()
if *flagGops {
agent.Listen(&agent.Options{})
@@ -39,6 +41,12 @@ func main() {
flog.Info("Enabling debug")
log.SetLevel(log.DebugLevel)
}
if *flagWebhook {
fmt.Printf("Starting webhook for reloading remote config...")
fmt.Printf("Serving at: POST /webhook")
webhook.Serve()
return
}
flog.Printf("Running version %s %s", version, githash)
if strings.Contains(version, "-dev") {
flog.Println("WARNING: THIS IS A DEVELOPMENT VERSION. Things may break.")