2019-09-07 14:54:53 +00:00
|
|
|
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)
|
2019-09-07 16:10:28 +00:00
|
|
|
|
|
|
|
// App routes
|
2019-09-07 14:54:53 +00:00
|
|
|
api := r.Group("/api")
|
|
|
|
{
|
2019-09-07 16:10:28 +00:00
|
|
|
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)
|
2019-09-07 14:54:53 +00:00
|
|
|
}
|
2019-09-07 16:10:28 +00:00
|
|
|
// 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)
|
|
|
|
}
|
|
|
|
|
2019-09-07 14:54:53 +00:00
|
|
|
r.GET("/health", healthHandler)
|
|
|
|
|
|
|
|
// Add support for PORT env
|
2019-09-07 16:10:28 +00:00
|
|
|
port := "8090"
|
2019-09-07 14:54:53 +00:00
|
|
|
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.")
|
|
|
|
}
|