Skip to content

Commit

Permalink
add config struct to cache by endpoint
Browse files Browse the repository at this point in the history
Signed-off-by: Avelino <avelinorun@gmail.com>
  • Loading branch information
avelino committed Dec 24, 2021
1 parent 0ec6069 commit 703025b
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ type TablesConf struct {
Fields []string `mapstructure:"fields"`
}

// CacheEndpoint specific configuration for specific endpoint
type CacheEndpoint struct {
Enable bool
Endpoint string
CacheTime int
}

// AccessConf informations
type AccessConf struct {
Restrict bool
Expand Down Expand Up @@ -73,6 +80,7 @@ type Prest struct {
CacheTime int
CacheStoragePath string
CacheSufixFile string
CacheEndpoints []CacheEndpoint
}

var (
Expand Down Expand Up @@ -207,12 +215,18 @@ func Parse(cfg *Prest) (err error) {
cfg.CacheTime = viper.GetInt("cache.time")
cfg.CacheStoragePath = viper.GetString("cache.storagepath")
cfg.CacheSufixFile = viper.GetString("cache.sufixfile")
var t []TablesConf
err = viper.UnmarshalKey("access.tables", &t)
var cacheendpoints []CacheEndpoint
err = viper.UnmarshalKey("cache.endpoints", &cacheendpoints)
if err != nil {
return
}
cfg.CacheEndpoints = cacheendpoints
var tablesconf []TablesConf
err = viper.UnmarshalKey("access.tables", &tablesconf)
if err != nil {
return
}
cfg.AccessConf.Tables = t
cfg.AccessConf.Tables = tablesconf
return
}

Expand Down

0 comments on commit 703025b

Please sign in to comment.