-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
43 lines (37 loc) · 866 Bytes
/
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
package main
import (
"flag"
"fmt"
"github.com/qichengzx/gopress/generator"
"log"
"net/http"
"time"
)
func main() {
generatePtr := flag.Bool("g", false, "Generate static files")
servePtr := flag.Bool("s", false, "Serve static files")
portPtr := flag.String("p", "8092", "Server port")
flag.Parse()
switch {
case *generatePtr:
timeStart := time.Now()
log.Println("Process begining")
defer func() {
timeEnd := time.Now()
used := timeEnd.Sub(timeStart)
log.Println("Process done")
log.Println("Used", used)
}()
var site = generator.New("./_config.yaml")
site.Build()
break;
case *servePtr && *portPtr != "" :
fmt.Println("server run at", *portPtr)
err := http.ListenAndServe(":"+*portPtr, http.FileServer(http.Dir("./public/")))
if err != nil {
log.Fatal("ListenAndServe: ", err)
}
default:
flag.Usage()
}
}