Skip to content

Commit

Permalink
Add missing ExternalAPIs
Browse files Browse the repository at this point in the history
  • Loading branch information
kirugan committed Jan 21, 2025
1 parent b5e7cd7 commit 4c9169a
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
1 change: 1 addition & 0 deletions internal/shared/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ type Config struct {
Metrics *MetricsConfig `mapstructure:"metrics"`
Assets *AssetsConfig `mapstructure:"assets"`
DelegationTransition *DelegationTransitionConfig `mapstructure:"delegation-transition"`
ExternalAPIs *ExternalAPIsConfig `mapstructure:"external_apis"`
}

func (cfg *Config) Validate() error {
Expand Down
49 changes: 49 additions & 0 deletions internal/shared/config/external_apis.go
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
}

0 comments on commit 4c9169a

Please sign in to comment.