tempestas

A REST API for processing sensor.community data
git clone https://git.bracken.jp/tempestas.git
Log | Files | Refs | README | LICENSE

main.go (977B)


      1 package main
      2 
      3 import (
      4 	"flag"
      5 	"fmt"
      6 	"log"
      7 
      8 	"git.bracken.jp/tempestas/http"
      9 	"git.bracken.jp/tempestas/storage"
     10 	_ "github.com/lib/pq"
     11 )
     12 
     13 func main() {
     14 	dbname := flag.String("db", "tempestas", "the database name")
     15 	dbuser := flag.String("user", "tempestas", "the database user")
     16 	dbpass := flag.String("password", "", "the database password")
     17 	devdb := flag.Bool("devdb", false, "whether to use developer-mode database")
     18 	addr := flag.String("address", ":8080", "HTTP service host:port")
     19 	assetDir := flag.String("assets", "/usr/local/share/tempestas/www", "HTTP asset directory")
     20 	flag.Parse()
     21 
     22 	var ds storage.DataStore
     23 	if *devdb {
     24 		fmt.Println("Using null database for development")
     25 		ds = storage.ConnectNull()
     26 	} else {
     27 		fmt.Println("Connecting to database")
     28 		ds = storage.ConnectPostgres(*dbname, *dbuser, *dbpass)
     29 	}
     30 	defer ds.Close()
     31 
     32 	fmt.Println("Waiting for requests at " + *addr)
     33 	s := http.CreateServer(ds, *assetDir)
     34 	log.Fatal(s.ListenAndServe(*addr))
     35 }