photoprism/internal/server/server.go

31 lines
670 B
Go
Raw Normal View History

package server
import (
"fmt"
2018-09-06 14:47:32 +02:00
"github.com/gin-gonic/gin"
"github.com/photoprism/photoprism/internal/context"
log "github.com/sirupsen/logrus"
)
2018-11-06 19:02:03 +01:00
// Start the REST API server using the configuration provided
func Start(ctx *context.Context) {
if ctx.HttpServerMode() != "" {
gin.SetMode(ctx.HttpServerMode())
} else if ctx.Debug() == false {
gin.SetMode(gin.ReleaseMode)
}
2019-05-02 14:10:05 +02:00
app := gin.New()
app.Use(gin.Logger(), gin.Recovery())
// Set template directory
app.LoadHTMLGlob(ctx.HttpTemplatesPath() + "/*")
registerRoutes(app, ctx)
if err := app.Run(fmt.Sprintf("%s:%d", ctx.HttpServerHost(), ctx.HttpServerPort())); err != nil {
log.Error(err)
}
}