-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
57 lines (48 loc) · 1.09 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package main
import (
"context"
"errors"
"log"
"os"
_ "github.com/joho/godotenv/autoload"
"github.com/rusher2004/nerdb/postgres/migrate"
"github.com/rusher2004/nerdb/postgres/ngrok"
"github.com/urfave/cli/v2"
)
func main() {
app := &cli.App{
Name: "NERDb Database",
Usage: "Manage and run the NERDb Postgres database",
Commands: []*cli.Command{
{
Name: "migrate",
Usage: "Run database migration",
Description: "Runs database migration up to latest migration.",
Action: runMigration,
},
{
Name: "host",
Usage: "Expose Postgres container to ngrok",
Action: grokIt,
},
},
}
if err := app.Run(os.Args); err != nil {
log.Fatal(err)
}
}
func grokIt(ctx *cli.Context) error {
newCtx := context.Background()
token, ok := os.LookupEnv("NGROK_AUTHTOKEN")
if !ok {
return errors.New("NGROK_AUTHTOKEN is not set")
}
return ngrok.Listen(newCtx, token)
}
func runMigration(ctx *cli.Context) error {
dbURL, ok := os.LookupEnv("POSTGRES_URL")
if !ok {
return errors.New("POSTGRES_URL is not set")
}
return migrate.Migrate(dbURL)
}