63 lines
1.5 KiB
Go
63 lines
1.5 KiB
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)
|
|
|
|
// App routes
|
|
api := r.Group("/api")
|
|
{
|
|
api.GET("/group/:name", groups.Get)
|
|
api.GET("/group/:name/tags", groups.Get)
|
|
api.GET("/group/:name/tags", groups.Get)
|
|
api.GET("/group/:name/featured", groups.Get)
|
|
api.GET("/group/:name/following", groups.Get)
|
|
api.GET("/group/:name/outbox", groups.Get)
|
|
api.GET("/group/:name/inbox", groups.Create)
|
|
api.POST("/group/:name/inbox", groups.Create)
|
|
api.POST("/group", groups.Create)
|
|
}
|
|
// r.GET("/@:name", groups.GetGroup)
|
|
// r.GET("/note/:noteid", note.GetNote)
|
|
|
|
// Activity pub routes
|
|
ap := r.Group("/activity")
|
|
{
|
|
ap.GET("/group/:name", groups.Get)
|
|
ap.GET("/group/:name/followers", groups.Get)
|
|
ap.GET("/group/:name/following", groups.Get)
|
|
ap.GET("/group/:name/outbox", groups.Get)
|
|
ap.GET("/group/:name/inbox", groups.Create)
|
|
ap.POST("/group/:name/inbox", groups.Create)
|
|
}
|
|
|
|
r.GET("/health", healthHandler)
|
|
|
|
// Add support for PORT env
|
|
port := "8090"
|
|
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.")
|
|
}
|