forked from evan-buss/openbooks
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: use separate config for each cobra command.
- Loading branch information
Showing
5 changed files
with
95 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"math/rand" | ||
"path" | ||
"time" | ||
|
||
"github.com/brianvoe/gofakeit/v5" | ||
"github.com/evan-buss/openbooks/server" | ||
) | ||
|
||
// Generate a random username to avoid IRC name collisions if multiple users are hosting | ||
// at the same time. | ||
func generateUserName() string { | ||
rand.Seed(time.Now().UnixNano()) | ||
gofakeit.Seed(int64(rand.Int())) | ||
return fmt.Sprintf("%s_%s", gofakeit.Adjective(), gofakeit.Noun()) | ||
} | ||
|
||
// Update a server config struct from globalFlags | ||
func bindGlobalFlags(config *server.Config) { | ||
config.Version = fmt.Sprintf("OpenBooks Server %s", ircVersion) | ||
config.UserName = globalFlags.UserName | ||
config.Log = globalFlags.Log | ||
config.Server = globalFlags.Server | ||
config.SearchBot = globalFlags.SearchBot | ||
} | ||
|
||
// Make sure the server config has a valid rate limit. | ||
func ensureValidRate(rateLimit int, config *server.Config) { | ||
|
||
// If user enters a limit that's too low, set to default of 10 seconds. | ||
if rateLimit < 10 { | ||
rateLimit = 10 | ||
} | ||
|
||
config.SearchTimeout = time.Duration(rateLimit) * time.Second | ||
} | ||
|
||
func sanitizePath(basepath string) string { | ||
cleaned := path.Clean(basepath) | ||
if cleaned == "/" { | ||
return cleaned | ||
} | ||
return cleaned + "/" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters