mirror of
https://github.com/ipfs/kubo.git
synced 2026-02-21 18:37:45 +08:00
style(repo): repo.Interface -> repo.Repo
The pkg.Interface style is modeled after heap.Interface. Generally, I find it helpful for interfaces that have many implementations. It provides clear distinction between the generic interface and the |n| implementations that implement it (which may be interface types themselves). For clients who cannot keep the repo name, one can imagine that the most likely rename is `ipfsrepo`. In that case, `ipfsrepo.Interface` remains meaningful. This is low-pri so it doesn't matter than much. But for the record, the repo.Interface feels appropriate in this use-case.
This commit is contained in:
parent
5705ea9859
commit
3eafb3e5ab
@ -228,7 +228,7 @@ func bootstrapWritePeers(w io.Writer, prefix string, peers []config.BootstrapPee
|
||||
return nil
|
||||
}
|
||||
|
||||
func bootstrapAdd(r repo.Interface, cfg *config.Config, peers []config.BootstrapPeer) ([]config.BootstrapPeer, error) {
|
||||
func bootstrapAdd(r repo.Repo, cfg *config.Config, peers []config.BootstrapPeer) ([]config.BootstrapPeer, error) {
|
||||
added := make([]config.BootstrapPeer, 0, len(peers))
|
||||
|
||||
for _, peer := range peers {
|
||||
@ -253,7 +253,7 @@ func bootstrapAdd(r repo.Interface, cfg *config.Config, peers []config.Bootstrap
|
||||
return added, nil
|
||||
}
|
||||
|
||||
func bootstrapRemove(r repo.Interface, cfg *config.Config, toRemove []config.BootstrapPeer) ([]config.BootstrapPeer, error) {
|
||||
func bootstrapRemove(r repo.Repo, cfg *config.Config, toRemove []config.BootstrapPeer) ([]config.BootstrapPeer, error) {
|
||||
removed := make([]config.BootstrapPeer, 0, len(toRemove))
|
||||
keep := make([]config.BootstrapPeer, 0, len(cfg.Bootstrap))
|
||||
|
||||
@ -280,7 +280,7 @@ func bootstrapRemove(r repo.Interface, cfg *config.Config, toRemove []config.Boo
|
||||
return removed, nil
|
||||
}
|
||||
|
||||
func bootstrapRemoveAll(r repo.Interface, cfg *config.Config) ([]config.BootstrapPeer, error) {
|
||||
func bootstrapRemoveAll(r repo.Repo, cfg *config.Config) ([]config.BootstrapPeer, error) {
|
||||
removed := make([]config.BootstrapPeer, len(cfg.Bootstrap))
|
||||
copy(removed, cfg.Bootstrap)
|
||||
|
||||
|
||||
@ -143,7 +143,7 @@ variable set to your preferred text editor.
|
||||
},
|
||||
}
|
||||
|
||||
func getConfig(r repo.Interface, key string) (*ConfigField, error) {
|
||||
func getConfig(r repo.Repo, key string) (*ConfigField, error) {
|
||||
value, err := r.GetConfigKey(key)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("Failed to get config value: %s", err)
|
||||
@ -154,7 +154,7 @@ func getConfig(r repo.Interface, key string) (*ConfigField, error) {
|
||||
}, nil
|
||||
}
|
||||
|
||||
func setConfig(r repo.Interface, key, value string) (*ConfigField, error) {
|
||||
func setConfig(r repo.Repo, key, value string) (*ConfigField, error) {
|
||||
err := r.SetConfigKey(key, value)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("Failed to set config value: %s", err)
|
||||
|
||||
@ -222,7 +222,7 @@ func (r *FSRepo) Close() error {
|
||||
}
|
||||
|
||||
var _ io.Closer = &FSRepo{}
|
||||
var _ repo.Interface = &FSRepo{}
|
||||
var _ repo.Repo = &FSRepo{}
|
||||
|
||||
// IsInitialized returns true if the repo is initialized at provided |path|.
|
||||
func IsInitialized(path string) bool {
|
||||
|
||||
@ -5,7 +5,7 @@ import (
|
||||
util "github.com/jbenet/go-ipfs/util"
|
||||
)
|
||||
|
||||
type Interface interface {
|
||||
type Repo interface {
|
||||
Config() *config.Config
|
||||
SetConfig(*config.Config) error
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user