-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.go
53 lines (45 loc) · 1.94 KB
/
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
package quotes
import (
"fmt"
"time"
"github.com/spf13/afero"
"github.com/surahman/FTeX/pkg/configloader"
"github.com/surahman/FTeX/pkg/constants"
)
// config is the configuration container for connecting to external Quotes services.
//
//nolint:lll
type config struct {
FiatCurrency apiConfig `json:"fiatCurrency,omitempty" mapstructure:"fiatCurrency" validate:"required" yaml:"fiatCurrency,omitempty"`
CryptoCurrency apiConfig `json:"cryptoCurrency,omitempty" mapstructure:"cryptoCurrency" validate:"required" yaml:"cryptoCurrency,omitempty"`
Connection connectionConfig `json:"connection,omitempty" mapstructure:"connection" yaml:"connection,omitempty"`
}
// apiConfig contains the API Key and URL information for a currency exchange endpoint.
type apiConfig struct {
APIKey string `json:"apiKey,omitempty" mapstructure:"apiKey" validate:"required" yaml:"apiKey,omitempty"`
HeaderKey string `json:"headerKey,omitempty" mapstructure:"headerKey" validate:"required" yaml:"headerKey,omitempty"`
Endpoint string `json:"endpoint,omitempty" mapstructure:"endpoint" validate:"required" yaml:"endpoint,omitempty"`
}
// connectionConfig contains HTTP connection attempt information.
//
//nolint:lll
type connectionConfig struct {
UserAgent string `json:"userAgent,omitempty" mapstructure:"userAgent" validate:"required" yaml:"userAgent,omitempty"`
Timeout time.Duration `json:"timeout,omitempty" mapstructure:"timeout" validate:"required" yaml:"timeout,omitempty"`
}
// newConfig creates a blank configuration struct for Redis.
func newConfig() *config {
return &config{}
}
// Load will attempt to load configurations from a file on a file system.
func (cfg *config) Load(fs afero.Fs) (err error) {
if err := configloader.Load(
fs,
cfg,
constants.QuotesFileName(),
constants.QuotesPrefix(),
"yaml"); err != nil {
return fmt.Errorf("quotes config loading failed: %w", err)
}
return nil
}