1
0
mirror of https://github.com/muety/wakapi.git synced 2023-08-10 21:12:56 +03:00

refactor: move config to separate package

chore: load config from main method
This commit is contained in:
Ferdinand Mütsch
2020-09-29 18:55:07 +02:00
parent 062a9c6f57
commit f843be8d12
20 changed files with 79 additions and 62 deletions

View File

@@ -2,6 +2,7 @@ package v1
import (
"github.com/gorilla/mux"
config2 "github.com/muety/wakapi/config"
"github.com/muety/wakapi/models"
v1 "github.com/muety/wakapi/models/compat/shields/v1"
"github.com/muety/wakapi/services"
@@ -19,14 +20,14 @@ const (
type BadgeHandler struct {
userSrvc *services.UserService
summarySrvc *services.SummaryService
config *models.Config
config *config2.Config
}
func NewBadgeHandler(summaryService *services.SummaryService, userService *services.UserService) *BadgeHandler {
return &BadgeHandler{
summarySrvc: summaryService,
userSrvc: userService,
config: models.GetConfig(),
config: config2.Get(),
}
}

View File

@@ -2,6 +2,7 @@ package v1
import (
"github.com/gorilla/mux"
config2 "github.com/muety/wakapi/config"
"github.com/muety/wakapi/models"
v1 "github.com/muety/wakapi/models/compat/wakatime/v1"
"github.com/muety/wakapi/services"
@@ -13,13 +14,13 @@ import (
type AllTimeHandler struct {
summarySrvc *services.SummaryService
config *models.Config
config *config2.Config
}
func NewAllTimeHandler(summaryService *services.SummaryService) *AllTimeHandler {
return &AllTimeHandler{
summarySrvc: summaryService,
config: models.GetConfig(),
config: config2.Get(),
}
}

View File

@@ -3,6 +3,7 @@ package v1
import (
"errors"
"github.com/gorilla/mux"
config2 "github.com/muety/wakapi/config"
"github.com/muety/wakapi/models"
v1 "github.com/muety/wakapi/models/compat/wakatime/v1"
"github.com/muety/wakapi/services"
@@ -14,13 +15,13 @@ import (
type SummariesHandler struct {
summarySrvc *services.SummaryService
config *models.Config
config *config2.Config
}
func NewSummariesHandler(summaryService *services.SummaryService) *SummariesHandler {
return &SummariesHandler{
summarySrvc: summaryService,
config: models.GetConfig(),
config: config2.Get(),
}
}

View File

@@ -2,6 +2,7 @@ package routes
import (
"encoding/json"
config2 "github.com/muety/wakapi/config"
"net/http"
"os"
@@ -12,13 +13,13 @@ import (
)
type HeartbeatHandler struct {
config *models.Config
config *config2.Config
heartbeatSrvc *services.HeartbeatService
}
func NewHeartbeatHandler(heartbeatService *services.HeartbeatService) *HeartbeatHandler {
return &HeartbeatHandler{
config: models.GetConfig(),
config: config2.Get(),
heartbeatSrvc: heartbeatService,
}
}

View File

@@ -3,6 +3,7 @@ package routes
import (
"fmt"
"github.com/gorilla/schema"
config2 "github.com/muety/wakapi/config"
"github.com/muety/wakapi/middlewares"
"github.com/muety/wakapi/models"
"github.com/muety/wakapi/services"
@@ -13,7 +14,7 @@ import (
)
type IndexHandler struct {
config *models.Config
config *config2.Config
userSrvc *services.UserService
keyValueSrvc *services.KeyValueService
}
@@ -23,7 +24,7 @@ var signupDecoder = schema.NewDecoder()
func NewIndexHandler(userService *services.UserService, keyValueService *services.KeyValueService) *IndexHandler {
return &IndexHandler{
config: models.GetConfig(),
config: config2.Get(),
userSrvc: userService,
keyValueSrvc: keyValueService,
}

View File

@@ -2,7 +2,7 @@ package routes
import (
"fmt"
"github.com/muety/wakapi/models"
"github.com/muety/wakapi/config"
"github.com/muety/wakapi/utils"
"html/template"
"io/ioutil"
@@ -25,10 +25,10 @@ func loadTemplates() {
"title": strings.Title,
"capitalize": utils.Capitalize,
"getBasePath": func() string {
return models.GetConfig().BasePath
return config.Get().BasePath
},
"getVersion": func() string {
return models.GetConfig().Version
return config.Get().Version
},
"htmlSafe": func(html string) template.HTML {
return template.HTML(html)

View File

@@ -3,6 +3,7 @@ package routes
import (
"fmt"
"github.com/gorilla/schema"
config2 "github.com/muety/wakapi/config"
"github.com/muety/wakapi/models"
"github.com/muety/wakapi/services"
"github.com/muety/wakapi/utils"
@@ -11,7 +12,7 @@ import (
)
type SettingsHandler struct {
config *models.Config
config *config2.Config
userSrvc *services.UserService
}
@@ -19,7 +20,7 @@ var credentialsDecoder = schema.NewDecoder()
func NewSettingsHandler(userService *services.UserService) *SettingsHandler {
return &SettingsHandler{
config: models.GetConfig(),
config: config2.Get(),
userSrvc: userService,
}
}

View File

@@ -1,6 +1,7 @@
package routes
import (
config2 "github.com/muety/wakapi/config"
"github.com/muety/wakapi/models"
"github.com/muety/wakapi/services"
"github.com/muety/wakapi/utils"
@@ -9,13 +10,13 @@ import (
type SummaryHandler struct {
summarySrvc *services.SummaryService
config *models.Config
config *config2.Config
}
func NewSummaryHandler(summaryService *services.SummaryService) *SummaryHandler {
return &SummaryHandler{
summarySrvc: summaryService,
config: models.GetConfig(),
config: config2.Get(),
}
}