-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
58 lines (49 loc) · 1.07 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package main
import (
"bufio"
"fmt"
"log"
"os"
"strings"
cmdSwitch "github.com/erwinhermanto31/quiz_master/cmd"
"github.com/erwinhermanto31/quiz_master/repo/mysql"
"github.com/erwinhermanto31/quiz_master/util"
"github.com/joho/godotenv"
)
func main() {
err := godotenv.Load()
if err != nil {
log.Fatal("Error loading .env file")
}
mysql.InitCon()
mysql.InitMigration()
fmt.Println("Welcome to Quiz Master! ")
fmt.Println(" ")
var command string
// var num int
// var i int
for {
consoleReader := bufio.NewReader(os.Stdin)
command, _ = consoleReader.ReadString('\n')
command = strings.Replace(command, "\n", "", 1)
fmt.Println(" ")
cmds := strings.Split(command, " ")
cmd := cmds[0]
switch cmd {
case util.Command[cmd]:
s := cmdSwitch.NewSwitch(util.Command[cmd])
err := s.Switch(command)
if err != nil {
fmt.Printf("%v\n", err)
}
case "help":
util.PrintHelp()
fmt.Println(" ")
case "exit":
fmt.Println("===================================")
os.Exit(0)
default:
fmt.Printf("unknown command: %s\n", cmd)
}
}
}