aboutsummaryrefslogtreecommitdiffstats
path: root/repository/config_mem.go
diff options
context:
space:
mode:
authorMichael Muré <batolettre@gmail.com>2019-12-08 21:15:06 +0100
committerMichael Muré <batolettre@gmail.com>2019-12-08 21:28:27 +0100
commitb92adfcb5f79f2b32c3dafb0fc3e7f1b753b6197 (patch)
tree69202c4021b10f3ab7b7f5ebf229d501e95c4786 /repository/config_mem.go
parent981a4a848b1329da1a73270e27633911f9298bb1 (diff)
downloadgit-bug-b92adfcb5f79f2b32c3dafb0fc3e7f1b753b6197.tar.gz
bridge: huge refactor to accept multiple kind of credentials
Diffstat (limited to 'repository/config_mem.go')
-rw-r--r--repository/config_mem.go26
1 files changed, 14 insertions, 12 deletions
diff --git a/repository/config_mem.go b/repository/config_mem.go
index bd680d03..5ce577ac 100644
--- a/repository/config_mem.go
+++ b/repository/config_mem.go
@@ -6,30 +6,32 @@ import (
"time"
)
-var _ Config = &memConfig{}
+var _ Config = &MemConfig{}
-type memConfig struct {
+type MemConfig struct {
config map[string]string
}
-func newMemConfig(config map[string]string) *memConfig {
- return &memConfig{config: config}
+func NewMemConfig() *MemConfig {
+ return &MemConfig{
+ config: make(map[string]string),
+ }
}
-func (mc *memConfig) StoreString(key, value string) error {
+func (mc *MemConfig) StoreString(key, value string) error {
mc.config[key] = value
return nil
}
-func (mc *memConfig) StoreBool(key string, value bool) error {
+func (mc *MemConfig) StoreBool(key string, value bool) error {
return mc.StoreString(key, strconv.FormatBool(value))
}
-func (mc *memConfig) StoreTimestamp(key string, value time.Time) error {
+func (mc *MemConfig) StoreTimestamp(key string, value time.Time) error {
return mc.StoreString(key, strconv.Itoa(int(value.Unix())))
}
-func (mc *memConfig) ReadAll(keyPrefix string) (map[string]string, error) {
+func (mc *MemConfig) ReadAll(keyPrefix string) (map[string]string, error) {
result := make(map[string]string)
for key, val := range mc.config {
if strings.HasPrefix(key, keyPrefix) {
@@ -39,7 +41,7 @@ func (mc *memConfig) ReadAll(keyPrefix string) (map[string]string, error) {
return result, nil
}
-func (mc *memConfig) ReadString(key string) (string, error) {
+func (mc *MemConfig) ReadString(key string) (string, error) {
// unlike git, the mock can only store one value for the same key
val, ok := mc.config[key]
if !ok {
@@ -49,7 +51,7 @@ func (mc *memConfig) ReadString(key string) (string, error) {
return val, nil
}
-func (mc *memConfig) ReadBool(key string) (bool, error) {
+func (mc *MemConfig) ReadBool(key string) (bool, error) {
// unlike git, the mock can only store one value for the same key
val, ok := mc.config[key]
if !ok {
@@ -59,7 +61,7 @@ func (mc *memConfig) ReadBool(key string) (bool, error) {
return strconv.ParseBool(val)
}
-func (mc *memConfig) ReadTimestamp(key string) (time.Time, error) {
+func (mc *MemConfig) ReadTimestamp(key string) (time.Time, error) {
value, err := mc.ReadString(key)
if err != nil {
return time.Time{}, err
@@ -74,7 +76,7 @@ func (mc *memConfig) ReadTimestamp(key string) (time.Time, error) {
}
// RmConfigs remove all key/value pair matching the key prefix
-func (mc *memConfig) RemoveAll(keyPrefix string) error {
+func (mc *MemConfig) RemoveAll(keyPrefix string) error {
for key := range mc.config {
if strings.HasPrefix(key, keyPrefix) {
delete(mc.config, key)