1
0
mirror of https://github.com/astaxie/beego.git synced 2024-11-15 07:40:56 +00:00
Beego/adapter/config/adapter.go

192 lines
5.4 KiB
Go
Raw Normal View History

2020-09-01 13:25:29 +00:00
// Copyright 2020
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package config
import (
"github.com/pkg/errors"
"github.com/astaxie/beego/core/config"
2020-09-01 13:25:29 +00:00
)
type newToOldConfigerAdapter struct {
delegate config.Configer
}
func (c *newToOldConfigerAdapter) Set(key, val string) error {
2020-10-13 14:32:41 +00:00
return c.delegate.Set(key, val)
2020-09-01 13:25:29 +00:00
}
func (c *newToOldConfigerAdapter) String(key string) string {
2020-10-13 14:32:41 +00:00
res, _ := c.delegate.String(key)
2020-09-01 13:25:29 +00:00
return res
}
func (c *newToOldConfigerAdapter) Strings(key string) []string {
2020-10-13 14:32:41 +00:00
res, _ := c.delegate.Strings(key)
2020-09-01 13:25:29 +00:00
return res
}
func (c *newToOldConfigerAdapter) Int(key string) (int, error) {
2020-10-13 14:32:41 +00:00
return c.delegate.Int(key)
2020-09-01 13:25:29 +00:00
}
func (c *newToOldConfigerAdapter) Int64(key string) (int64, error) {
2020-10-13 14:32:41 +00:00
return c.delegate.Int64(key)
2020-09-01 13:25:29 +00:00
}
func (c *newToOldConfigerAdapter) Bool(key string) (bool, error) {
2020-10-13 14:32:41 +00:00
return c.delegate.Bool(key)
2020-09-01 13:25:29 +00:00
}
func (c *newToOldConfigerAdapter) Float(key string) (float64, error) {
2020-10-13 14:32:41 +00:00
return c.delegate.Float(key)
2020-09-01 13:25:29 +00:00
}
func (c *newToOldConfigerAdapter) DefaultString(key string, defaultVal string) string {
2020-10-13 14:32:41 +00:00
return c.delegate.DefaultString(key, defaultVal)
2020-09-01 13:25:29 +00:00
}
func (c *newToOldConfigerAdapter) DefaultStrings(key string, defaultVal []string) []string {
2020-10-13 14:32:41 +00:00
return c.delegate.DefaultStrings(key, defaultVal)
2020-09-01 13:25:29 +00:00
}
func (c *newToOldConfigerAdapter) DefaultInt(key string, defaultVal int) int {
2020-10-13 14:32:41 +00:00
return c.delegate.DefaultInt(key, defaultVal)
2020-09-01 13:25:29 +00:00
}
func (c *newToOldConfigerAdapter) DefaultInt64(key string, defaultVal int64) int64 {
2020-10-13 14:32:41 +00:00
return c.delegate.DefaultInt64(key, defaultVal)
2020-09-01 13:25:29 +00:00
}
func (c *newToOldConfigerAdapter) DefaultBool(key string, defaultVal bool) bool {
2020-10-13 14:32:41 +00:00
return c.delegate.DefaultBool(key, defaultVal)
2020-09-01 13:25:29 +00:00
}
func (c *newToOldConfigerAdapter) DefaultFloat(key string, defaultVal float64) float64 {
2020-10-13 14:32:41 +00:00
return c.delegate.DefaultFloat(key, defaultVal)
2020-09-01 13:25:29 +00:00
}
func (c *newToOldConfigerAdapter) DIY(key string) (interface{}, error) {
2020-10-13 14:32:41 +00:00
return c.delegate.DIY(key)
2020-09-01 13:25:29 +00:00
}
func (c *newToOldConfigerAdapter) GetSection(section string) (map[string]string, error) {
2020-10-13 14:32:41 +00:00
return c.delegate.GetSection(section)
2020-09-01 13:25:29 +00:00
}
func (c *newToOldConfigerAdapter) SaveConfigFile(filename string) error {
2020-10-13 14:32:41 +00:00
return c.delegate.SaveConfigFile(filename)
2020-09-01 13:25:29 +00:00
}
type oldToNewConfigerAdapter struct {
delegate Configer
}
2020-10-13 14:32:41 +00:00
func (o *oldToNewConfigerAdapter) Set(key, val string) error {
2020-09-01 13:25:29 +00:00
return o.delegate.Set(key, val)
}
2020-10-13 14:32:41 +00:00
func (o *oldToNewConfigerAdapter) String(key string) (string, error) {
2020-09-01 13:25:29 +00:00
return o.delegate.String(key), nil
}
2020-10-13 14:32:41 +00:00
func (o *oldToNewConfigerAdapter) Strings(key string) ([]string, error) {
2020-09-01 13:25:29 +00:00
return o.delegate.Strings(key), nil
}
2020-10-13 14:32:41 +00:00
func (o *oldToNewConfigerAdapter) Int(key string) (int, error) {
2020-09-01 13:25:29 +00:00
return o.delegate.Int(key)
}
2020-10-13 14:32:41 +00:00
func (o *oldToNewConfigerAdapter) Int64(key string) (int64, error) {
2020-09-01 13:25:29 +00:00
return o.delegate.Int64(key)
}
2020-10-13 14:32:41 +00:00
func (o *oldToNewConfigerAdapter) Bool(key string) (bool, error) {
2020-09-01 13:25:29 +00:00
return o.delegate.Bool(key)
}
2020-10-13 14:32:41 +00:00
func (o *oldToNewConfigerAdapter) Float(key string) (float64, error) {
2020-09-01 13:25:29 +00:00
return o.delegate.Float(key)
}
2020-10-13 14:32:41 +00:00
func (o *oldToNewConfigerAdapter) DefaultString(key string, defaultVal string) string {
2020-09-01 13:25:29 +00:00
return o.delegate.DefaultString(key, defaultVal)
}
2020-10-13 14:32:41 +00:00
func (o *oldToNewConfigerAdapter) DefaultStrings(key string, defaultVal []string) []string {
2020-09-01 13:25:29 +00:00
return o.delegate.DefaultStrings(key, defaultVal)
}
2020-10-13 14:32:41 +00:00
func (o *oldToNewConfigerAdapter) DefaultInt(key string, defaultVal int) int {
2020-09-01 13:25:29 +00:00
return o.delegate.DefaultInt(key, defaultVal)
}
2020-10-13 14:32:41 +00:00
func (o *oldToNewConfigerAdapter) DefaultInt64(key string, defaultVal int64) int64 {
2020-09-01 13:25:29 +00:00
return o.delegate.DefaultInt64(key, defaultVal)
}
2020-10-13 14:32:41 +00:00
func (o *oldToNewConfigerAdapter) DefaultBool(key string, defaultVal bool) bool {
2020-09-01 13:25:29 +00:00
return o.delegate.DefaultBool(key, defaultVal)
}
2020-10-13 14:32:41 +00:00
func (o *oldToNewConfigerAdapter) DefaultFloat(key string, defaultVal float64) float64 {
2020-09-01 13:25:29 +00:00
return o.delegate.DefaultFloat(key, defaultVal)
}
2020-10-13 14:32:41 +00:00
func (o *oldToNewConfigerAdapter) DIY(key string) (interface{}, error) {
2020-09-01 13:25:29 +00:00
return o.delegate.DIY(key)
}
2020-10-13 14:32:41 +00:00
func (o *oldToNewConfigerAdapter) GetSection(section string) (map[string]string, error) {
2020-09-01 13:25:29 +00:00
return o.delegate.GetSection(section)
}
2020-10-13 14:32:41 +00:00
func (o *oldToNewConfigerAdapter) Unmarshaler(prefix string, obj interface{}, opt ...config.DecodeOption) error {
2020-09-01 13:25:29 +00:00
return errors.New("unsupported operation, please use actual config.Configer")
}
2020-10-13 14:32:41 +00:00
func (o *oldToNewConfigerAdapter) Sub(key string) (config.Configer, error) {
2020-09-01 13:25:29 +00:00
return nil, errors.New("unsupported operation, please use actual config.Configer")
}
2020-10-13 14:32:41 +00:00
func (o *oldToNewConfigerAdapter) OnChange(key string, fn func(value string)) {
2020-09-01 13:25:29 +00:00
// do nothing
}
2020-10-13 14:32:41 +00:00
func (o *oldToNewConfigerAdapter) SaveConfigFile(filename string) error {
2020-09-01 13:25:29 +00:00
return o.delegate.SaveConfigFile(filename)
}
type oldToNewConfigAdapter struct {
delegate Config
}
func (o *oldToNewConfigAdapter) Parse(key string) (config.Configer, error) {
old, err := o.delegate.Parse(key)
if err != nil {
return nil, err
}
return &oldToNewConfigerAdapter{delegate: old}, nil
}
func (o *oldToNewConfigAdapter) ParseData(data []byte) (config.Configer, error) {
old, err := o.delegate.ParseData(data)
if err != nil {
return nil, err
}
return &oldToNewConfigerAdapter{delegate: old}, nil
}