Repository navigation
Expand file tree
/
Copy pathmetadata_types.go
More file actions
120 lines (108 loc) · 4.3 KB
/
Copy pathmetadata_types.go
File metadata and controls
120 lines (108 loc) · 4.3 KB
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
package glassnode
import (
"encoding/json"
"fmt"
)
// Asset describes a supported blockchain asset or token.
type Asset struct {
ID string `json:"id"`
ExternalIDs map[string]string `json:"external_ids,omitempty"`
Symbol string `json:"symbol"`
Name string `json:"name"`
AssetType string `json:"asset_type"`
Blockchains []Blockchain `json:"blockchains"`
Categories []string `json:"categories,omitempty"`
LogoURL string `json:"logo_url,omitempty"`
SemanticTags []string `json:"semantic_tags,omitempty"`
DefaultNetwork string `json:"default_network,omitempty"`
}
// Blockchain describes a token deployment and on-chain support.
type Blockchain struct {
Blockchain string `json:"blockchain"`
Address string `json:"address,omitempty"`
Decimals int `json:"decimals,omitempty"`
OnChainSupport bool `json:"on_chain_support"`
}
// AssetsResponse is the wire envelope for asset metadata.
type AssetsResponse struct {
Data []Asset `json:"data"`
}
// NamesResponse is the response of the metadata list endpoints
// (/v1/metadata/tags, /v1/metadata/assets/tags, ...): {"data":[{"name":"..."},...]}.
type NamesResponse struct {
Data []NameEntry `json:"data"`
}
// NameEntry is a single named value in a names response.
type NameEntry struct {
Name string `json:"name"`
}
// MetricMetadata describes a metric, its selectors and available variants.
type MetricMetadata struct {
Path string `json:"path,omitempty"`
Tier int `json:"tier,omitempty"`
IsPIT bool `json:"is_pit,omitempty"`
Parameters map[string][]string `json:"parameters"`
ParametersDefaults map[string][]string `json:"parameters_defaults,omitempty"`
Queried map[string]string `json:"queried,omitempty"`
Refs Refs `json:"refs,omitempty"`
BulkSupported bool `json:"bulk_supported"`
TimeRange *TimeRange `json:"timerange,omitempty"`
Modified int64 `json:"modified,omitempty"`
Descriptors *MetricDescriptors `json:"descriptors,omitempty"`
}
// UnmarshalJSON accepts each parameters_defaults value either as a list, as the
// API currently returns it, or as a single string, as the API documentation
// describes it.
func (m *MetricMetadata) UnmarshalJSON(data []byte) error {
type plain MetricMetadata
var wire struct {
*plain
ParametersDefaults map[string]json.RawMessage `json:"parameters_defaults"`
}
wire.plain = (*plain)(m)
if err := json.Unmarshal(data, &wire); err != nil {
return err
}
m.ParametersDefaults = nil
for key, raw := range wire.ParametersDefaults {
var values []string
if err := json.Unmarshal(raw, &values); err != nil {
var value string
if err := json.Unmarshal(raw, &value); err != nil {
return fmt.Errorf("parameters_defaults %q: expected a string or a list of strings", key)
}
values = []string{value}
}
if m.ParametersDefaults == nil {
m.ParametersDefaults = make(map[string][]string, len(wire.ParametersDefaults))
}
m.ParametersDefaults[key] = values
}
return nil
}
// MetricVariant links the base, bulk and point-in-time metric paths.
type MetricVariant struct {
Base *string `json:"base,omitempty"`
Bulk *string `json:"bulk,omitempty"`
PIT *string `json:"pit,omitempty"`
}
// MetricDescriptors contains human-readable metric descriptions.
type MetricDescriptors struct {
Name string `json:"name,omitempty"`
ShortName string `json:"short_name,omitempty"`
Group string `json:"group,omitempty"`
Tags []string `json:"tags,omitempty"`
Description map[string]string `json:"description,omitempty"`
DataSharingGroup string `json:"data_sharing_group,omitempty"`
}
// TimeRange bounds available data in Unix seconds.
type TimeRange struct {
Min int64 `json:"min,omitempty"`
Max int64 `json:"max,omitempty"`
}
// Refs links API documentation, Studio and related metric variants.
type Refs struct {
Docs string `json:"docs,omitempty"`
Studio string `json:"studio,omitempty"`
MetricVariant *MetricVariant `json:"metric_variant,omitempty"`
}