func createDBCmd(args []string) { fs := flag.NewFlagSet("createdb", flag.ExitOnError) drop := fs.Bool("drop", false, "drop DB before creating") fs.Usage = func() { fmt.Fprintln(os.Stderr, `usage: orbit-server createdb [options] Creates the necessary DB tables and indexes. The options are: `) fs.PrintDefaults() os.Exit(1) } fs.Parse(args) if fs.NArg() != 0 { fs.Usage() } datastore.Connect() if *drop { datastore.Drop() } datastore.Create() }
func serveCmd(args []string) { fs := flag.NewFlagSet("serve", flag.ExitOnError) httpAddr := fs.String("http", ":5000", "HTTP service address") gitProjectsRoot := fs.String("git-root", ".", "git projects root") gitBin := fs.String("git-bin", "/usr/bin/git", "path to git binary") fs.Usage = func() { fmt.Fprintln(os.Stderr, `usage: orbit-server serve [options] Starts the web server that serves the API. The options are: `) fs.PrintDefaults() os.Exit(1) } fs.Parse(args) if fs.NArg() != 0 { fs.Usage() } git.SetConfig(git.Config{ ProjectRoot: *gitProjectsRoot, GitBinPath: *gitBin, UploadPack: true, ReceivePack: true, }) datastore.Connect() m := http.NewServeMux() m.Handle("/api/", http.StripPrefix("/api", api.Handler())) m.Handle("/git/", http.StripPrefix("/git", git.Handler())) log.Print("Listening on ", *httpAddr) err := http.ListenAndServe(*httpAddr, m) if err != nil { log.Fatal("ListenAndServe:", err) } }