-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
57 lines (48 loc) · 1.35 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"
"fmt"
"os"
"github.com/awlsring/texit/internal/app/ui/adapters/primary/cli"
"github.com/awlsring/texit/internal/app/ui/adapters/primary/cli/handler"
api_gateway "github.com/awlsring/texit/internal/app/ui/adapters/secondary/gateway/api"
"github.com/awlsring/texit/internal/app/ui/core/service/api"
"github.com/awlsring/texit/pkg/gen/texit"
)
func panicOnErr(err error) {
if err != nil {
panic(err)
}
}
type Sec struct {
key string
}
func (s Sec) SmithyAPIHttpApiKeyAuth(ctx context.Context, operationName string) (texit.SmithyAPIHttpApiKeyAuth, error) {
return texit.SmithyAPIHttpApiKeyAuth{
APIKey: s.key,
}, nil
}
func initClient(address string, key string) texit.Invoker {
c, err := texit.NewClient(address, Sec{key: key})
panicOnErr(err)
return c
}
func isInitCommand(args []string) bool {
return len(args) > 1 && args[1] == "init"
}
func main() {
if isInitCommand(os.Args) {
cli.InitDefaultConfig()
fmt.Println("Texit default config has been initialized. Please edit the file at ~/.texit/config.yaml to set your server address and api key.")
return
}
cli.MakeTexitDir()
cfg, err := cli.LoadConfig()
panicOnErr(err)
client := initClient(cfg.Api.Address, cfg.Api.ApiKey)
apiGw := api_gateway.New(client)
svc := api.NewService(apiGw)
hdl := handler.New(svc)
tool := cli.New(hdl)
panicOnErr(tool.Run())
}