aboutsummaryrefslogblamecommitdiffstats
path: root/cmd/datamaps/main.go
blob: 7841e956db59bfbca7040abd01a0ff4642c2a8d6 (plain) (tree)
1
2
3
4
5
6
7
8
9





                                                                           
             
             
                  
            
 
                                                    

 
             



                                                           



                                       
                                                                  


                                      
                                          


                                      










                                                                                   
                                                            
         
 
/*
datamaps-go 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() {
	dbpc := datamaps.NewDBPathChecker(os.UserConfigDir)
	if !dbpc.Check() {
		datamaps.SetUp()
	}
	opts := datamaps.ParseOptions()

	switch opts.Command {
	case "datamap":
		if err := datamaps.DatamapToDB(opts); err != nil {
			log.Fatal(err)
		}
	case "setup":
		_, err := datamaps.SetUp()
		if 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))
	}
}