forked from viniciuswebdev/goahead
/
main.go
78 lines (64 loc) · 1.64 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package main
// This is a fork from https://github.com/viniciuswebdev/goahead
import (
"code.google.com/p/gcfg"
"flag"
"fmt"
"github.com/Zocprint/go301/database"
"github.com/Zocprint/go301/server"
"log"
)
type Config struct {
General server.Server
Database database.DatabaseConf
Table database.TableConf
Cache database.CacheConf
}
var _cfg Config
func main() {
configFilePath := flag.String("config", "./etc/goahead.ini", "Configuration file path")
help := flag.Bool("help", false, "Show me the help!")
run := flag.Bool("run", false, "Run server")
build := flag.Bool("build", false, "Create the scaffold")
flag.Parse()
if *help || (!(*run) && !(*build)) {
showHelp()
return
}
err := gcfg.ReadFileInto(&_cfg, *configFilePath)
if err != nil {
log.Fatal(err)
}
db := database.Create(&(_cfg.Database))
err = db.IsValid()
if err != nil {
log.Fatal(err)
}
if *build {
buildScaffold(db)
return
}
if *run {
runServer(db)
return
}
}
func showHelp() {
fmt.Println("Go301 is a simple service that redirects routes\n")
fmt.Println("Usage: ")
fmt.Println("\t goahead [argument [-config filepath with ini configuration]]")
fmt.Println("")
fmt.Println("The commands are: ")
fmt.Println("\t -help show the help")
fmt.Println("\t -build create the scaffold")
fmt.Println("\t -run run server!")
fmt.Println("")
fmt.Println("Visit http://github.com/Zocprint/go301 for many informations")
}
func buildScaffold(db *database.Database) {
fmt.Println("Creating the scaffold...")
db.CreateTables(&(_cfg.Table))
}
func runServer(db *database.Database) {
_cfg.General.TurnOn(db, &(_cfg.Table), &(_cfg.Cache))
}