Move init so it will be default implementation of config

This commit is contained in:
Ming Deng 2020-08-08 13:17:49 +00:00
parent 7fc1e4de96
commit f9a3eae9d5
2 changed files with 9 additions and 13 deletions

View File

@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
package ini
package config
import (
"bufio"
@ -26,8 +26,6 @@ import (
"strconv"
"strings"
"sync"
"github.com/astaxie/beego/pkg/config"
)
var (
@ -47,7 +45,7 @@ type IniConfig struct {
}
// Parse creates a new Config and parses the file configuration from the named file.
func (ini *IniConfig) Parse(name string) (config.Configer, error) {
func (ini *IniConfig) Parse(name string) (Configer, error) {
return ini.parseFile(name)
}
@ -197,7 +195,7 @@ func (ini *IniConfig) parseData(dir string, data []byte) (*IniConfigContainer, e
val = bytes.Trim(val, `"`)
}
cfg.data[section][key] = config.ExpandValueEnv(string(val))
cfg.data[section][key] = ExpandValueEnv(string(val))
if comment.Len() > 0 {
cfg.keyComment[section+"."+key] = comment.String()
comment.Reset()
@ -210,7 +208,7 @@ func (ini *IniConfig) parseData(dir string, data []byte) (*IniConfigContainer, e
// ParseData parse ini the data
// When include other.conf,other.conf is either absolute directory
// or under beego in default temporary directory(/tmp/beego[-username]).
func (ini *IniConfig) ParseData(data []byte) (config.Configer, error) {
func (ini *IniConfig) ParseData(data []byte) (Configer, error) {
dir := "beego"
currentUser, err := user.Current()
if err == nil {
@ -235,7 +233,7 @@ type IniConfigContainer struct {
// Bool returns the boolean value for a given key.
func (c *IniConfigContainer) Bool(key string) (bool, error) {
return config.ParseBool(c.getdata(key))
return ParseBool(c.getdata(key))
}
// DefaultBool returns the boolean value for a given key.
@ -502,5 +500,5 @@ func (c *IniConfigContainer) getdata(key string) string {
}
func init() {
config.Register("ini", &IniConfig{})
Register("ini", &IniConfig{})
}

View File

@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
package ini
package config
import (
"fmt"
@ -20,8 +20,6 @@ import (
"os"
"strings"
"testing"
"github.com/astaxie/beego/pkg/config"
)
func TestIni(t *testing.T) {
@ -94,7 +92,7 @@ password = ${GOPATH}
}
f.Close()
defer os.Remove("testini.conf")
iniconf, err := config.NewConfig("ini", "testini.conf")
iniconf, err := NewConfig("ini", "testini.conf")
if err != nil {
t.Fatal(err)
}
@ -167,7 +165,7 @@ httpport=8080
name=mysql
`
)
cfg, err := config.NewConfigData("ini", []byte(inicontext))
cfg, err := NewConfigData("ini", []byte(inicontext))
if err != nil {
t.Fatal(err)
}