This repository has been archived on 2025-03-30. You can view files and clone it, but cannot push or open issues or pull requests.
bactdb/cmd/bactdb/bactdb.go
2015-01-05 11:50:42 -09:00

49 lines
860 B
Go

package main
import (
"log"
"net/http"
"os"
"github.com/codegangsta/cli"
"github.com/thermokarst/bactdb/api"
"github.com/thermokarst/bactdb/datastore"
)
func main() {
app := cli.NewApp()
app.Name = "bactdb"
app.Usage = "a database for bacteria"
app.Commands = []cli.Command{
{
Name: "serve",
ShortName: "s",
Usage: "Start web server",
Flags: []cli.Flag{
cli.StringFlag{
Name: "http",
Value: ":8901",
Usage: "HTTP service address",
},
},
Action: cmdServe,
},
}
app.Run(os.Args)
}
func cmdServe(c *cli.Context) {
httpAddr := c.String("http")
datastore.Connect()
m := http.NewServeMux()
m.Handle("/api/", http.StripPrefix("/api", api.Handler()))
log.Print("Listening on ", httpAddr)
err := http.ListenAndServe(httpAddr, m)
if err != nil {
log.Fatal("ListenAndServe: ", err)
}
}