-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
65 lines (53 loc) · 1.26 KB
/
main.go
File metadata and controls
65 lines (53 loc) · 1.26 KB
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
59
60
61
62
63
64
65
package main
import (
"fmt"
"os"
"github.com/dracit7/Courselect/lib/db"
"github.com/dracit7/Courselect/lib/log"
"github.com/dracit7/Courselect/router"
"github.com/dracit7/Courselect/setting"
"github.com/fvbock/endless"
"github.com/urfave/cli"
)
func main() {
var configFile string
// Handle command-line arguments.
app := cli.NewApp()
app.Name = "Courselect"
app.Usage = "Courselect is an online platform for publishing and selecting courses."
app.Flags = []cli.Flag{
cli.StringFlag{
Name: "conf",
Value: "conf/debug.conf",
Usage: "specify config file",
Destination: &configFile,
},
}
app.Action = func(c *cli.Context) error {
Start(configFile)
return nil
}
// Run the application
err := app.Run(os.Args)
if err != nil {
log.Fatal(err.Error())
}
}
// Start the application
func Start(configFile string) {
// Set up each module.
setting.Setup(configFile)
log.Setup(os.Stdout)
db.Setup()
router := router.Setup()
endpoint := fmt.Sprintf(":%d", setting.Server.Port)
server := endless.NewServer(endpoint, router)
server.BeforeBegin = func(add string) {
log.Info("*** Started the server ***")
}
// Start the server
err := server.ListenAndServe()
if err != nil {
log.Fatal("Server has been shutted down.")
}
}