forked from devfeel/dotweb
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request devfeel#108 from devfeel/develop
Version1.4.8 - 新增Config.IncludeConfigSet,ItemContext更名为ItemMap,新增ConcurrenceMap、ReadonlyMap接口
- Loading branch information
Showing
19 changed files
with
435 additions
and
393 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package config | ||
|
||
import ( | ||
"encoding/xml" | ||
"errors" | ||
"github.com/devfeel/dotweb/core" | ||
"io/ioutil" | ||
) | ||
|
||
type ( | ||
// ConfigSet 单元配置组,包含一系列单元配置节点 | ||
ConfigSet struct { | ||
XMLName xml.Name `xml:"config" json:"-" yaml:"-"` | ||
Name string `xml:"name,attr"` | ||
ConfigSetNodes []*ConfigSetNode `xml:"set"` | ||
} | ||
|
||
// ConfigSetNode update for issue #16 配置文件 | ||
ConfigSetNode struct { | ||
Key string `xml:"key,attr"` | ||
Value string `xml:"value,attr"` | ||
} | ||
) | ||
|
||
// ParseConfigSetXML include ConfigSet xml file | ||
func ParseConfigSetXML(configFile string) (core.ConcurrenceMap, error) { | ||
return parseConfigSetFile(configFile, ConfigType_XML) | ||
} | ||
|
||
// ParseConfigSetJSON include ConfigSet json file | ||
func ParseConfigSetJSON(configFile string) (core.ConcurrenceMap, error) { | ||
return parseConfigSetFile(configFile, ConfigType_JSON) | ||
} | ||
|
||
// ParseConfigSetYaml include ConfigSet yaml file | ||
func ParseConfigSetYaml(configFile string) (core.ConcurrenceMap, error) { | ||
return parseConfigSetFile(configFile, ConfigType_Yaml) | ||
} | ||
|
||
func parseConfigSetFile(configFile string, confType string) (core.ConcurrenceMap, error) { | ||
content, err := ioutil.ReadFile(configFile) | ||
if err != nil { | ||
return nil, errors.New("DotWeb:Config:parseConfigSetFile 配置文件[" + configFile + ", " + confType + "]无法解析 - " + err.Error()) | ||
} | ||
set := new(ConfigSet) | ||
if confType == ConfigType_XML { | ||
err = UnmarshalXML(content, set) | ||
} | ||
if confType == ConfigType_JSON { | ||
err = UnmarshalJSON(content, set) | ||
} | ||
if confType == ConfigType_Yaml { | ||
err = UnmarshalYaml(content, set) | ||
} | ||
if err != nil { | ||
return nil, errors.New("DotWeb:Config:parseConfigSetFile 配置文件[" + configFile + ", " + confType + "]无法解析 - " + err.Error()) | ||
} | ||
item := core.NewConcurrenceMap() | ||
for _, s := range set.ConfigSetNodes { | ||
item.Set(s.Key, s.Value) | ||
} | ||
return item, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,5 +2,5 @@ package _const | |
|
||
//dotweb const | ||
const ( | ||
Version = "1.4.7" | ||
Version = "1.4.8" | ||
) |
Oops, something went wrong.