12345678910111213141516171819202122232425262728293031323334353637383940 |
- package reader
- import (
- "gogs.baozhida.cn/zoie/OAuth-core/config/encoder"
- "gogs.baozhida.cn/zoie/OAuth-core/config/encoder/json"
- "gogs.baozhida.cn/zoie/OAuth-core/config/encoder/toml"
- "gogs.baozhida.cn/zoie/OAuth-core/config/encoder/xml"
- "gogs.baozhida.cn/zoie/OAuth-core/config/encoder/yaml"
- )
- type Options struct {
- Encoding map[string]encoder.Encoder
- }
- type Option func(o *Options)
- func NewOptions(opts ...Option) Options {
- options := Options{
- Encoding: map[string]encoder.Encoder{
- "json": json.NewEncoder(),
- "yaml": yaml.NewEncoder(),
- "toml": toml.NewEncoder(),
- "xml": xml.NewEncoder(),
- "yml": yaml.NewEncoder(),
- },
- }
- for _, o := range opts {
- o(&options)
- }
- return options
- }
- func WithEncoder(e encoder.Encoder) Option {
- return func(o *Options) {
- if o.Encoding == nil {
- o.Encoding = make(map[string]encoder.Encoder)
- }
- o.Encoding[e.String()] = e
- }
- }
|