aboutsummaryrefslogtreecommitdiffstats
path: root/vnfs/DAaaS/microservices/GoApps/src/go-hdfs-writer/pkg/utils/kafka-config.go
blob: 080bfd4bbb8a35ce54423d3c83afdda6c94a6b89 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package utils


import (
	"os"
)

// SetKafkaParametersByObjectMap sets the  value of the kafka parameters
// and sets the KafkaConfig object 
func SetKafkaParametersByObjectMap(m map[string]interface{}) KafkaConfig {
	kc := KafkaConfig{}
	kc.broker = m["broker"].(string)
	kc.group = m["group"].(string)
	kc.topic = m["topic"].(string)

	return kc
}

// SetKafkaParametersByEnvVariables sets the kafka parameters
func SetKafkaParametersByEnvVariables() KafkaConfig {
	slogger := GetLoggerInstance()
	
	kafkaConfigObject := KafkaConfig{
		broker: os.Getenv("BROKER"),
		group: os.Getenv("GROUP"),
		topic: os.Getenv("TOPIC"),
	}
	slogger.Infof("::broker:: %s", kafkaConfigObject.broker)
	slogger.Infof("::group:: %s", kafkaConfigObject.group)
	slogger.Infof("::topic:: %s", kafkaConfigObject.topic)

	return kafkaConfigObject
}

// KafkaConfig contains all the config parameters needed for kafka. This can be extended over time
type KafkaConfig struct {
	broker string
	group string
	topic string
}

// GetBroker returns kafka broker configured
func (k KafkaConfig) GetBroker() string {
	return k.broker
}

// GetGroup returns kafka group configured
func (k KafkaConfig) GetGroup() string {
	return k.group
}

// GetTopic returns kafka topic configured
func (k KafkaConfig) GetTopic() string {
	return k.topic
}