mirror of
https://github.com/pushbits/server.git
synced 2025-05-10 15:37:00 +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()
|
c := configuration.Get()
|
||||||
|
|
||||||
|
if c.Debug {
|
||||||
|
log.Printf("%+v\n", c)
|
||||||
|
}
|
||||||
|
|
||||||
cm := credentials.CreateManager(c.Crypto)
|
cm := credentials.CreateManager(c.Crypto)
|
||||||
|
|
||||||
db, err := database.Create(cm, c.Database.Dialect, c.Database.Connection)
|
db, err := database.Create(cm, c.Database.Dialect, c.Database.Connection)
|
||||||
|
@ -51,6 +55,7 @@ func main() {
|
||||||
|
|
||||||
setupCleanup(db, dp)
|
setupCleanup(db, dp)
|
||||||
|
|
||||||
engine := router.Create(db, dp)
|
engine := router.Create(c.Debug, db, dp)
|
||||||
runner.Run(engine)
|
|
||||||
|
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.
|
// Configuration holds values that can be configured by the user.
|
||||||
type Configuration struct {
|
type Configuration struct {
|
||||||
|
Debug bool `default:"false"`
|
||||||
|
HTTP struct {
|
||||||
|
ListenAddress string `default:""`
|
||||||
|
Port int `default:"8080"`
|
||||||
|
}
|
||||||
Database struct {
|
Database struct {
|
||||||
Dialect string `default:"sqlite3"`
|
Dialect string `default:"sqlite3"`
|
||||||
Connection string `default:"pushbits.db"`
|
Connection string `default:"pushbits.db"`
|
||||||
|
|
|
@ -13,9 +13,13 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
// Create a Gin engine and setup all routes.
|
// 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.")
|
log.Println("Setting up HTTP routes.")
|
||||||
|
|
||||||
|
if !debug {
|
||||||
|
gin.SetMode(gin.ReleaseMode)
|
||||||
|
}
|
||||||
|
|
||||||
auth := authentication.Authenticator{DB: db}
|
auth := authentication.Authenticator{DB: db}
|
||||||
|
|
||||||
applicationHandler := api.ApplicationHandler{DB: db, Dispatcher: dp}
|
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}
|
userHandler := api.UserHandler{DB: db, Dispatcher: dp}
|
||||||
|
|
||||||
r := gin.Default()
|
r := gin.Default()
|
||||||
|
|
||||||
r.Use(location.Default())
|
r.Use(location.Default())
|
||||||
|
|
||||||
applicationGroup := r.Group("/application")
|
applicationGroup := r.Group("/application")
|
||||||
|
|
|
@ -1,10 +1,12 @@
|
||||||
package runner
|
package runner
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Run starts the Gin engine.
|
// Run starts the Gin engine.
|
||||||
func Run(engine *gin.Engine) {
|
func Run(engine *gin.Engine, address string, port int) {
|
||||||
engine.Run(":8080")
|
engine.Run(fmt.Sprintf("%s:%d", address, port))
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue