blob: 66f78a04b44c341a76ac6ecc5c23af8b2cc2b51c (
plain) (
blame)
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
|
/*datamaps is a simple tool to extract from and send data to spreadsheets.
*/
package main
import (
"fmt"
"log"
"net/http"
"os"
"github.com/yulqen/datamaps-go/pkg/datamaps"
)
func main() {
opts := datamaps.ParseOptions()
if opts.Command == "help" {
os.Stdout.WriteString(datamaps.Usage)
os.Exit(0)
}
dbpc := datamaps.NewDBPathChecker(os.UserConfigDir)
if !dbpc.Check() {
datamaps.SetUp()
}
switch opts.Command {
case "import":
if err := datamaps.ImportToDB(opts); err != nil {
log.Fatal(err)
}
case "datamap":
if err := datamaps.DatamapToDB(opts); err != nil {
log.Fatal(err)
}
case "setup":
_, err := datamaps.SetUp()
if err != nil {
log.Fatal(err)
}
case "createmaster":
if err := datamaps.CreateMaster(opts); err != nil {
log.Fatal(err)
}
case "server":
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
if r.URL.Path != "/" {
http.NotFound(w, r)
return
}
fmt.Fprintf(w, "Welcome to datamaps!")
// or you could write it thus
// w.Write([]byte("Hello from datamaps"))
})
log.Println("Starting server on :8080")
log.Fatal(http.ListenAndServe(":8080", nil))
}
}
|