-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
56 lines (49 loc) · 2.07 KB
/
config.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
package directive
import (
"fmt"
"github.com/goccy/go-yaml"
"github.com/vektah/gqlparser/v2/ast"
"io"
)
type Config struct {
Analyzer []*AnalyzerConfig `yaml:"analyzer"`
}
type AnalyzerConfig struct {
AnalyzerName string `yaml:"analyzer_name"`
Description string `yaml:"description"`
DefinitionConfig []*DefinitionConfig `yaml:"definition"`
FieldConfig []*FieldConfig `yaml:"field"`
ArgumentConfig []*ArgumentConfig `yaml:"argument"`
}
type DefinitionConfig struct {
Description string `yaml:"description"`
Directive string `yaml:"directive"`
Kinds []ast.DefinitionKind `yaml:"kind"`
DefinitionPatterns []string `yaml:"definition"`
ExcludeDefinitionPatterns []string `yaml:"exclude_definition"`
ReportFormat string `yaml:"report_format"`
}
type FieldConfig struct {
Description string `yaml:"description"`
Directive string `yaml:"directive"`
Kinds []ast.DefinitionKind `yaml:"kind"`
FieldParentTypePatterns []string `yaml:"field_parent_type"`
FieldTypePatterns []string `yaml:"field_type"`
ExcludeFieldPatterns []string `yaml:"exclude_field"`
ReportFormat string `yaml:"report_format"`
}
type ArgumentConfig struct {
Description string `yaml:"description"`
Directive string `yaml:"directive"`
Kinds []ast.DefinitionKind `yaml:"kind"`
ArgumentTypePatterns []string `yaml:"argument_type"`
ExcludeArgumentPatterns []string `yaml:"exclude_argument"`
ReportFormat string `yaml:"report_format"`
}
func ParseConfigFile(configFile io.Reader) (*Config, error) {
var config Config
if err := yaml.NewDecoder(configFile).Decode(&config); err != nil {
return nil, fmt.Errorf("failed to decode config file: %w", err)
}
return &config, nil
}