-
Notifications
You must be signed in to change notification settings - Fork 7
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
2 changed files
with
50 additions
and
0 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,49 @@ | ||
package config | ||
|
||
import ( | ||
"fmt" | ||
"time" | ||
) | ||
|
||
type ExternalAPIsConfig struct { | ||
CoinMarketCap *CoinMarketCapConfig `mapstructure:"coinmarketcap"` | ||
} | ||
|
||
type CoinMarketCapConfig struct { | ||
APIKey string `mapstructure:"api_key"` | ||
BaseURL string `mapstructure:"base_url"` | ||
Timeout time.Duration `mapstructure:"timeout"` | ||
CacheTTL time.Duration `mapstructure:"cache_ttl"` | ||
} | ||
|
||
func (cfg *ExternalAPIsConfig) Validate() error { | ||
if cfg.CoinMarketCap == nil { | ||
return fmt.Errorf("missing coinmarketcap config") | ||
} | ||
|
||
if err := cfg.CoinMarketCap.Validate(); err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func (cfg *CoinMarketCapConfig) Validate() error { | ||
if cfg.APIKey == "" { | ||
return fmt.Errorf("missing coinmarketcap api key") | ||
} | ||
|
||
if cfg.BaseURL == "" { | ||
return fmt.Errorf("missing coinmarketcap base url") | ||
} | ||
|
||
if cfg.Timeout <= 0 { | ||
return fmt.Errorf("invalid coinmarketcap timeout") | ||
} | ||
|
||
if cfg.CacheTTL <= 0 { | ||
return fmt.Errorf("invalid coinmarketcap cache ttl") | ||
} | ||
|
||
return nil | ||
} |