-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
89 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package config | ||
|
||
import ( | ||
"vibrain/internal/pkg/logger" | ||
|
||
"github.com/caarlos0/env/v11" | ||
) | ||
|
||
var Settings = &Config{} | ||
|
||
// type DatabaseConfig struct { | ||
// Driver string `json:"driver"` // postgres, mysql, sqlite3 | ||
// Host string `json:"host"` | ||
// Port int `json:"port"` | ||
// User string `json:"user"` | ||
// Password string `json:"password"` | ||
// Name string `json:"name"` | ||
// } | ||
|
||
// func (d DatabaseConfig) DSN() string { | ||
// switch d.Driver { | ||
// case "postgres": | ||
// return fmt.Sprintf("host=%s port=%d user=%s password=%s dbname=%s sslmode=disable", d.Host, d.Port, d.User, d.Password, d.Name) | ||
// case "mysql": | ||
// return fmt.Sprintf("%s:%s@tcp(%s:%d)/%s", d.User, d.Password, d.Host, d.Port, d.Name) | ||
// case "sqlite3": | ||
// return d.Name | ||
// } | ||
// return "" | ||
// } | ||
|
||
type Config struct { | ||
Debug bool `env:"DEBUG" envDefault:"false"` | ||
Port int `env:"PORT" envDefault:"1323"` | ||
DatabaseURL string `env:"DATABASE_URL,required"` | ||
QueueDatabaseURL string `env:"QUEUE_DATABASE_URL,expand" envDefault:"${DATABASE_URL}"` | ||
} | ||
|
||
func init() { | ||
if err := env.Parse(Settings); err != nil { | ||
logger.Default.Fatal("failed to load settings", "err", err) | ||
} | ||
logger.Default.Info("settings loaded") | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package constant | ||
|
||
type ContextKey string | ||
|
||
const ( | ||
ContextKeyRequestID = "request_id" | ||
ContextKeyLogger = "logger" | ||
ContextKeyUserID = "user_id" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters