File tree Expand file tree Collapse file tree 2 files changed +43
-10
lines changed Expand file tree Collapse file tree 2 files changed +43
-10
lines changed Original file line number Diff line number Diff line change 1+ package config
2+
3+ // Alias - type for aliasing in config
4+ type Alias [Type any ] struct {
5+ name string
6+ entity Type
7+ }
8+
9+ // UnmarshalYAML -
10+ func (a * Alias [Type ]) UnmarshalYAML (unmarshal func (interface {}) error ) error {
11+ if err := unmarshal (& a .name ); err == nil {
12+ return nil
13+ }
14+
15+ var typ Type
16+ if err := unmarshal (& typ ); err != nil {
17+ return err
18+ }
19+ a .entity = typ
20+ return nil
21+ }
22+
23+ // Name - returns alias name if it exists
24+ func (a * Alias [Type ]) Name () string {
25+ return a .name
26+ }
27+
28+ // Struct - returns substitute struct
29+ func (a * Alias [Type ]) Struct () Type {
30+ return a .entity
31+ }
32+
33+ // SetStruct - set entity. Use in Substitute
34+ func (a * Alias [Type ]) SetStruct (entity Type ) {
35+ a .entity = entity
36+ }
Original file line number Diff line number Diff line change @@ -21,9 +21,6 @@ type Config struct {
2121
2222// Substitute -
2323func (c * Config ) Substitute () error {
24- if c .Hasura != nil {
25- c .Hasura .SetSourceName ()
26- }
2724 return nil
2825}
2926
@@ -32,6 +29,7 @@ type DataSource struct {
3229 Kind string `yaml:"kind"`
3330 URL string `yaml:"url" validate:"required,url"`
3431 Credentials * Credentials `yaml:"credentials,omitempty" validate:"omitempty"`
32+ Timeout uint `yaml:"timeout" validate:"omitempty"`
3533}
3634
3735// Contracts -
@@ -63,13 +61,12 @@ type Hasura struct {
6361 Rest * bool `yaml:"rest"`
6462}
6563
66- func (s * Hasura ) SetSourceName () {
67- if s == nil {
68- return
69- }
70- if s .Source == "" {
71- s .Source = "default"
72- }
64+ // UnmarshalYAML -
65+ func (h * Hasura ) UnmarshalYAML (unmarshal func (interface {}) error ) error {
66+ h .Source = "default"
67+
68+ type plain Hasura
69+ return unmarshal ((* plain )(h ))
7370}
7471
7572// Prometheus -
You can’t perform that action at this time.
0 commit comments