-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.go
66 lines (52 loc) · 1.15 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
60
61
62
63
64
65
66
// Copyright (C) 2021 Storj Labs, Inc.
// See LICENSE for copying information.
package main
import (
"context"
"github.com/elek/docker-storj-extension/backend"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
"go.uber.org/zap"
"log"
"storj.io/private/cfgstruct"
)
// Flags contains app configuration.
var Flags struct {
Config backend.Config
}
func init() {
cfgstruct.Bind(pflag.CommandLine, &Flags)
}
func main() {
pflag.Parse()
c := cobra.Command{}
run := cobra.Command{
Use: "run",
RunE: func(cmd *cobra.Command, args []string) error {
return runServer(context.Background(), Flags.Config)
},
}
c.AddCommand(&run)
dp := cobra.Command{
Use: "dispatch",
RunE: func(cmd *cobra.Command, args []string) error {
n := backend.NewCliDispatcher()
return n.Dispatch(args[0], args[1:])
},
}
c.AddCommand(&dp)
err := c.Execute()
if err != nil {
log.Fatalf("%++v", err)
}
}
func runServer(ctx context.Context, config backend.Config) error {
logger := zap.NewExample()
app, err := backend.NewApp(logger.Named("storj-extension"), config)
if err != nil {
return err
}
runErr := app.Run(ctx)
defer app.Close()
return runErr
}