代码拉取完成,页面将自动刷新
同步操作将从 K./go-adm 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
package adm
import (
"encoding/xml"
"fmt"
"bytes"
"git.oschina.net/janpoem/go-agi"
)
type XmlConfig struct {
XMLName xml.Name `xml:"databases"`
Dbs []XmlDb `xml:"database"`
}
type XmlDb struct {
XMLName xml.Name `xml:"database"`
DSN string `xml:"dsn,attr"`
Name string `xml:"name,attr"`
Host string `xml:"host"`
Port int `xml:"port"`
Db string `xml:"db"`
User string `xml:"user"`
Password string `xml:"password"`
MaxConn int `xml:"maxConn"`
MaxIdle int `xml:"maxIdle"`
Charset string `xml:"charset"`
Options []XmlDbOps `xml:"option"`
}
type XmlDbOps struct {
XMLName xml.Name `xml:"option"`
Name string `xml:"name,attr"`
Value string `xml:"value,attr"`
}
var dbConfigs = make(map[string]*XmlDb)
func LoadConf(path string) {
data, err := agi.ReadFileByte(path)
if err != nil {
fmt.Println(err)
} else {
config := XmlConfig{}
err = xml.Unmarshal(data, &config)
for i, len := 0, len(config.Dbs); i < len; i++ {
addDbConf(&config.Dbs[i])
}
}
}
func addDbConf(db *XmlDb) {
_, exists := dbConfigs[db.Name]
if !exists {
dbConfigs[db.Name] = db
}
}
func GetConf(name string) (*XmlDb) {
item, exists := dbConfigs[name]
if exists {
return item
}
return nil
}
func (this *XmlDb) GetPort() (int) {
port := this.Port
if port <= 0 {
port = 3306
}
return port
}
func (this *XmlDb) GetCharset() (string) {
if len(this.Charset) <= 0 {
return "utf8"
}
return this.Charset
}
func (this *XmlDb) GetOpsStr() (string) {
i, l := 0, len(this.Options)
buffer := bytes.NewBufferString("charset=" + this.GetCharset())
for ; i < l; i++ {
buffer.WriteString("&")
buffer.WriteString(this.Options[i].Name + "=" + this.Options[i].Value)
}
return buffer.String()
}
func (this *XmlDb) GetConnDSN() (string) {
return fmt.Sprintf("%s:%s@tcp(%s:%d)/%s?%s", this.User, this.Password, this.Host, this.GetPort(), this.Db, this.GetOpsStr())
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。