mirror of
https://github.com/dnote/dnote
synced 2026-03-14 14:35:50 +01:00
Remove AppEnv
This commit is contained in:
parent
d57b8eaadb
commit
b6ae8dafa8
8 changed files with 6 additions and 20 deletions
|
|
@ -45,7 +45,6 @@ type App struct {
|
|||
EmailBackend mailer.Backend
|
||||
Files map[string][]byte
|
||||
HTTP500Page []byte
|
||||
AppEnv string
|
||||
WebURL string
|
||||
DisableRegistration bool
|
||||
Port string
|
||||
|
|
|
|||
|
|
@ -29,7 +29,6 @@ func NewTest() App {
|
|||
EmailTemplates: mailer.NewTemplates(),
|
||||
EmailBackend: &testutils.MockEmailbackendImplementation{},
|
||||
HTTP500Page: assets.MustGetHTTP500ErrorPage(),
|
||||
AppEnv: "TEST",
|
||||
WebURL: "http://127.0.0.0.1",
|
||||
Port: "3000",
|
||||
DisableRegistration: false,
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@ func initDB(dbPath string) *gorm.DB {
|
|||
func initApp(cfg config.Config) app.App {
|
||||
db := initDB(cfg.DBPath)
|
||||
|
||||
emailBackend, err := mailer.NewDefaultBackend(cfg.IsProd())
|
||||
emailBackend, err := mailer.NewDefaultBackend()
|
||||
if err != nil {
|
||||
emailBackend = &mailer.DefaultBackend{Enabled: false}
|
||||
} else {
|
||||
|
|
@ -53,7 +53,6 @@ func initApp(cfg config.Config) app.App {
|
|||
EmailTemplates: mailer.NewTemplates(),
|
||||
EmailBackend: emailBackend,
|
||||
HTTP500Page: cfg.HTTP500Page,
|
||||
AppEnv: cfg.AppEnv,
|
||||
WebURL: cfg.WebURL,
|
||||
DisableRegistration: cfg.DisableRegistration,
|
||||
Port: cfg.Port,
|
||||
|
|
|
|||
|
|
@ -32,7 +32,6 @@ import (
|
|||
func startCmd(args []string) {
|
||||
fs := setupFlagSet("start", "dnote-server start")
|
||||
|
||||
appEnv := fs.String("appEnv", "", "Application environment (env: APP_ENV, default: PRODUCTION)")
|
||||
port := fs.String("port", "", "Server port (env: PORT, default: 3001)")
|
||||
webURL := fs.String("webUrl", "", "Full URL to server without trailing slash (env: WebURL, default: http://localhost:3001)")
|
||||
dbPath := fs.String("dbPath", "", "Path to SQLite database file (env: DBPath, default: $XDG_DATA_HOME/dnote/server.db)")
|
||||
|
|
@ -42,7 +41,6 @@ func startCmd(args []string) {
|
|||
fs.Parse(args)
|
||||
|
||||
cfg, err := config.New(config.Params{
|
||||
AppEnv: *appEnv,
|
||||
Port: *port,
|
||||
WebURL: *webURL,
|
||||
DBPath: *dbPath,
|
||||
|
|
|
|||
|
|
@ -26,8 +26,6 @@ import (
|
|||
)
|
||||
|
||||
const (
|
||||
// AppEnvProduction represents an app environment for production.
|
||||
AppEnvProduction string = "PRODUCTION"
|
||||
// DefaultDBDir is the default directory name for Dnote data
|
||||
DefaultDBDir = "dnote"
|
||||
// DefaultDBFilename is the default database filename
|
||||
|
|
@ -65,7 +63,6 @@ func getOrEnv(value, envKey, defaultVal string) string {
|
|||
|
||||
// Config is an application configuration
|
||||
type Config struct {
|
||||
AppEnv string
|
||||
WebURL string
|
||||
DisableRegistration bool
|
||||
Port string
|
||||
|
|
@ -77,7 +74,6 @@ type Config struct {
|
|||
|
||||
// Params are the configuration parameters for creating a new Config
|
||||
type Params struct {
|
||||
AppEnv string
|
||||
Port string
|
||||
WebURL string
|
||||
DBPath string
|
||||
|
|
@ -89,7 +85,6 @@ type Params struct {
|
|||
// Empty string params will fall back to environment variables and defaults.
|
||||
func New(p Params) (Config, error) {
|
||||
c := Config{
|
||||
AppEnv: getOrEnv(p.AppEnv, "APP_ENV", AppEnvProduction),
|
||||
Port: getOrEnv(p.Port, "PORT", "3001"),
|
||||
WebURL: getOrEnv(p.WebURL, "WebURL", "http://localhost:3001"),
|
||||
DBPath: getOrEnv(p.DBPath, "DBPath", DefaultDBPath),
|
||||
|
|
@ -106,11 +101,6 @@ func New(p Params) (Config, error) {
|
|||
return c, nil
|
||||
}
|
||||
|
||||
// IsProd checks if the app environment is configured to be production.
|
||||
func (c Config) IsProd() bool {
|
||||
return c.AppEnv == AppEnvProduction
|
||||
}
|
||||
|
||||
func validate(c Config) error {
|
||||
if _, err := url.ParseRequestURI(c.WebURL); err != nil {
|
||||
return errors.Wrapf(ErrWebURLInvalid, "'%s'", c.WebURL)
|
||||
|
|
|
|||
|
|
@ -36,6 +36,7 @@ var (
|
|||
func getDBLogLevel(level string) logger.LogLevel {
|
||||
switch level {
|
||||
case log.LevelDebug:
|
||||
return logger.Info
|
||||
case log.LevelInfo:
|
||||
return logger.Info
|
||||
case log.LevelWarn:
|
||||
|
|
|
|||
|
|
@ -82,7 +82,7 @@ func getSMTPParams() (*dialerParams, error) {
|
|||
}
|
||||
|
||||
// NewDefaultBackend creates a default backend
|
||||
func NewDefaultBackend(enabled bool) (*DefaultBackend, error) {
|
||||
func NewDefaultBackend() (*DefaultBackend, error) {
|
||||
p, err := getSMTPParams()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
|
@ -92,7 +92,7 @@ func NewDefaultBackend(enabled bool) (*DefaultBackend, error) {
|
|||
|
||||
return &DefaultBackend{
|
||||
Dialer: &gomailDialer{Dialer: d},
|
||||
Enabled: enabled,
|
||||
Enabled: true,
|
||||
}, nil
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -74,7 +74,7 @@ func TestNewDefaultBackend(t *testing.T) {
|
|||
t.Setenv("SmtpUsername", "user@example.com")
|
||||
t.Setenv("SmtpPassword", "secret")
|
||||
|
||||
backend, err := NewDefaultBackend(true)
|
||||
backend, err := NewDefaultBackend()
|
||||
if err != nil {
|
||||
t.Fatalf("NewDefaultBackend failed: %v", err)
|
||||
}
|
||||
|
|
@ -93,7 +93,7 @@ func TestNewDefaultBackend(t *testing.T) {
|
|||
t.Setenv("SmtpUsername", "")
|
||||
t.Setenv("SmtpPassword", "")
|
||||
|
||||
_, err := NewDefaultBackend(true)
|
||||
_, err := NewDefaultBackend()
|
||||
if err == nil {
|
||||
t.Error("expected error when SMTP not configured")
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue