init; project structure & bybit provider
This commit is contained in:
commit
ae096d4820
14 changed files with 482 additions and 0 deletions
45
internal/config/config.go
Normal file
45
internal/config/config.go
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
package config
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/ilyakaznacheev/cleanenv"
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
Logger Logger `yaml:"logger"`
|
||||
Providers struct {
|
||||
Bybit Bybit `yaml:"bybit"`
|
||||
} `yaml:"providers"`
|
||||
}
|
||||
|
||||
type Logger struct {
|
||||
ServiceName string `yaml:"service_name" env-required:"true"` // service name for printing in logs
|
||||
Encoding string `yaml:"encoding" env-default:"json"` // console/json
|
||||
Level string `yaml:"level" env-default:"info"` // debug/info/warn/error
|
||||
}
|
||||
|
||||
type Bybit struct {
|
||||
BaseURL string `yaml:"base_url" env-default:"https://api.bybit.com"` // bybit api url
|
||||
}
|
||||
|
||||
// MustLoad returns config or panic.
|
||||
func MustLoad() *Config {
|
||||
configPath := os.Getenv("CONFIG_PATH")
|
||||
if configPath == "" {
|
||||
panic("CONFIG_PATH is not set")
|
||||
}
|
||||
// check if file exists
|
||||
if _, err := os.Stat(configPath); os.IsNotExist(err) {
|
||||
panic(fmt.Sprintf("config file does not exist: %s", configPath))
|
||||
}
|
||||
|
||||
var cfg Config
|
||||
// read config
|
||||
if err := cleanenv.ReadConfig(configPath, &cfg); err != nil {
|
||||
panic(fmt.Errorf("cannot read config: %w", err))
|
||||
}
|
||||
|
||||
return &cfg
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue