Skip to content

Commit a1aecc0

Browse files
committed
Update main.go
1 parent 07529f0 commit a1aecc0

File tree

2 files changed

+12
-14
lines changed

2 files changed

+12
-14
lines changed

cmd/openbooks/main.go

+11
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,11 @@ package main
22

33
import (
44
"fmt"
5+
"math/rand"
56
"os"
7+
"time"
68

9+
"github.com/brianvoe/gofakeit/v5"
710
"github.com/spf13/cobra"
811
)
912

@@ -18,3 +21,11 @@ func main() {
1821
os.Exit(1)
1922
}
2023
}
24+
25+
// Generate a random username to avoid IRC name collisions if multiple users are hosting
26+
// at the same time.
27+
func generateUserName() string {
28+
rand.Seed(time.Now().UnixNano())
29+
gofakeit.Seed(int64(rand.Int()))
30+
return fmt.Sprintf("%s-%s", gofakeit.Adjective(), gofakeit.Noun())
31+
}

cmd/openbooks/server.go

+1-14
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,20 @@
11
package main
22

33
import (
4-
"fmt"
5-
"math/rand"
64
"os"
75
"path"
8-
"time"
96

10-
"github.com/brianvoe/gofakeit/v5"
117
"github.com/evan-buss/openbooks/server"
128

139
"github.com/spf13/cobra"
1410
)
1511

1612
func init() {
1713
rootCmd.AddCommand(serverCmd)
18-
userName := generateUserName()
1914

2015
serverCmd.Flags().BoolP("log", "l", false, "Save raw IRC logs for each client connection.")
2116
serverCmd.Flags().BoolP("browser", "b", false, "Open the browser on server start.")
22-
serverCmd.Flags().StringP("name", "n", userName, "Use a name that isn't randomly generated. One word only.")
17+
serverCmd.Flags().StringP("name", "n", generateUserName(), "Use a name that isn't randomly generated. One word only.")
2318
serverCmd.Flags().StringP("port", "p", "5228", "Set the local network port for browser mode.")
2419
serverCmd.Flags().StringP("dir", "d", path.Join(os.TempDir(), "openbooks"), "The directory where eBooks are saved when persist enabled.")
2520
serverCmd.Flags().Bool("persist", false, "Persist eBooks in 'dir'. Default is to delete after sending.")
@@ -64,14 +59,6 @@ var serverCmd = &cobra.Command{
6459
},
6560
}
6661

67-
// Generate a random username to avoid IRC name collisions if multiple users are hosting
68-
// at the same time.
69-
func generateUserName() string {
70-
rand.Seed(time.Now().UnixNano())
71-
gofakeit.Seed(int64(rand.Int()))
72-
return fmt.Sprintf("%s-%s", gofakeit.Adjective(), gofakeit.Noun())
73-
}
74-
7562
func sanitizePath(basepath string) string {
7663
cleaned := path.Clean(basepath)
7764
if cleaned == "/" {

0 commit comments

Comments
 (0)