mirror of
https://github.com/pushbits/server.git
synced 2025-05-10 07:26:59 +02:00
Add configuration for HTTP and debug mode
This commit is contained in:
parent
ba0306f384
commit
354ce0c08d
4 changed files with 22 additions and 5 deletions
9
app.go
9
app.go
|
@ -31,6 +31,10 @@ func main() {
|
|||
|
||||
c := configuration.Get()
|
||||
|
||||
if c.Debug {
|
||||
log.Printf("%+v\n", c)
|
||||
}
|
||||
|
||||
cm := credentials.CreateManager(c.Crypto)
|
||||
|
||||
db, err := database.Create(cm, c.Database.Dialect, c.Database.Connection)
|
||||
|
@ -51,6 +55,7 @@ func main() {
|
|||
|
||||
setupCleanup(db, dp)
|
||||
|
||||
engine := router.Create(db, dp)
|
||||
runner.Run(engine)
|
||||
engine := router.Create(c.Debug, db, dp)
|
||||
|
||||
runner.Run(engine, c.HTTP.ListenAddress, c.HTTP.Port)
|
||||
}
|
||||
|
|
|
@ -20,6 +20,11 @@ type CryptoConfig struct {
|
|||
|
||||
// Configuration holds values that can be configured by the user.
|
||||
type Configuration struct {
|
||||
Debug bool `default:"false"`
|
||||
HTTP struct {
|
||||
ListenAddress string `default:""`
|
||||
Port int `default:"8080"`
|
||||
}
|
||||
Database struct {
|
||||
Dialect string `default:"sqlite3"`
|
||||
Connection string `default:"pushbits.db"`
|
||||
|
|
|
@ -13,9 +13,13 @@ import (
|
|||
)
|
||||
|
||||
// Create a Gin engine and setup all routes.
|
||||
func Create(db *database.Database, dp *dispatcher.Dispatcher) *gin.Engine {
|
||||
func Create(debug bool, db *database.Database, dp *dispatcher.Dispatcher) *gin.Engine {
|
||||
log.Println("Setting up HTTP routes.")
|
||||
|
||||
if !debug {
|
||||
gin.SetMode(gin.ReleaseMode)
|
||||
}
|
||||
|
||||
auth := authentication.Authenticator{DB: db}
|
||||
|
||||
applicationHandler := api.ApplicationHandler{DB: db, Dispatcher: dp}
|
||||
|
@ -23,6 +27,7 @@ func Create(db *database.Database, dp *dispatcher.Dispatcher) *gin.Engine {
|
|||
userHandler := api.UserHandler{DB: db, Dispatcher: dp}
|
||||
|
||||
r := gin.Default()
|
||||
|
||||
r.Use(location.Default())
|
||||
|
||||
applicationGroup := r.Group("/application")
|
||||
|
|
|
@ -1,10 +1,12 @@
|
|||
package runner
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
// Run starts the Gin engine.
|
||||
func Run(engine *gin.Engine) {
|
||||
engine.Run(":8080")
|
||||
func Run(engine *gin.Engine, address string, port int) {
|
||||
engine.Run(fmt.Sprintf("%s:%d", address, port))
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue