-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.go
59 lines (53 loc) · 1.3 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
58
59
package main
import (
"fmt"
"os"
"github.com/FACT-Finder/noflake/api"
"github.com/FACT-Finder/noflake/database"
"github.com/FACT-Finder/noflake/logger"
"github.com/FACT-Finder/noflake/server"
"github.com/rs/zerolog"
"github.com/rs/zerolog/log"
"github.com/urfave/cli/v2"
)
//go:generate oapi-codegen -config ./openapi-gen.yml openapi.yaml
func main() {
logger.Init(zerolog.InfoLevel)
app := &cli.App{
Name: "noflake",
Flags: []cli.Flag{
&cli.StringFlag{
Name: "address",
Usage: "the address to listen on",
EnvVars: []string{"NOFLAKE_ADDRESS"},
Value: ":8000",
},
&cli.StringFlag{
Name: "db",
Usage: "the path to the sqlite database",
EnvVars: []string{"NOFLAKE_DB"},
Value: "noflake.sqlite3",
},
&cli.StringFlag{
Name: "token",
Usage: "token to secure the POST endpoints",
EnvVars: []string{"NOFLAKE_TOKEN"},
Required: true,
},
},
Action: func(c *cli.Context) error {
db := database.New(c.String("db"))
token := c.String("token")
webapi := api.New(db, token)
listenAddr := c.String("address")
log.Info().Str("address", listenAddr).Msg("HTTP")
err := server.Start(webapi, listenAddr)
return err
},
}
err := app.Run(os.Args)
if err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
}