WIP
This commit is contained in:
parent
28f29f3d68
commit
d081639b88
1 changed files with 34 additions and 5 deletions
|
@ -1,6 +1,7 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
|
@ -21,21 +22,38 @@ func main() {
|
|||
ShortName: "s",
|
||||
Usage: "Start web server",
|
||||
Flags: []cli.Flag{
|
||||
cli.StringFlag{
|
||||
Name: "http",
|
||||
Value: ":8901",
|
||||
Usage: "HTTP service address",
|
||||
cli.IntFlag{
|
||||
Name: "port",
|
||||
Value: 8901,
|
||||
Usage: "HTTP service port",
|
||||
},
|
||||
},
|
||||
Action: cmdServe,
|
||||
},
|
||||
{
|
||||
Name: "createdb",
|
||||
ShortName: "c",
|
||||
Usage: "create the database schema",
|
||||
Flags: []cli.Flag{
|
||||
cli.BoolFlag{
|
||||
Name: "drop",
|
||||
Usage: "drop DB before creating",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "migration_path",
|
||||
Usage: "path to migrations",
|
||||
Value: "./datastore/migrations",
|
||||
},
|
||||
},
|
||||
Action: cmdCreateDB,
|
||||
},
|
||||
}
|
||||
|
||||
app.Run(os.Args)
|
||||
}
|
||||
|
||||
func cmdServe(c *cli.Context) {
|
||||
httpAddr := c.String("http")
|
||||
httpAddr := fmt.Sprintf(":%v", c.Int("port"))
|
||||
|
||||
datastore.Connect()
|
||||
|
||||
|
@ -47,3 +65,14 @@ func cmdServe(c *cli.Context) {
|
|||
log.Fatal("ListenAndServe: ", err)
|
||||
}
|
||||
}
|
||||
|
||||
func cmdCreateDB(c *cli.Context) {
|
||||
migrationsPath := c.String("migration_path")
|
||||
|
||||
datastore.Connect()
|
||||
|
||||
if c.Bool("drop") {
|
||||
datastore.Drop(migrationsPath)
|
||||
}
|
||||
datastore.Create(migrationsPath)
|
||||
}
|
||||
|
|
Reference in a new issue