mirror of
https://github.com/astaxie/beego.git
synced 2024-11-21 21:40:55 +00:00
Move init so it will be default implementation of config
This commit is contained in:
parent
7fc1e4de96
commit
f9a3eae9d5
@ -12,7 +12,7 @@
|
|||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
package ini
|
package config
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
@ -26,8 +26,6 @@ import (
|
|||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/astaxie/beego/pkg/config"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@ -47,7 +45,7 @@ type IniConfig struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Parse creates a new Config and parses the file configuration from the named file.
|
// 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)
|
return ini.parseFile(name)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -197,7 +195,7 @@ func (ini *IniConfig) parseData(dir string, data []byte) (*IniConfigContainer, e
|
|||||||
val = bytes.Trim(val, `"`)
|
val = bytes.Trim(val, `"`)
|
||||||
}
|
}
|
||||||
|
|
||||||
cfg.data[section][key] = config.ExpandValueEnv(string(val))
|
cfg.data[section][key] = ExpandValueEnv(string(val))
|
||||||
if comment.Len() > 0 {
|
if comment.Len() > 0 {
|
||||||
cfg.keyComment[section+"."+key] = comment.String()
|
cfg.keyComment[section+"."+key] = comment.String()
|
||||||
comment.Reset()
|
comment.Reset()
|
||||||
@ -210,7 +208,7 @@ func (ini *IniConfig) parseData(dir string, data []byte) (*IniConfigContainer, e
|
|||||||
// ParseData parse ini the data
|
// ParseData parse ini the data
|
||||||
// When include other.conf,other.conf is either absolute directory
|
// When include other.conf,other.conf is either absolute directory
|
||||||
// or under beego in default temporary directory(/tmp/beego[-username]).
|
// 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"
|
dir := "beego"
|
||||||
currentUser, err := user.Current()
|
currentUser, err := user.Current()
|
||||||
if err == nil {
|
if err == nil {
|
||||||
@ -235,7 +233,7 @@ type IniConfigContainer struct {
|
|||||||
|
|
||||||
// Bool returns the boolean value for a given key.
|
// Bool returns the boolean value for a given key.
|
||||||
func (c *IniConfigContainer) Bool(key string) (bool, error) {
|
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.
|
// DefaultBool returns the boolean value for a given key.
|
||||||
@ -502,5 +500,5 @@ func (c *IniConfigContainer) getdata(key string) string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
config.Register("ini", &IniConfig{})
|
Register("ini", &IniConfig{})
|
||||||
}
|
}
|
@ -12,7 +12,7 @@
|
|||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
package ini
|
package config
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
@ -20,8 +20,6 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/astaxie/beego/pkg/config"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestIni(t *testing.T) {
|
func TestIni(t *testing.T) {
|
||||||
@ -94,7 +92,7 @@ password = ${GOPATH}
|
|||||||
}
|
}
|
||||||
f.Close()
|
f.Close()
|
||||||
defer os.Remove("testini.conf")
|
defer os.Remove("testini.conf")
|
||||||
iniconf, err := config.NewConfig("ini", "testini.conf")
|
iniconf, err := NewConfig("ini", "testini.conf")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
@ -167,7 +165,7 @@ httpport=8080
|
|||||||
name=mysql
|
name=mysql
|
||||||
`
|
`
|
||||||
)
|
)
|
||||||
cfg, err := config.NewConfigData("ini", []byte(inicontext))
|
cfg, err := NewConfigData("ini", []byte(inicontext))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user