-
Notifications
You must be signed in to change notification settings - Fork 14
/
verify.go
55 lines (41 loc) · 1.14 KB
/
verify.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
package command
import (
"context"
"github.com/avenga/couper/cache"
"github.com/avenga/couper/config"
"github.com/avenga/couper/config/configload"
"github.com/avenga/couper/config/runtime"
"github.com/hashicorp/hcl/v2"
"github.com/sirupsen/logrus"
)
var _ Cmd = &Verify{}
type Verify struct{}
func NewVerify() *Verify {
return &Verify{}
}
func (v Verify) Execute(args Args, conf *config.Couper, logger *logrus.Entry) error {
cf, err := configload.LoadFiles(args, conf.Environment)
if diags, ok := err.(hcl.Diagnostics); ok {
for _, diag := range diags {
logger.WithError(diag).Error()
}
return diags
} else if err != nil {
logger.WithError(err).Error()
return err
}
tmpStoreCh := make(chan struct{})
defer close(tmpStoreCh)
tmpMemStore := cache.New(logger, tmpStoreCh)
ctx, cancel := context.WithCancel(cf.Context)
cf.Context = ctx
defer cancel()
_, err = runtime.NewServerConfiguration(cf, logger, tmpMemStore)
if err != nil {
logger.WithError(err).Error()
}
return err
}
func (v Verify) Usage() {
println("Usage of verify:\n verify [-f <file>] [-d <dir>] Verify the syntax of the given configuration file(s).")
}