Better config handling with constants (#83)
This commit is contained in:
@ -18,11 +18,10 @@ package models
|
||||
|
||||
import (
|
||||
"code.vikunja.io/api/pkg/config"
|
||||
"github.com/spf13/viper"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
config.InitConfig()
|
||||
MainTest(m, viper.GetString("service.rootpath"))
|
||||
MainTest(m, config.ServiceRootpath.GetString())
|
||||
}
|
||||
|
@ -17,6 +17,7 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"code.vikunja.io/api/pkg/config"
|
||||
"code.vikunja.io/api/pkg/db"
|
||||
"code.vikunja.io/api/pkg/log"
|
||||
"encoding/gob"
|
||||
@ -24,7 +25,6 @@ import (
|
||||
"github.com/go-xorm/xorm"
|
||||
xrc "github.com/go-xorm/xorm-redis-cache"
|
||||
_ "github.com/mattn/go-sqlite3" // Because.
|
||||
"github.com/spf13/viper"
|
||||
)
|
||||
|
||||
var (
|
||||
@ -61,13 +61,13 @@ func SetEngine() (err error) {
|
||||
|
||||
// Cache
|
||||
// We have to initialize the cache here to avoid import cycles
|
||||
if viper.GetBool("cache.enabled") {
|
||||
switch viper.GetString("cache.type") {
|
||||
if config.CacheEnabled.GetBool() {
|
||||
switch config.CacheType.GetString() {
|
||||
case "memory":
|
||||
cacher := xorm.NewLRUCacher(xorm.NewMemoryStore(), viper.GetInt("cache.maxelementsize"))
|
||||
cacher := xorm.NewLRUCacher(xorm.NewMemoryStore(), config.CacheMaxElementSize.GetInt())
|
||||
x.SetDefaultCacher(cacher)
|
||||
case "redis":
|
||||
cacher := xrc.NewRedisCacher(viper.GetString("redis.host"), viper.GetString("redis.password"), xrc.DEFAULT_EXPIRATION, x.Logger())
|
||||
cacher := xrc.NewRedisCacher(config.RedisEnabled.GetString(), config.RedisPassword.GetString(), xrc.DEFAULT_EXPIRATION, x.Logger())
|
||||
x.SetDefaultCacher(cacher)
|
||||
gob.Register(GetTables())
|
||||
default:
|
||||
@ -85,7 +85,7 @@ func getLimitFromPageIndex(page int) (limit, start int) {
|
||||
return 0, 0
|
||||
}
|
||||
|
||||
limit = viper.GetInt("service.pagecount")
|
||||
limit = config.ServicePageCount.GetInt()
|
||||
start = limit * (page - 1)
|
||||
return
|
||||
}
|
||||
|
@ -24,7 +24,6 @@ import (
|
||||
"fmt"
|
||||
"github.com/go-xorm/core"
|
||||
"github.com/go-xorm/xorm"
|
||||
"github.com/spf13/viper"
|
||||
"gopkg.in/testfixtures.v2"
|
||||
"os"
|
||||
"path/filepath"
|
||||
@ -71,7 +70,7 @@ func createTestEngine(fixturesDir string) error {
|
||||
return err
|
||||
}
|
||||
|
||||
if viper.GetString("database.type") == "mysql" {
|
||||
if config.DatabaseType.GetString() == "mysql" {
|
||||
fixturesHelper = &testfixtures.MySQL{}
|
||||
}
|
||||
} else {
|
||||
|
@ -17,10 +17,10 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"code.vikunja.io/api/pkg/config"
|
||||
"code.vikunja.io/api/pkg/mail"
|
||||
"code.vikunja.io/api/pkg/metrics"
|
||||
"code.vikunja.io/api/pkg/utils"
|
||||
"github.com/spf13/viper"
|
||||
"golang.org/x/crypto/bcrypt"
|
||||
)
|
||||
|
||||
@ -69,7 +69,7 @@ func CreateUser(user User) (newUser User, err error) {
|
||||
}
|
||||
|
||||
newUser.IsActive = true
|
||||
if viper.GetBool("mailer.enabled") {
|
||||
if config.MailerEnabled.GetBool() {
|
||||
// The new user should not be activated until it confirms his mail address
|
||||
newUser.IsActive = false
|
||||
// Generate a confirm token
|
||||
@ -99,7 +99,7 @@ func CreateUser(user User) (newUser User, err error) {
|
||||
}
|
||||
|
||||
// Dont send a mail if we're testing
|
||||
if !viper.GetBool("mailer.enabled") {
|
||||
if !config.MailerEnabled.GetBool() {
|
||||
return newUserOut, err
|
||||
}
|
||||
|
||||
|
@ -17,9 +17,9 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"code.vikunja.io/api/pkg/config"
|
||||
"code.vikunja.io/api/pkg/mail"
|
||||
"code.vikunja.io/api/pkg/utils"
|
||||
"github.com/spf13/viper"
|
||||
)
|
||||
|
||||
// PasswordReset holds the data to reset a password
|
||||
@ -62,7 +62,7 @@ func UserPasswordReset(reset *PasswordReset) (err error) {
|
||||
}
|
||||
|
||||
// Dont send a mail if we're testing
|
||||
if !viper.GetBool("mailer.enabled") {
|
||||
if !config.MailerEnabled.GetBool() {
|
||||
return
|
||||
}
|
||||
|
||||
@ -103,7 +103,7 @@ func RequestUserPasswordResetToken(tr *PasswordTokenRequest) (err error) {
|
||||
}
|
||||
|
||||
// Dont send a mail if we're testing
|
||||
if !viper.GetBool("mailer.enabled") {
|
||||
if !config.MailerEnabled.GetBool() {
|
||||
return
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user