Skip to content

Commit

Permalink
Merge pull request #61 from HilkopterBob/fix-naming
Browse files Browse the repository at this point in the history
Fix naming
  • Loading branch information
HilkopterBob authored Oct 8, 2024
2 parents ea25449 + 1445407 commit 54ede0b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 14 deletions.
10 changes: 5 additions & 5 deletions config/conf-init.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ func StartViper(config ConfigProvider) ConfigProvider {
if err := config.ReadInConfig(); err != nil {
if _, ok := err.(viper.ConfigFileNotFoundError); ok {
CreateDefaultConfig(config)
new_config := StartViper(config)
newConfig := StartViper(config)
logger.Logger.Info("No Config found, created default Config.")
return new_config
return newConfig
} else {
logger.Logger.Panicf("Cannot create default config, got: %s", err)
}
Expand Down Expand Up @@ -79,8 +79,8 @@ network:
logger.Logger.Panicf("Incompatible Default Config! Got: %s", err)
}

err_write := config.WriteConfigAs("./config.yaml")
if err_write != nil {
logger.Logger.Panicf("Cannot write config file, got: %s", err)
errWrite := config.WriteConfigAs("./config.yaml")
if errWrite != nil {
logger.Logger.Panicf("Cannot write config file, got: %s", errWrite)
}
}
19 changes: 10 additions & 9 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,14 +145,14 @@ func generateAdmin() error {
}

// Insert Admin
AdminInsertionData, err := db.DB.Create("user", TemporalAdmin)
adminInsertionData, err := db.DB.Create("user", TemporalAdmin)
if err != nil {
logger.Logger.Panicf("Got error while inserting Default Admin into DB: %s", err)
}

// Unmarshal data
var createdUser structs.User
err = surrealdb.Unmarshal(AdminInsertionData, &createdUser)
err = surrealdb.Unmarshal(adminInsertionData, &createdUser)
if err != nil {
logger.Logger.Panicf("Got error while querring Default Admin: %s", err)
}
Expand Down Expand Up @@ -201,7 +201,7 @@ func startServer() {
// Start the server in a goroutine
go func() {
for {
router := server.AddRoutes(config.Config)
Router := server.AddRoutes(config.Config)

// Setup server address from config
serverAddr := config.Config.GetString("network.fqdn") + ":" + config.Config.GetString("network.port")
Expand All @@ -213,18 +213,17 @@ func startServer() {
logger.Logger.Infof("Starting Fiber HTTPS server at https://%s...\n", serverAddr)

err := server.ListenAndServeTLS(
router.Router,
Router.Router,
config.Config.GetString("network.ssl-config.certificatepath"),
config.Config.GetString("network.ssl-config.privatekeypath"),
serverAddr)
if err != nil {
logger.Logger.Panicf("Server error: %s\n", err)
}
} else {

logger.Logger.Infof("Starting Fiber server at %s...\n", serverAddr)

if err := router.Router.Listen(serverAddr); err != nil {
if err := Router.Router.Listen(serverAddr); err != nil {
logger.Logger.Panicf("Server error: %s\n", err)
}
}
Expand All @@ -239,14 +238,15 @@ func startServer() {

_, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
if err := router.Router.Shutdown(); err != nil {

if err := Router.Router.Shutdown(); err != nil {
logger.Logger.Warnf("Server shutdown failed: %v\n", err)
} else {

// TODO: add Reason for restart/Stoping
fmt.Println("Server stopped.")
logger.Logger.Info("Server stopped.")
}

startServer()

case <-quitChan:
Expand All @@ -256,7 +256,8 @@ func startServer() {
logger.Logger.Info("Shutting down Fiber server...")
_, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
if err := router.Router.Shutdown(); err != nil {

if err := Router.Router.Shutdown(); err != nil {
logger.Logger.Warnf("Server shutdown failed: %v\n", err)
} else {
fmt.Println("Server stopped gracefully.")
Expand Down

0 comments on commit 54ede0b

Please sign in to comment.