mirror of
https://github.com/Luzifer/nginx-sso.git
synced 2025-04-17 12:41:51 +00:00
refactor according to suggestions
This commit is contained in:
parent
1f05ee38bb
commit
de9bb6e23a
1 changed files with 9 additions and 6 deletions
15
main.go
15
main.go
|
@ -84,17 +84,17 @@ func init() {
|
|||
func loadConfiguration() ([]byte, error) {
|
||||
yamlSource, err := ioutil.ReadFile(cfg.ConfigFile)
|
||||
if err != nil {
|
||||
return []byte(""), fmt.Errorf("Unable to read configuration file: %s", err)
|
||||
return nil, errors.Wrap(err, "Unable to read configuration file")
|
||||
}
|
||||
|
||||
if err = yaml.Unmarshal(yamlSource, &mainCfg); err != nil {
|
||||
return []byte(""), fmt.Errorf("Unable to load configuration file: %s", err)
|
||||
return nil, errors.Wrap(err, "Unable to load configuration file")
|
||||
}
|
||||
|
||||
return yamlSource, nil
|
||||
}
|
||||
|
||||
func loadModules(yamlSource []byte) error {
|
||||
func initializeModules(yamlSource []byte) error {
|
||||
if mainCfg.Plugins.Directory != "" {
|
||||
if err := loadPlugins(mainCfg.Plugins.Directory); err != nil {
|
||||
return errors.Wrap(err, "Unable to load plugins")
|
||||
|
@ -121,8 +121,8 @@ func main() {
|
|||
cookieStore = sessions.NewCookieStore([]byte(mainCfg.Cookie.AuthKey))
|
||||
registerModules()
|
||||
|
||||
if err := loadModules(yamlSource); err != nil {
|
||||
log.WithError(err).Fatal("Unable to load modules")
|
||||
if err = initializeModules(yamlSource); err != nil {
|
||||
log.WithError(err).Fatal("Unable to initialize modules")
|
||||
}
|
||||
|
||||
http.HandleFunc("/", handleRootRequest)
|
||||
|
@ -142,9 +142,12 @@ func main() {
|
|||
for sig := range sigChan {
|
||||
switch sig {
|
||||
case syscall.SIGHUP:
|
||||
if _, err := loadConfiguration(); err != nil {
|
||||
if yamlSource, err = loadConfiguration(); err != nil {
|
||||
log.WithError(err).Error("Unable to reload configuration")
|
||||
}
|
||||
if err = initializeModules(yamlSource); err != nil {
|
||||
log.WithError(err).Fatal("Unable to initialize modules")
|
||||
}
|
||||
|
||||
default:
|
||||
log.Fatalf("Received unexpected signal: %v", sig)
|
||||
|
|
Loading…
Add table
Reference in a new issue