Files
cgrates/config/cacheconfig.go
2017-09-10 15:02:46 +00:00

71 lines
1.7 KiB
Go
Executable File

/*
Real-time Online/Offline Charging System (OCS) for Telecom & ISP environments
Copyright (C) ITsysCOM GmbH
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>
*/
package config
import (
"time"
"github.com/cgrates/cgrates/utils"
)
type CacheParamConfig struct {
Limit int
TTL time.Duration
StaticTTL bool
Precache bool
}
func (self *CacheParamConfig) loadFromJsonCfg(jsnCfg *CacheParamJsonCfg) error {
if jsnCfg == nil {
return nil
}
var err error
if jsnCfg.Limit != nil {
self.Limit = *jsnCfg.Limit
}
if jsnCfg.Ttl != nil {
if self.TTL, err = utils.ParseDurationWithSecs(*jsnCfg.Ttl); err != nil {
return err
}
}
if jsnCfg.Static_ttl != nil {
self.StaticTTL = *jsnCfg.Static_ttl
}
if jsnCfg.Precache != nil {
self.Precache = *jsnCfg.Precache
}
return nil
}
type CacheConfig map[string]*CacheParamConfig
func (self CacheConfig) loadFromJsonCfg(jsnCfg *CacheJsonCfg) (err error) {
if jsnCfg == nil {
return
}
for kJsn, vJsn := range *jsnCfg {
val := new(CacheParamConfig)
if err := val.loadFromJsonCfg(vJsn); err != nil {
return err
}
self[kJsn] = val
}
return nil
}