You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
58 lines
1.6 KiB
58 lines
1.6 KiB
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
|
|
"git.kapschcs.at/bpredota/golang-api-skeleton/lib/cmd"
|
|
log "github.com/sirupsen/logrus"
|
|
"github.com/spf13/viper"
|
|
)
|
|
|
|
var (
|
|
Version string // allows to set version on build
|
|
APPName string // allows to overwrite app name on build
|
|
APPDescription string // allows to overwrite app description on build
|
|
)
|
|
|
|
func main() {
|
|
log.SetFormatter(&log.JSONFormatter{})
|
|
log.SetOutput(os.Stdout)
|
|
hostname, err := os.Hostname()
|
|
if err != nil {
|
|
hostname = "unknown"
|
|
}
|
|
contextLogger := log.WithFields(log.Fields{
|
|
"host": hostname,
|
|
"version": Version,
|
|
"app": APPName,
|
|
})
|
|
// config priority: flags > env > config file
|
|
// cobra sets env if flag is given so that viper can pick it up
|
|
if err := cmd.Initialize(Version, APPName, APPDescription); err != nil {
|
|
contextLogger.WithFields(log.Fields{
|
|
"module": "config",
|
|
}).Fatal(err)
|
|
}
|
|
|
|
// db, _ := gorm.Open(sqlite.Open("gorm.db"), &gorm.Config{})
|
|
// db.AutoMigrate(&user.User{})
|
|
// userRepo := user.NewRepository(db)
|
|
// userService := user.NewService(userRepo)
|
|
// user1 := &user.User{
|
|
// Username: "jdoe",
|
|
// Firstname: "Joe",
|
|
// Lastname: "Doe",
|
|
// Email: "jdoe@acme.inc",
|
|
// }
|
|
// result, err := userService.Create(user1)
|
|
// if err != nil {
|
|
// panic(err)
|
|
// }
|
|
// fmt.Println(result)
|
|
|
|
fmt.Println("main.go --> Environment:", viper.GetString("application.environment"))
|
|
fmt.Println("main.go --> Listen:", viper.GetString("application.listenaddress"))
|
|
fmt.Println("main.go --> Database Port: ", viper.GetInt("database.port"))
|
|
fmt.Println("main.go --> Application Port:", viper.GetInt("application.port"))
|
|
}
|