Skip to content

Commit

Permalink
Merge pull request #187 from sbezverk/issue_#186
Browse files Browse the repository at this point in the history
add error check for all types of publishers
  • Loading branch information
sbezverk authored Jan 12, 2022
2 parents 11e080c + c4ba9f9 commit 3d775a6
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 12 deletions.
23 changes: 16 additions & 7 deletions cmd/gobmp/gobmp.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,23 @@ func main() {
var err error
switch strings.ToLower(dump) {
case "file":
publisher = filer.NewFiler(file)
publisher, err = filer.NewFiler(file)
if err != nil {
glog.Errorf("failed to initialize file publisher with error: %+v", err)
os.Exit(1)
}
glog.V(5).Infof("file publisher has been successfully initialized.")
case "console":
publisher = dumper.NewDumper()
publisher, err = dumper.NewDumper()
if err != nil {
glog.Errorf("failed to initialize console publisher with error: %+v", err)
os.Exit(1)
}
glog.V(5).Infof("console publisher has been successfully initialized.")
default:
publisher, err = kafka.NewKafkaPublisher(kafkaSrv)
if err != nil {
glog.Errorf("fail to initialize Kafka publisher with error: %+v", err)
glog.Errorf("restarting gobmp...")
glog.Errorf("failed to initialize Kafka publisher with error: %+v", err)
os.Exit(1)
}
glog.V(5).Infof("Kafka publisher has been successfully initialized.")
Expand All @@ -92,17 +101,17 @@ func main() {
// Initializing bmp server
interceptFlag, err := strconv.ParseBool(intercept)
if err != nil {
glog.Errorf("fail to parse to bool the value of the intercept flag with error: %+v", err)
glog.Errorf("failed to parse to bool the value of the intercept flag with error: %+v", err)
os.Exit(1)
}
splitAFFlag, err := strconv.ParseBool(splitAF)
if err != nil {
glog.Errorf("fail to parse to bool the value of the intercept flag with error: %+v", err)
glog.Errorf("failed to parse to bool the value of the intercept flag with error: %+v", err)
os.Exit(1)
}
bmpSrv, err := gobmpsrv.NewBMPServer(srcPort, dstPort, interceptFlag, publisher, splitAFFlag)
if err != nil {
glog.Errorf("fail to setup new gobmp server with error: %+v", err)
glog.Errorf("failed to setup new gobmp server with error: %+v", err)
os.Exit(1)
}
// Starting Interceptor server
Expand Down
4 changes: 2 additions & 2 deletions pkg/dumper/dumper.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ func (p *pubwriter) Stop() {
}

// NewDumper returns a new instance of standard out dumper
func NewDumper() pub.Publisher {
func NewDumper() (pub.Publisher, error) {
pw := pubwriter{
output: log.New(os.Stdout, "gobmp: ", log.Lmicroseconds),
}

return &pw
return &pw, nil
}
6 changes: 3 additions & 3 deletions pkg/filer/filer.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,14 @@ func (p *pubfiler) Stop() {
}

// NewFiler returns a new instance of message filer
func NewFiler(file string) pub.Publisher {
func NewFiler(file string) (pub.Publisher, error) {
f, err := os.Create(file)
if err != nil {
return nil
return nil, err
}
pw := pubfiler{
file: f,
}

return &pw
return &pw, nil
}

0 comments on commit 3d775a6

Please sign in to comment.