-
-
Notifications
You must be signed in to change notification settings - Fork 191
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
5 changed files
with
115 additions
and
33 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,48 @@ | ||
package agollo | ||
|
||
import ( | ||
"fmt" | ||
"github.com/zouyx/agollo/agcache" | ||
) | ||
|
||
const propertiesFormat ="%s=%s\n" | ||
|
||
//ContentParser 内容转换 | ||
type ContentParser interface { | ||
parse(cache agcache.CacheInterface) (string,error) | ||
} | ||
|
||
//DefaultParser 默认内容转换器 | ||
type DefaultParser struct { | ||
|
||
} | ||
|
||
func (d *DefaultParser)parse(cache agcache.CacheInterface) (string,error){ | ||
value, err := cache.Get(defaultContentKey) | ||
if err!=nil{ | ||
return "",err | ||
} | ||
return string(value),nil | ||
} | ||
|
||
//PropertiesParser properties转换器 | ||
type PropertiesParser struct { | ||
|
||
} | ||
|
||
func (d *PropertiesParser)parse(cache agcache.CacheInterface) (string,error){ | ||
properties := convertToProperties(cache) | ||
return properties,nil | ||
} | ||
|
||
func convertToProperties(cache agcache.CacheInterface) string { | ||
properties:="" | ||
if cache==nil { | ||
return properties | ||
} | ||
cache.Range(func(key, value interface{}) bool { | ||
properties+=fmt.Sprintf(propertiesFormat,key,string(value.([]byte))) | ||
return true | ||
}) | ||
return properties | ||
} |
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