Added first stub for swagger docs.

This commit is contained in:
Patrick Connolly
2018-11-04 21:13:00 +08:00
parent fc5e3a6728
commit b9d6c06c82
4 changed files with 83 additions and 0 deletions

View File

@@ -11,8 +11,20 @@ import (
"github.com/labstack/echo"
"github.com/labstack/echo/middleware"
"github.com/zfjagann/golang-ring"
"github.com/swaggo/echo-swagger"
_ "github.com/42wim/matterbridge/docs"
)
// @title Matterbridge API
// @version TODO
// @description A read/write API for the Matterbridge chat bridge.
// @license.name Apache 2.0
// @license.url https://github.com/42wim/matterbridge/blob/master/LICENSE
// @host TODO
// @basePath /api
type API struct {
Messages ring.Ring
sync.RWMutex
@@ -41,6 +53,10 @@ func New(cfg *bridge.Config) bridge.Bridger {
return key == b.GetString("Token"), nil
}))
}
e.GET("/swagger/*", echoSwagger.WrapHandler)
e.GET("/swagger", b.handleDocsRedirect)
e.GET("/", b.handleDocsRedirect)
e.GET("/api", b.handleDocsRedirect)
e.GET("/api/health", b.handleHealthcheck)
e.GET("/api/messages", b.handleMessages)
e.GET("/api/stream", b.handleStream)
@@ -82,6 +98,10 @@ func (b *API) handleHealthcheck(c echo.Context) error {
return c.String(http.StatusOK, "OK")
}
func (b *Api) handleDocsRedirect(c echo.Context) error {
return c.Redirect(http.StatusMovedPermanently, "/swagger/index.html")
}
func (b *API) handlePostMessage(c echo.Context) error {
message := config.Message{}
if err := c.Bind(&message); err != nil {