mirror of
https://github.com/pushbits/server.git
synced 2025-06-06 20:51:59 +02:00
Restructure project layout
This commit is contained in:
parent
a49db216d5
commit
9a4a096526
32 changed files with 35 additions and 35 deletions
66
internal/configuration/configuration.go
Normal file
66
internal/configuration/configuration.go
Normal file
|
@ -0,0 +1,66 @@
|
|||
package configuration
|
||||
|
||||
import (
|
||||
"github.com/jinzhu/configor"
|
||||
)
|
||||
|
||||
// Argon2Config holds the parameters used for creating hashes with Argon2.
|
||||
type Argon2Config struct {
|
||||
Memory uint32 `default:"131072"`
|
||||
Iterations uint32 `default:"4"`
|
||||
Parallelism uint8 `default:"4"`
|
||||
SaltLength uint32 `default:"16"`
|
||||
KeyLength uint32 `default:"32"`
|
||||
}
|
||||
|
||||
// CryptoConfig holds the parameters used for creating hashes.
|
||||
type CryptoConfig struct {
|
||||
Argon2 Argon2Config
|
||||
}
|
||||
|
||||
// Configuration holds values that can be configured by the user.
|
||||
type Configuration struct {
|
||||
Debug bool `default:"false"`
|
||||
HTTP struct {
|
||||
ListenAddress string `default:""`
|
||||
Port int `default:"8080"`
|
||||
}
|
||||
Database struct {
|
||||
Dialect string `default:"sqlite3"`
|
||||
Connection string `default:"pushbits.db"`
|
||||
}
|
||||
Admin struct {
|
||||
Name string `default:"admin"`
|
||||
Password string `default:"admin"`
|
||||
MatrixID string `required:"true"`
|
||||
}
|
||||
Matrix struct {
|
||||
Homeserver string `default:"https://matrix.org"`
|
||||
Username string `required:"true"`
|
||||
Password string `required:"true"`
|
||||
}
|
||||
Security struct {
|
||||
CheckHIBP bool `default:"false"`
|
||||
}
|
||||
Crypto CryptoConfig
|
||||
}
|
||||
|
||||
func configFiles() []string {
|
||||
return []string{"config.yml"}
|
||||
}
|
||||
|
||||
// Get returns the configuration extracted from env variables or config file.
|
||||
func Get() *Configuration {
|
||||
config := &Configuration{}
|
||||
|
||||
err := configor.New(&configor.Config{
|
||||
Environment: "production",
|
||||
ENVPrefix: "PUSHBITS",
|
||||
ErrorOnUnmatchedKeys: true,
|
||||
}).Load(config, configFiles()...)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
return config
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue