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
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
|
@ -21,21 +22,38 @@ func main() {
|
||||||
ShortName: "s",
|
ShortName: "s",
|
||||||
Usage: "Start web server",
|
Usage: "Start web server",
|
||||||
Flags: []cli.Flag{
|
Flags: []cli.Flag{
|
||||||
cli.StringFlag{
|
cli.IntFlag{
|
||||||
Name: "http",
|
Name: "port",
|
||||||
Value: ":8901",
|
Value: 8901,
|
||||||
Usage: "HTTP service address",
|
Usage: "HTTP service port",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Action: cmdServe,
|
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)
|
app.Run(os.Args)
|
||||||
}
|
}
|
||||||
|
|
||||||
func cmdServe(c *cli.Context) {
|
func cmdServe(c *cli.Context) {
|
||||||
httpAddr := c.String("http")
|
httpAddr := fmt.Sprintf(":%v", c.Int("port"))
|
||||||
|
|
||||||
datastore.Connect()
|
datastore.Connect()
|
||||||
|
|
||||||
|
@ -47,3 +65,14 @@ func cmdServe(c *cli.Context) {
|
||||||
log.Fatal("ListenAndServe: ", err)
|
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