From 3eafb3e5ab8ada47be8104407b1e65fd65b91dcf Mon Sep 17 00:00:00 2001 From: Brian Tiger Chow Date: Tue, 13 Jan 2015 02:52:23 -0800 Subject: [PATCH] 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. --- core/commands/bootstrap.go | 6 +++--- core/commands/config.go | 4 ++-- repo/fsrepo/fsrepo.go | 2 +- repo/repo.go | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/core/commands/bootstrap.go b/core/commands/bootstrap.go index 6cdda8974..c3cfeee7b 100644 --- a/core/commands/bootstrap.go +++ b/core/commands/bootstrap.go @@ -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) diff --git a/core/commands/config.go b/core/commands/config.go index a091ad41c..e5cf3d386 100644 --- a/core/commands/config.go +++ b/core/commands/config.go @@ -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) diff --git a/repo/fsrepo/fsrepo.go b/repo/fsrepo/fsrepo.go index 1857751ef..5698acd44 100644 --- a/repo/fsrepo/fsrepo.go +++ b/repo/fsrepo/fsrepo.go @@ -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 { diff --git a/repo/repo.go b/repo/repo.go index fef058f4a..dc7689f31 100644 --- a/repo/repo.go +++ b/repo/repo.go @@ -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