Files
cgrates/agents/libdmt.go
2018-09-20 15:17:51 +02:00

61 lines
1.9 KiB
Go

/*
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 agents
import (
"fmt"
"os"
"path/filepath"
"strings"
"github.com/cgrates/cgrates/utils"
"github.com/fiorix/go-diameter/diam/dict"
)
func loadDictionaries(dictsDir, componentId string) error {
fi, err := os.Stat(dictsDir)
if err != nil {
if strings.HasSuffix(err.Error(), "no such file or directory") {
return fmt.Errorf("<%s> Invalid dictionaries folder: <%s>", componentId, dictsDir)
}
return err
} else if !fi.IsDir() { // If config dir defined, needs to exist
return fmt.Errorf("<DiameterAgent> Path: <%s> is not a directory", dictsDir)
}
return filepath.Walk(dictsDir, func(path string, info os.FileInfo, err error) error {
if !info.IsDir() {
return nil
}
cfgFiles, err := filepath.Glob(filepath.Join(path, "*.xml")) // Only consider .xml files
if err != nil {
return err
}
if cfgFiles == nil { // No need of processing further since there are no dictionary files in the folder
return nil
}
for _, filePath := range cfgFiles {
utils.Logger.Info(fmt.Sprintf("<%s> Loading dictionary out of file %s", componentId, filePath))
if err := dict.Default.LoadFile(filePath); err != nil {
return err
}
}
return nil
})
}