-
Notifications
You must be signed in to change notification settings - Fork 9
/
object.go
91 lines (78 loc) · 1.92 KB
/
object.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
package upload
import (
"encoding/json"
"fmt"
"github.com/mitchellh/mapstructure"
"github.com/opensibyl/sibyl2"
)
const (
configFile = "sibyl-upload-config"
configType = "json"
)
type SrcConfigPart struct {
RepoId string `mapstructure:"repoId"`
RevHash string `mapstructure:"revHash"`
Src string `mapstructure:"src"`
Lang []string `mapstructure:"lang"`
WithCtx bool `mapstructure:"withCtx"`
WithClass bool `mapstructure:"withClass"`
IncludeRegex string `mapstructure:"includeRegex"`
ExcludeRegex string `mapstructure:"excludeRegex"`
}
type ServerConfigPart struct {
Url string `mapstructure:"url"`
Batch int `mapstructure:"batch"`
Dry bool `mapstructure:"dry"`
Depth int `mapstructure:"depth"`
}
type ContextPart struct {
GraphCache *sibyl2.FuncGraph
}
type Config struct {
*SrcConfigPart `mapstructure:"src"`
*ServerConfigPart `mapstructure:"server"`
}
func (config *Config) ToMap() (map[string]any, error) {
var m map[string]interface{}
err := mapstructure.Decode(config, &m)
if err != nil {
return nil, err
}
return m, nil
}
func (config *Config) ToJson() ([]byte, error) {
toMap, err := config.ToMap()
if err != nil {
return nil, err
}
return json.Marshal(toMap)
}
func (config *Config) GetFuncUploadUrl() string {
return fmt.Sprintf("%s/api/v1/func", config.Url)
}
func (config *Config) GetClazzUploadUrl() string {
return fmt.Sprintf("%s/api/v1/clazz", config.Url)
}
func (config *Config) GetFuncCtxUploadUrl() string {
return fmt.Sprintf("%s/api/v1/funcctx", config.Url)
}
func DefaultConfig() *Config {
return &Config{
&SrcConfigPart{
RepoId: "",
RevHash: "",
Src: ".",
Lang: []string{},
WithCtx: true,
WithClass: true,
IncludeRegex: "",
ExcludeRegex: "",
},
&ServerConfigPart{
Url: "http://127.0.0.1:9876",
Batch: 50,
Dry: false,
Depth: 1,
},
}
}