Files
cgrates/ers/filecsv.go
2019-09-01 20:59:38 +02:00

81 lines
2.0 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 ers
import (
"fmt"
"strings"
"sync"
"github.com/cgrates/cgrates/config"
"github.com/cgrates/cgrates/utils"
)
func NewCSVFileER(cfg *config.EventReaderCfg,
rdrExit chan struct{}, appExit chan bool) (er EventReader, err error) {
srcPath := cfg.SourcePath
if strings.HasSuffix(srcPath, utils.Slash) {
srcPath = srcPath[:len(srcPath)-1]
}
return &CSVFileER{erCfg: cfg, rdrDir: srcPath,
rdrExit: rdrExit, appExit: appExit}, nil
}
// CSVFileER implements EventReader interface for .csv files
type CSVFileER struct {
sync.RWMutex
erCfg *config.EventReaderCfg
rdrDir string
rdrExit chan struct{}
appExit chan bool
}
func (csv *CSVFileER) Config() *config.EventReaderCfg {
return csv.erCfg
}
func (csv *CSVFileER) Subscribe() error {
go func() {
if err := watchDir(csv.rdrDir, csv.processDir,
utils.ERs, csv.rdrExit); err != nil {
utils.Logger.Crit(
fmt.Sprintf("<%s> watching directory <%s> got error: <%s>",
utils.ERs, csv.rdrDir, err.Error()))
csv.appExit <- true
}
}()
return nil
}
func (csv *CSVFileER) Read() (ev *utils.CGREvent, err error) {
return
}
func (csv *CSVFileER) Processed() (nrItms int64) {
return
}
func (csv *CSVFileER) Close() (err error) {
return
}
func (csv *CSVFileER) processDir(itmPath, itmID string) (err error) {
return
}