package flabweb import ( "net/http" "strconv" "github.com/gin-gonic/gin" "sectorinf.com/emilis/flabk/util/uriutil" ) const ( EndpointOutbox = "outbox" ) var ( tempOutboxIDCauseImNotStoringThis = 0 ) type Server struct { router *gin.Engine v1 *gin.RouterGroup hostname string } func New(hostname string) Server { router := gin.Default() v1 := router.Group("v1") server := Server{ hostname: hostname, router: router, v1: v1, } v1.POST(EndpointOutbox, server.Outbox) return server } func (s Server) Run() error { return s.router.Run(":8081") } func (s Server) Outbox(ctx *gin.Context) { id := tempOutboxIDCauseImNotStoringThis tempOutboxIDCauseImNotStoringThis++ ctx.Header("Location", uriutil.JoinURIs(s.hostname, EndpointOutbox, strconv.Itoa(id))) ctx.Status(http.StatusCreated) }