-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
60 lines (51 loc) · 1.38 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
package main
import (
"fmt"
"log"
"net/http"
"os/exec"
)
func buildSite() {
fmt.Println("\n---buildSite---\nCompiling website...")
out, err := exec.Command("hugo").Output()
if err != nil {
log.Fatal(err)
}
fmt.Printf("%s\nWebsite compiled!\n---buildSite---\n\n", out)
}
func git(file string) {
//need to accommodate for username, email eventually
cmdName := "git"
gitAdd := []string{"add", file}
outadd, err := exec.Command(cmdName, gitAdd...).Output()
if err != nil {
fmt.Printf("fatal error on git add\n")
fmt.Println(err)
}
fmt.Printf("\n------git------\ngit add "+file+" %s\n", outadd)
gitCommit := []string{"commit", "-m", "updating " + file + " from topiary"}
outci, err := exec.Command(cmdName, gitCommit...).Output()
if err != nil {
fmt.Printf("fatal error on git commit\n")
fmt.Println(err)
}
fmt.Printf("git commit "+file+" %s\n------git------\n", outci)
}
func main() {
initConfig()
buildSite()
initAuth()
// serve site output (`/public`) into `/`
http.Handle("/", http.FileServer(http.Dir("./public")))
// serve the topiary admin
adminroot := getConfig("adminroot")
admindir := getConfig("admindir")
serveAdmin(adminroot, admindir)
// start the server
fmt.Println("Starting server on port 3000...")
fmt.Println("Admin available at:", adminroot)
err := http.ListenAndServe(":3000", nil)
if err != nil {
log.Fatal("ListenAndServe: ", err)
}
}