HDFSWriter microservice working copy
[demo.git] / vnfs / DAaaS / microservices / GoApps / src / go-hdfs-writer / pkg / utils / kafka-config.go
1 package utils
2
3
4 import (
5         "os"
6 )
7
8 // SetKafkaParametersByObjectMap sets the  value of the kafka parameters
9 // and sets the KafkaConfig object 
10 func SetKafkaParametersByObjectMap(m map[string]interface{}) KafkaConfig {
11         kc := KafkaConfig{}
12         kc.broker = m["broker"].(string)
13         kc.group = m["group"].(string)
14         kc.topic = m["topic"].(string)
15
16         return kc
17 }
18
19 // SetKafkaParametersByEnvVariables sets the kafka parameters
20 func SetKafkaParametersByEnvVariables() KafkaConfig {
21         slogger := GetLoggerInstance()
22         
23         kafkaConfigObject := KafkaConfig{
24                 broker: os.Getenv("BROKER"),
25                 group: os.Getenv("GROUP"),
26                 topic: os.Getenv("TOPIC"),
27         }
28         slogger.Infof("::broker:: %s", kafkaConfigObject.broker)
29         slogger.Infof("::group:: %s", kafkaConfigObject.group)
30         slogger.Infof("::topic:: %s", kafkaConfigObject.topic)
31
32         return kafkaConfigObject
33 }
34
35 // KafkaConfig contains all the config parameters needed for kafka. This can be extended over time
36 type KafkaConfig struct {
37         broker string
38         group string
39         topic string
40 }
41
42 // GetBroker returns kafka broker configured
43 func (k KafkaConfig) GetBroker() string {
44         return k.broker
45 }
46
47 // GetGroup returns kafka group configured
48 func (k KafkaConfig) GetGroup() string {
49         return k.group
50 }
51
52 // GetTopic returns kafka topic configured
53 func (k KafkaConfig) GetTopic() string {
54         return k.topic
55 }