mirror of
https://github.com/gomods/athens
synced 2026-02-03 11:00:32 +00:00
fix golint issues (#110)
* fix stutters * add comments * add -set_exit_status flag to golint * missing renames * renames again
This commit is contained in:
committed by
Aaron Schlesinger
parent
b7e15a845c
commit
0a3eb4c4ea
+1
-1
@@ -12,5 +12,5 @@ before_script:
|
||||
script:
|
||||
- test -z $(gofmt -s -l $GO_FILES) # Fail if a .go file hasn't been formatted with gofmt
|
||||
- go vet ./... # Go static analyzer
|
||||
- golint $(go list ./...) # TODO: add -set_exit_status at some point
|
||||
- golint -set_exit_status $(go list ./...) # Linter
|
||||
- go test -race ./... # Run all the tests with the race detector enabled
|
||||
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
|
||||
func addRegistryRoutes(app *buffalo.App) error {
|
||||
cdnGetter := newCDNGetter()
|
||||
mgoStore := mongo.NewMongoUserStore("127.0.0.1:27017")
|
||||
mgoStore := mongo.NewUserStore("127.0.0.1:27017")
|
||||
if err := mgoStore.Connect(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
+2
-2
@@ -10,7 +10,7 @@ import (
|
||||
"github.com/spf13/afero"
|
||||
)
|
||||
|
||||
func newStorage() (storage.Storage, error) {
|
||||
func newStorage() (storage.Backend, error) {
|
||||
storageType := envy.Get("ATHENS_STORAGE_TYPE", "memory")
|
||||
switch storageType {
|
||||
case "memory":
|
||||
@@ -31,7 +31,7 @@ func newStorage() (storage.Storage, error) {
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("missing mongo URL (%s)", err)
|
||||
}
|
||||
return mongo.NewMongoStorage(mongoURI), nil
|
||||
return mongo.NewStorage(mongoURI), nil
|
||||
default:
|
||||
return nil, fmt.Errorf("storage type %s is unknown", storageType)
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package payloads
|
||||
|
||||
// Upload is used to send a module (zip and mod file) via POST request to the storage backend and save it there.
|
||||
type Upload struct {
|
||||
Module []byte `json:"module"`
|
||||
Zip []byte `json:"zip"`
|
||||
|
||||
@@ -24,7 +24,8 @@ type gitCrawler struct {
|
||||
ref string
|
||||
}
|
||||
|
||||
func NewGitCrawler(owner string, repoName string, ref string) (repo.RepoCrawler, error) {
|
||||
// NewGitCrawler creates a new Crawler for repositories hosted on github
|
||||
func NewGitCrawler(owner string, repoName string, ref string) (repo.Crawler, error) {
|
||||
if owner == "" || repoName == "" {
|
||||
return nil, errors.New("invalid repository identifier")
|
||||
}
|
||||
@@ -36,6 +37,7 @@ func NewGitCrawler(owner string, repoName string, ref string) (repo.RepoCrawler,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// Fetches a tarball of a repo and untars it into a temp dir which is used later in the workflow.
|
||||
func (g gitCrawler) DownloadRepo() (string, error) {
|
||||
uri := fmt.Sprintf(fetchRepoURI, g.owner, g.repoName, g.ref)
|
||||
|
||||
|
||||
+2
-1
@@ -1,6 +1,7 @@
|
||||
package repo
|
||||
|
||||
type RepoCrawler interface {
|
||||
// Crawler downloads repositories to a tmp directory, then module zip generation flow can proceed with this directory.
|
||||
type Crawler interface {
|
||||
// Downloads repo to tmp folder, path to tmp returned
|
||||
DownloadRepo() (string, error)
|
||||
}
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
package storage
|
||||
|
||||
// Backend is a complete storage backend (i.e. file system, database) implementation - a lister, reader and saver
|
||||
type Backend interface {
|
||||
Lister
|
||||
Getter
|
||||
Saver
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package storage
|
||||
|
||||
// BackendConnector is a regular storage backend with Connect functionality
|
||||
type BackendConnector interface {
|
||||
Backend
|
||||
Connect() error
|
||||
}
|
||||
|
||||
type noOpConnectedBackend struct {
|
||||
s Backend
|
||||
}
|
||||
|
||||
// NoOpBackendConnector wraps storage backend with Connect functionality
|
||||
func NoOpBackendConnector(s Backend) BackendConnector {
|
||||
return noOpConnectedBackend{s: s}
|
||||
}
|
||||
|
||||
func (n noOpConnectedBackend) Connect() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (n noOpConnectedBackend) Get(module, vsn string) (*Version, error) {
|
||||
return n.s.Get(module, vsn)
|
||||
}
|
||||
func (n noOpConnectedBackend) List(module string) ([]string, error) {
|
||||
return n.s.List(module)
|
||||
}
|
||||
func (n noOpConnectedBackend) Save(module, version string, mod, zip []byte) error {
|
||||
return n.s.Save(module, version, mod, zip)
|
||||
}
|
||||
@@ -28,7 +28,7 @@ var (
|
||||
|
||||
type FsTests struct {
|
||||
suite.Suite
|
||||
storage storage.Storage
|
||||
storage storage.Backend
|
||||
rootDir string
|
||||
fs afero.Fs
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ func (s *storageImpl) versionLocation(module, version string) string {
|
||||
|
||||
// NewStorage returns a new ListerSaver implementation that stores
|
||||
// everything under rootDir
|
||||
func NewStorage(rootDir string, filesystem afero.Fs) storage.Storage {
|
||||
func NewStorage(rootDir string, filesystem afero.Fs) storage.Backend {
|
||||
return &storageImpl{rootDir: rootDir, filesystem: filesystem}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package storage
|
||||
|
||||
// Module represents a vgo module saved in a storage backend.
|
||||
type Module struct {
|
||||
Module string `bson:"module"`
|
||||
Version string `bson:"version"`
|
||||
|
||||
@@ -26,11 +26,11 @@ var (
|
||||
|
||||
type MongoTests struct {
|
||||
suite.Suite
|
||||
storage storage.StorageConnector
|
||||
storage storage.BackendConnector
|
||||
}
|
||||
|
||||
func (d *MongoTests) SetupTest() {
|
||||
store := NewMongoStorage("mongodb://127.0.0.1:27017")
|
||||
store := NewStorage("mongodb://127.0.0.1:27017")
|
||||
store.Connect()
|
||||
|
||||
store.s.DB(store.d).C(store.c).RemoveAll(nil)
|
||||
|
||||
@@ -10,7 +10,8 @@ import (
|
||||
"github.com/gomods/athens/pkg/storage"
|
||||
)
|
||||
|
||||
func (s *MongoModuleStore) Get(module, vsn string) (*storage.Version, error) {
|
||||
// Get a specific version of a module
|
||||
func (s *ModuleStore) Get(module, vsn string) (*storage.Version, error) {
|
||||
c := s.s.DB(s.d).C(s.c)
|
||||
result := &storage.Module{}
|
||||
err := c.Find(bson.M{"module": module, "version": vsn}).One(result)
|
||||
|
||||
@@ -7,7 +7,8 @@ import (
|
||||
"github.com/gomods/athens/pkg/storage"
|
||||
)
|
||||
|
||||
func (s *MongoModuleStore) List(module string) ([]string, error) {
|
||||
// List lists all versions of a module
|
||||
func (s *ModuleStore) List(module string) ([]string, error) {
|
||||
c := s.s.DB(s.d).C(s.c)
|
||||
result := make([]storage.Module, 0)
|
||||
err := c.Find(bson.M{"module": module}).All(&result)
|
||||
|
||||
@@ -4,21 +4,23 @@ import (
|
||||
"github.com/globalsign/mgo"
|
||||
)
|
||||
|
||||
type MongoModuleStore struct {
|
||||
// ModuleStore represents a mongo backed storage backend.
|
||||
type ModuleStore struct {
|
||||
s *mgo.Session
|
||||
d string // database
|
||||
c string // collection
|
||||
url string
|
||||
}
|
||||
|
||||
// NewMongoStorage returns an unconnected Mongo Module Storage
|
||||
// that satisfies the Storage interface. You must call
|
||||
// NewStorage returns an unconnected Mongo backed storage
|
||||
// that satisfies the Backend interface. You must call
|
||||
// Connect() on the returned store before using it.
|
||||
func NewMongoStorage(url string) *MongoModuleStore {
|
||||
return &MongoModuleStore{url: url}
|
||||
func NewStorage(url string) *ModuleStore {
|
||||
return &ModuleStore{url: url}
|
||||
}
|
||||
|
||||
func (m *MongoModuleStore) Connect() error {
|
||||
// Connect conntect the the newly created mongo backend.
|
||||
func (m *ModuleStore) Connect() error {
|
||||
s, err := mgo.Dial(m.url)
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
@@ -28,7 +28,7 @@ func (m *MongoTests) TestGetSaveListRoundTrip() {
|
||||
func (m *MongoTests) TestNewMongoStorage() {
|
||||
r := m.Require()
|
||||
url := "mongodb://127.0.0.1:27017"
|
||||
getterSaver := NewMongoStorage(url)
|
||||
getterSaver := NewStorage(url)
|
||||
getterSaver.Connect()
|
||||
|
||||
r.NotNil(getterSaver.c)
|
||||
|
||||
@@ -2,7 +2,8 @@ package mongo
|
||||
|
||||
import "github.com/gomods/athens/pkg/storage"
|
||||
|
||||
func (s *MongoModuleStore) Save(module, version string, mod, zip []byte) error {
|
||||
// Save stores a module in mongo storage.
|
||||
func (s *ModuleStore) Save(module, version string, mod, zip []byte) error {
|
||||
m := &storage.Module{
|
||||
Module: module,
|
||||
Version: version,
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package storage
|
||||
|
||||
// Reader lists all module versions and gets a specific one from the underlying backend.
|
||||
type Reader struct {
|
||||
Lister
|
||||
Getter
|
||||
|
||||
@@ -1,8 +0,0 @@
|
||||
package storage
|
||||
|
||||
// Storage is a complete storage implementation - a lister, reader and saver
|
||||
type Storage interface {
|
||||
Lister
|
||||
Getter
|
||||
Saver
|
||||
}
|
||||
@@ -1,30 +0,0 @@
|
||||
package storage
|
||||
|
||||
// StorageConnector is a regular storage with Connect functionality
|
||||
type StorageConnector interface {
|
||||
Storage
|
||||
Connect() error
|
||||
}
|
||||
|
||||
type noOpConnectedStorage struct {
|
||||
s Storage
|
||||
}
|
||||
|
||||
// NoOpStorageConnector wraps storage with Connect functionality
|
||||
func NoOpStorageConnector(s Storage) StorageConnector {
|
||||
return noOpConnectedStorage{s: s}
|
||||
}
|
||||
|
||||
func (n noOpConnectedStorage) Connect() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (n noOpConnectedStorage) Get(module, vsn string) (*Version, error) {
|
||||
return n.s.Get(module, vsn)
|
||||
}
|
||||
func (n noOpConnectedStorage) List(module string) ([]string, error) {
|
||||
return n.s.List(module)
|
||||
}
|
||||
func (n noOpConnectedStorage) Save(module, version string, mod, zip []byte) error {
|
||||
return n.s.Save(module, version, mod, zip)
|
||||
}
|
||||
@@ -2,6 +2,7 @@ package storage
|
||||
|
||||
import "io"
|
||||
|
||||
// Version represents a version of a module and contains .mod file and zip of a specific version
|
||||
type Version struct {
|
||||
RevInfo RevInfo
|
||||
Mod []byte
|
||||
|
||||
+10
-8
@@ -10,21 +10,23 @@ import (
|
||||
"github.com/globalsign/mgo/bson"
|
||||
)
|
||||
|
||||
type MongoUserStore struct {
|
||||
// UserStore represents a UserStore implementation backed by mongo.
|
||||
type UserStore struct {
|
||||
s *mgo.Session
|
||||
d string // database
|
||||
c string // collection
|
||||
url string
|
||||
}
|
||||
|
||||
// NewMongoUserStore returns an unconnected MongoUserStore
|
||||
// NewUserStore returns an unconnected UserStore
|
||||
// that satisfies the UserStore interface. You must call
|
||||
// Connect() on the returned store before using it.
|
||||
func NewMongoUserStore(url string) *MongoUserStore {
|
||||
return &MongoUserStore{url: url}
|
||||
func NewUserStore(url string) *UserStore {
|
||||
return &UserStore{url: url}
|
||||
}
|
||||
|
||||
func (m *MongoUserStore) Connect() error {
|
||||
// Connect establishes a session to the mongo cluster.
|
||||
func (m *UserStore) Connect() error {
|
||||
s, err := mgo.Dial(m.url)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
@@ -51,7 +53,7 @@ func (m *MongoUserStore) Connect() error {
|
||||
}
|
||||
|
||||
// Get returns a user from the Mongo Store
|
||||
func (m *MongoUserStore) Get(id, provider string) (*user.User, error) {
|
||||
func (m *UserStore) Get(id, provider string) (*user.User, error) {
|
||||
c := m.s.DB(m.d).C(m.c)
|
||||
result := &user.User{}
|
||||
err := c.Find(bson.M{"provider": provider, "userid": id}).One(result)
|
||||
@@ -64,12 +66,12 @@ func (m *MongoUserStore) Get(id, provider string) (*user.User, error) {
|
||||
}
|
||||
|
||||
// Save adds a user to the Mongo Store
|
||||
func (m *MongoUserStore) Save(u *user.User) error {
|
||||
func (m *UserStore) Save(u *user.User) error {
|
||||
c := m.s.DB(m.d).C(m.c)
|
||||
return c.Insert(u)
|
||||
}
|
||||
|
||||
// Update updates a user in the Mongo Store
|
||||
func (m *MongoUserStore) Update(*user.User) error {
|
||||
func (m *UserStore) Update(*user.User) error {
|
||||
return errors.New("not implemented")
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ import (
|
||||
"github.com/gomods/athens/pkg/user"
|
||||
)
|
||||
|
||||
var m *MongoUserStore
|
||||
var m *UserStore
|
||||
|
||||
func TestConnect(t *testing.T) {
|
||||
setup(t)
|
||||
@@ -40,7 +40,7 @@ func TestCreate(t *testing.T) {
|
||||
func setup(t *testing.T) {
|
||||
var err error
|
||||
if m == nil {
|
||||
m = NewMongoUserStore("mongodb://127.0.0.1:27017")
|
||||
m = NewUserStore("mongodb://127.0.0.1:27017")
|
||||
err = m.Connect()
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
|
||||
+2
-1
@@ -7,9 +7,10 @@ import (
|
||||
"github.com/markbates/goth"
|
||||
)
|
||||
|
||||
// ErrNotFound will be returned if a user could not be found in the user store
|
||||
var ErrNotFound = errors.New("user not found")
|
||||
|
||||
// UserStore provides an interface for storing Users
|
||||
// Store provides an interface for getting, storing and updating Users
|
||||
type Store interface {
|
||||
Get(id, provider string) (*User, error)
|
||||
Save(*User) error
|
||||
|
||||
Reference in New Issue
Block a user