-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
16cd6a3
commit f9a8387
Showing
6 changed files
with
53 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,3 +16,6 @@ key: | |
|
||
cosmos: | ||
addr: "localhost:9090" | ||
|
||
select: | ||
limit: 20 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package config | ||
|
||
import ( | ||
"gitlab.com/distributed_lab/figure" | ||
"gitlab.com/distributed_lab/kit/comfig" | ||
"gitlab.com/distributed_lab/kit/kv" | ||
) | ||
|
||
type Selecter interface { | ||
Limit() uint64 | ||
} | ||
|
||
type selecter struct { | ||
getter kv.Getter | ||
once comfig.Once | ||
} | ||
|
||
func NewSelecter(getter kv.Getter) Selecter { | ||
return &selecter{ | ||
getter: getter, | ||
} | ||
} | ||
|
||
func (s *selecter) Limit() uint64 { | ||
return s.once.Do(func() interface{} { | ||
var config struct { | ||
Limit uint64 `fig:"limit"` | ||
} | ||
|
||
if err := figure.Out(&config).From(kv.MustGetStringMap(s.getter, "select")).Please(); err != nil { | ||
panic(err) | ||
} | ||
|
||
return config.Limit | ||
}).(uint64) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters