-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
107 lines (70 loc) · 2.64 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
package main
import (
"net/http"
"github.com/go-chi/chi/v5"
"github.com/rs/zerolog"
"github.com/rs/zerolog/log"
database "github.com/aswinbennyofficial/SuSHi/db"
"github.com/aswinbennyofficial/SuSHi/models"
"github.com/aswinbennyofficial/SuSHi/routes"
"github.com/aswinbennyofficial/SuSHi/utils"
)
func main() {
var config models.Config
// Load configuration
config,err := utils.LoadConfig()
if err != nil {
log.Panic().Err(err).Msg("Error in LoadConfig()")
return
}
log.Info().Msg("Configuration loaded successfully")
// Set log level
if config.LogLevel == "Debug" {
zerolog.SetGlobalLevel(zerolog.DebugLevel)
} else {
zerolog.SetGlobalLevel(zerolog.InfoLevel)
}
// Load logger
utils.LoadLogger(config)
// Show config log
showConfigLog(config)
// Connect to the database
config.DB,config.DatabaseConfig.String,err = database.Connect(config)
if err != nil {
log.Fatal().Err(err).Msg("Failed to connect to the database")
return
}
// Do migration
err = database.Migrate(config)
if err != nil {
log.Fatal().Err(err).Msg("Failed to migrate the database")
return
}
// Start goroutine to remove expired ssh connections
go utils.CheckExpiredBuckets()
config.Router = chi.NewRouter()
routes.Load(config)
// Start HTTP server
log.Info().Msgf("Starting server on port %s", config.ServerPort)
err = http.ListenAndServe(":8080", config.Router)
if err != nil {
log.Fatal().Msgf("Failed to start server: %v", err)
}
}
func showConfigLog(config models.Config){
log.Debug().Msgf("ServerPort: %s", config.ServerPort)
log.Debug().Msgf("JWTSecret: %s", config.JWTSecret)
log.Debug().Msgf("LogLevel: %s", config.LogLevel)
log.Debug().Msgf("LogPath: %s", config.LogPath)
log.Debug().Msgf("SSHHost: %s", config.SSHConfig.SSHHost)
log.Debug().Msgf("SSHPort: %s", config.SSHConfig.SSHPort)
log.Debug().Msgf("SSHUser: %s", config.SSHConfig.SSHUser)
log.Debug().Msgf("PrivateKey: %s", config.SSHConfig.PrivateKey)
log.Debug().Msgf("Host: %s", config.DatabaseConfig.Host)
log.Debug().Msgf("Port: %s", config.DatabaseConfig.Port)
log.Debug().Msgf("User: %s", config.DatabaseConfig.User)
log.Debug().Msgf("Password: %s", config.DatabaseConfig.Password)
log.Debug().Msgf("Database: %s", config.DatabaseConfig.Database)
log.Debug().Msgf("Google : cid %s | csecret %s | scope %s | redirecturl %s | state %s", config.OAuthConfig.Google.ClientID,config.OAuthConfig.Google.ClientSecret,config.OAuthConfig.Google.Scopes,config.OAuthConfig.Google.RedirectURL,config.OAuthConfig.Google.State)
log.Debug().Msgf("Github client id : %s", config.OAuthConfig.GitHub.ClientID)
}