Skip to content

Commit

Permalink
example (#15)
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Muravya committed Apr 21, 2021
1 parent 6f75e35 commit 7e51f8c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
25 changes: 16 additions & 9 deletions cmd/honeypot/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,15 @@ import (
"io"
"log"
"os"
"sync"
)

var (
once sync.Once
AppConfiguration *AppConfig
)

//core params
var (
port = kingpin.Flag("port", "Port we start at").Short('p').
Envar("PORT").Default("22").Uint16()
Expand Down Expand Up @@ -42,9 +49,6 @@ var accessLogger *log.Logger
//application logger
var applicationLogger *logrus.Logger

//are params already parsed
var alreadyParsed = false

//singleton keeper
var broadcasterObject *util.Broadcaster

Expand Down Expand Up @@ -74,14 +78,12 @@ type PromMetrics struct {
Prefix string
}

//GetAppConfig parses args and converts 'em to AppConfig
func GetAppConfig() AppConfig {
if !alreadyParsed {
func init() {
once.Do(func() {
kingpin.Parse()
alreadyParsed = true
}
})

return AppConfig{
AppConfiguration = &AppConfig{
Port: *port,
AccessLog: *accessLog,
ApplicationLog: *applicationLog,
Expand All @@ -97,6 +99,11 @@ func GetAppConfig() AppConfig {
}
}

//GetAppConfig parses args and converts 'em to AppConfig
func GetAppConfig() AppConfig {
return *AppConfiguration
}

//GetAccessLogger logger for access log
func GetAccessLogger() *log.Logger {
accessLog := GetAppConfig().AccessLog
Expand Down
2 changes: 1 addition & 1 deletion cmd/honeypot/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func main() {
registerWriters()

//getting HostKey
hostKey, hostKeyErr := sshutil.HostKey(&appConfig)
hostKey, hostKeyErr := sshutil.HostKey(config.AppConfiguration)
if hostKeyErr != nil {
if hostKeyErr.Error() == sshutil.NoHostKeyMarker {
hostKey = nil
Expand Down

0 comments on commit 7e51f8c

Please sign in to comment.