diff options
Diffstat (limited to 'cmd')
| -rw-r--r-- | cmd/daemon/main.go | 38 |
1 files changed, 35 insertions, 3 deletions
diff --git a/cmd/daemon/main.go b/cmd/daemon/main.go index a118df3..98dd565 100644 --- a/cmd/daemon/main.go +++ b/cmd/daemon/main.go @@ -40,10 +40,12 @@ func main() { enableTls := flag.Bool("tls", false, "Enable TLS") certPath := flag.String("tls-cert", "", "TLS certificate PEM file path") keyPath := flag.String("tls-key", "", "TLS key PEM file path") + test := flag.Bool("test", false, "Create test database entries") + dbPath := flag.String("db", "solec.db", "SQLite database path") flag.Parse() - db, err := storage.InitDb("test.db") + db, err := storage.InitDb(*dbPath) if err != nil { panic(err) } @@ -59,7 +61,10 @@ func main() { } serv = server.NewServer(cfg, db) - serv.AddChannel("test") + + if *test { + seedDatabase() + } go func() { if err := serv.Start(); err != nil { @@ -185,10 +190,37 @@ func setPerm(args []string) { } } +func seedDatabase() { + log.Println("creating test users") + log.Println("user1, user2, user3") + setUser([]string{"user1@localhost", "test"}) + setUser([]string{"user2@localhost", "test"}) + setUser([]string{"user3@localhost", "test"}) + + log.Println("setting #test@localhost channel permissions") + log.Println("user1, user2 -> #test") + setPerm([]string{"user1@localhost", "#test@localhost", "1", "1"}) + setPerm([]string{"user2@localhost", "#test@localhost", "1", "1"}) + + log.Println("setting user channel permissions") + log.Println("user1 -> user1, user2, user3") + setPerm([]string{"user1@localhost", "user1@localhost", "1", "1"}) + setPerm([]string{"user1@localhost", "user2@localhost", "1", "1"}) + setPerm([]string{"user1@localhost", "user3@localhost", "1", "1"}) + + log.Println("user2 -> user1, user2") + setPerm([]string{"user2@localhost", "user1@localhost", "1", "1"}) + setPerm([]string{"user2@localhost", "user2@localhost", "1", "1"}) + + log.Println("user3 -> user1, user3") + setPerm([]string{"user3@localhost", "user1@localhost", "1", "1"}) + setPerm([]string{"user3@localhost", "user3@localhost", "1", "1"}) +} + func exit(args []string) { os.Exit(0) } func printErr(err error) { - fmt.Println("error:", err) + log.Println("error:", err) } |
