40 lines
768 B
Go
40 lines
768 B
Go
package main
|
|
|
|
import (
|
|
"git.macaw.me/inhosin/subhub/handlers/groups"
|
|
"git.macaw.me/inhosin/subhub/handlers/webfinder"
|
|
"github.com/gin-gonic/gin"
|
|
log "github.com/sirupsen/logrus"
|
|
"net/http"
|
|
"os"
|
|
)
|
|
|
|
func init() {
|
|
|
|
log.SetOutput(os.Stdout)
|
|
}
|
|
|
|
func main() {
|
|
r := gin.Default()
|
|
r.GET("/.well-known/webfinger", webfinder.Get)
|
|
api := r.Group("/api")
|
|
{
|
|
api.GET("/api/group/:name", groups.Get)
|
|
api.POST("/api/group", groups.Create)
|
|
}
|
|
r.GET("/health", healthHandler)
|
|
|
|
// Add support for PORT env
|
|
port := "8080"
|
|
if fromEnv := os.Getenv("PORT"); fromEnv != "" {
|
|
port = fromEnv
|
|
}
|
|
|
|
log.WithField("port", port).Info("starting pubcast api server")
|
|
log.Fatal(r.Run(":" + port))
|
|
}
|
|
|
|
func healthHandler(c *gin.Context) {
|
|
c.String(http.StatusOK, "I`am alive.")
|
|
}
|