-
Notifications
You must be signed in to change notification settings - Fork 557
/
queryyml.go
62 lines (52 loc) · 1.47 KB
/
queryyml.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
package templates
import (
"io/ioutil"
"strings"
"gopkg.in/yaml.v3"
)
type QueryYml struct {
// Keeper struct descriptor
Keeper Keeper `yaml:"keeper"`
// Path to client folder e.g. "github.com/osmosis-labs/osmosis/v12/x/twap/client"
ClientPath string `yaml:"client_path"`
// list of all queries, key is the query name, e.g. `GetArithmeticTwap`
Queries map[string]YmlQueryDescriptor `yaml:"queries"`
protoPath string
}
type Keeper struct {
// e.g. github.com/osmosis-labs/osmosis/v12/x/twap
Path string `yaml:"path"`
// e.g. Keeper
Struct string `yaml:"struct"`
}
type YmlQueryDescriptor struct {
ProtoWrapper *ProtoWrapperDescriptor `yaml:"proto_wrapper,omitempty"`
Cli *CliDescriptor
}
type ProtoWrapperDescriptor struct {
DefaultValues map[string]string `yaml:"default_values"`
QueryFunc string `yaml:"query_func"`
Response string
}
type CliDescriptor struct {
}
func ReadYmlFile(filepath string) (QueryYml, error) {
content, err := ioutil.ReadFile(filepath) // the file is inside the local directory
if err != nil {
return QueryYml{}, err
}
var query QueryYml
err = yaml.Unmarshal(content, &query)
if err != nil {
return QueryYml{}, err
}
query.protoPath = filepath
return query, nil
}
// input is of form github.com/osmosis-labs/osmosis/vXX/{PATH}
// returns PATH
func ParseFilePathFromImportPath(importPath string) string {
splits := strings.Split(importPath, "/")
pathSplits := splits[4:]
return strings.Join(pathSplits, "/")
}