Skip to content

Commit

Permalink
Update the utils funcations
Browse files Browse the repository at this point in the history
  • Loading branch information
ragul28 committed Feb 28, 2021
1 parent 981b97a commit 1bc6414
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
2 changes: 2 additions & 0 deletions utils/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ type Confg struct {
Password string
Groupid string
Topic string
MsgSize string
}

func LoadConfig() *Confg {
Expand All @@ -26,6 +27,7 @@ func LoadConfig() *Confg {
c.Password = getConfig("KAFKA_PASSWORD", "password", "", "Kafka broker password")
c.Groupid = getConfig("KAFKA_GROUPID", "gid", "gid", "Kafka group id")
c.Topic = getConfig("KAFKA_TOPIC", "topic", "topic", "Kafka topic name")
c.MsgSize = getConfig("KAFKA_MSGSIZE", "msgsize", "10", "Kafka message size")

return &c
}
Expand Down
10 changes: 10 additions & 0 deletions utils/logdebug.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package utils

import "log"

// DebugLogging helper func to log debug
func DebugLogging(logstring string, enableDebug bool) {
if enableDebug {
log.Printf(logstring)
}
}
16 changes: 16 additions & 0 deletions utils/randstring.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package utils

import (
"math/rand"
)

var letters = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")

// RandString genrates rand messages to produce
func RandString(n int) string {
b := make([]rune, n)
for i := range b {
b[i] = letters[rand.Intn(len(letters))]
}
return string(b)
}

0 comments on commit 1bc6414

Please sign in to comment.