-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(remote): Parse config using FillStruct. Remotes field.
Parse the config using FillStruct. Fix numerous bugs found while supporting the config struct. Add a Remotes component to the config, which uses ArbitrarySetter to support arbitrary remote names.
- Loading branch information
Showing
7 changed files
with
197 additions
and
48 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
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 config | ||
|
||
import ( | ||
"fmt" | ||
) | ||
|
||
// Remotes encapsulates configuration options for remotes | ||
type Remotes struct { | ||
nameMap map[string]string | ||
} | ||
|
||
// SetArbitrary is for implementing the ArbitrarySetter interface defined by base/fill_struct.go | ||
func (r *Remotes) SetArbitrary(key string, val interface{}) (err error) { | ||
if r.nameMap == nil { | ||
r.nameMap = map[string]string{} | ||
} | ||
str, ok := val.(string) | ||
if !ok { | ||
return fmt.Errorf("invalid remote value: %s", val) | ||
} | ||
r.nameMap[key] = str | ||
return nil | ||
} | ||
|
||
// Get retrieves an address from the name of remote | ||
func (r *Remotes) Get(name string) (string, bool) { | ||
addr, ok := r.nameMap[name] | ||
return addr, ok | ||
} |
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