Skip to content
This repository has been archived by the owner on Feb 1, 2024. It is now read-only.

Commit

Permalink
separate out makeKelpOS() from the kelpos#init() method so the versio…
Browse files Browse the repository at this point in the history
…n command does not display log lines
  • Loading branch information
nikhilsaraf committed May 4, 2020
1 parent 3553368 commit 8f7a929
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions support/kelpos/kelpos.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,12 @@ type Process struct {
// singleton is the singleton instance of KelpOS
var singleton *KelpOS

func init() {
// startedMakeKelpOS is used to track cycles in the initialization of makeKelpOS()
var startedMakeKelpOS = false

func makeKelpOS() *KelpOS {
startedMakeKelpOS = true

binDir, e := MakeOsPathBase()
if e != nil {
panic(errors.Wrap(e, "could not make binDir"))
Expand Down Expand Up @@ -80,7 +85,7 @@ func init() {

// using dotKelpWorkingDir as working directory since all our config files and log files are located in here and we want
// to have the shortest path lengths to accommodate for the 260 character file path limit in windows
singleton = &KelpOS{
return &KelpOS{
binDir: binDir,
dotKelpWorkingDir: dotKelpWorkingDir,
processes: map[string]Process{},
Expand All @@ -98,8 +103,14 @@ type BotInstance struct {

// GetKelpOS gets the singleton instance
func GetKelpOS() *KelpOS {
if singleton == nil {
panic(fmt.Errorf("there is a cycle stemming from the init() method since singleton was nil"))
if singleton != nil {
return singleton
}

if startedMakeKelpOS {
panic(fmt.Errorf("there is a cycle stemming from the makeKelpOS() method since singleton was nil and startedMakeKelpOS was true"))
}

singleton = makeKelpOS()
return singleton
}

0 comments on commit 8f7a929

Please sign in to comment.