forked from apolloconfig/agollo
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
26 changed files
with
697 additions
and
257 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
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,19 @@ | ||
package constant | ||
|
||
//ConfigFileFormat 配置文件类型 | ||
type ConfigFileFormat string | ||
|
||
const ( | ||
//Properties Properties | ||
Properties ConfigFileFormat = ".properties" | ||
//XML XML | ||
XML ConfigFileFormat = ".xml" | ||
//JSON JSON | ||
JSON ConfigFileFormat = ".json" | ||
//YML YML | ||
YML ConfigFileFormat = ".yml" | ||
//YAML YAML | ||
YAML ConfigFileFormat = ".yaml" | ||
// DEFAULT DEFAULT | ||
DEFAULT ConfigFileFormat = ".default" | ||
) |
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
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,18 @@ | ||
package extension | ||
|
||
import ( | ||
"github.com/zouyx/agollo/v3/constant" | ||
"github.com/zouyx/agollo/v3/utils/parse" | ||
) | ||
|
||
var formatParser = make(map[constant.ConfigFileFormat]parse.ContentParser, 0) | ||
|
||
// AddFormatParser 设置 formatParser | ||
func AddFormatParser(key constant.ConfigFileFormat, contentParser parse.ContentParser) { | ||
formatParser[key] = contentParser | ||
} | ||
|
||
// GetFormatParser 获取 formatParser | ||
func GetFormatParser(key constant.ConfigFileFormat) parse.ContentParser { | ||
return formatParser[key] | ||
} |
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,29 @@ | ||
package extension | ||
|
||
import ( | ||
"github.com/zouyx/agollo/v3/constant" | ||
"testing" | ||
|
||
. "github.com/tevid/gohamcrest" | ||
) | ||
|
||
// TestParser 默认内容转换器 | ||
type TestParser struct { | ||
} | ||
|
||
// Parse 内存内容默认转换器 | ||
func (d *TestParser) Parse(s string) (map[string]string, error) { | ||
return nil, nil | ||
} | ||
|
||
func TestAddFormatParser(t *testing.T) { | ||
AddFormatParser(constant.DEFAULT, &TestParser{}) | ||
AddFormatParser(constant.Properties, &TestParser{}) | ||
|
||
p := GetFormatParser(constant.DEFAULT) | ||
|
||
b := p.(*TestParser) | ||
Assert(t, b, NotNilVal()) | ||
|
||
Assert(t, len(formatParser), Equal(2)) | ||
} |
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 |
---|---|---|
@@ -1,5 +1,8 @@ | ||
module github.com/zouyx/agollo/v3 | ||
|
||
require github.com/tevid/gohamcrest v1.1.1 | ||
require ( | ||
github.com/spf13/viper v1.7.0 | ||
github.com/tevid/gohamcrest v1.1.1 | ||
) | ||
|
||
go 1.13 |
Oops, something went wrong.