-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
54 lines (39 loc) · 981 Bytes
/
config.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package config
import (
"fmt"
"net/url"
"path/filepath"
"github.com/alecthomas/kong"
"github.com/rs/zerolog"
)
type LogFormat string
const (
FormatJson LogFormat = "json"
FormatText LogFormat = "text"
)
type Config struct {
PublicURL *url.URL `env:"PUBLIC_URL" required:"" help:"The public URL where the Oxidrive UI and API are exposed"`
LogLevel zerolog.Level `env:"LOG_LEVEL" default:"info"`
LogFormat LogFormat `env:"LOG_FORMAT" default:"json"`
Host string `env:"HOST" default:"127.0.0.1"`
Port int16 `env:"PORT" default:"4000"`
AssetsFolder string `env:"OXIDRIVE_ASSETS_FOLDER" default:"./assets"`
AuthConfig
DatabaseConfig
StorageConfig
}
func Parse() Config {
cfg := Config{}
_ = kong.Parse(&cfg)
return cfg
}
func (c *Config) ListenAddress() string {
return fmt.Sprintf("%s:%d", c.Host, c.Port)
}
func (c *Config) AssetsFolderPath() string {
path, err := filepath.Abs(c.AssetsFolder)
if err != nil {
panic(err)
}
return path
}