Following changes made as part of this commit: 1. Add Build status, Go Doc and Go Report badges to README.md 2. Fixed go vet errors like "composite literal uses unkeyed fields" 3. Fixed go fmt issues 4. Add gofmt & go vet checks to travis build file 5. Spell correction This help bump up gofmt and misspell report.
diff --git a/.travis.yml b/.travis.yml index 0fc0167..5080b8b 100644 --- a/.travis.yml +++ b/.travis.yml
@@ -12,4 +12,6 @@ - glide install script: + - diff -u <(echo -n) <(gofmt -d $(git ls-files | grep '.go$' | grep -v vendor)) + - go vet $(glide novendor) - go test $(glide novendor)
diff --git a/README.md b/README.md index 551ba2f..6223065 100644 --- a/README.md +++ b/README.md
@@ -1,5 +1,7 @@ # apid-core +[](https://travis-ci.org/apid/apid-core) [](https://godoc.org/github.com/apid/apid-core) [](https://goreportcard.com/report/github.com/apid/apid-core) + apid-core is a library that provides a container for publishing APIs that provides core services to its plugins including configuration, API publishing, data access, and a local pub/sub event system.
diff --git a/api/api_test.go b/api/api_test.go index b896f4e..c3af427 100644 --- a/api/api_test.go +++ b/api/api_test.go
@@ -15,12 +15,12 @@ package api_test import ( + "encoding/json" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" - "net/url" - "net/http" "io/ioutil" - "encoding/json" + "net/http" + "net/url" ) var _ = Describe("API Service", func() { @@ -32,8 +32,8 @@ uri.Path = "/exp/vars" resp, err := http.Get(uri.String()) - defer resp.Body.Close() Expect(err).ShouldNot(HaveOccurred()) + defer resp.Body.Close() Expect(resp.StatusCode).Should(Equal(http.StatusOK)) body, err := ioutil.ReadAll(resp.Body)
diff --git a/apid.go b/apid.go index 97134d7..96c3f6e 100644 --- a/apid.go +++ b/apid.go
@@ -16,20 +16,20 @@ import ( "errors" + "github.com/apid/apid-core/util" "os" "time" - "github.com/apid/apid-core/util" ) const ( SystemEventsSelector EventSelector = "system event" ShutdownEventSelector EventSelector = "shutdown event" ShutdownTimeout time.Duration = 10 * time.Second - configfwdProxyURL = "configfwdproxy_url" - configfwdProxyProt = "configfwdproxy_prot" - configfwdProxyUser = "configfwdproxy_user" - configfwdProxyPasswd = "configfwdproxy_passwd" - configfwdProxyPort = "configfwdproxy_port" + configfwdProxyURL = "configfwdproxy_url" + configfwdProxyProt = "configfwdproxy_prot" + configfwdProxyUser = "configfwdproxy_user" + configfwdProxyPasswd = "configfwdproxy_passwd" + configfwdProxyPort = "configfwdproxy_port" ) var (
diff --git a/config/config_suite_test.go b/config/config_suite_test.go index 347039e..1573c7e 100644 --- a/config/config_suite_test.go +++ b/config/config_suite_test.go
@@ -18,9 +18,9 @@ . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" - "testing" "github.com/apid/apid-core" "github.com/apid/apid-core/factory" + "testing" ) var _ = BeforeSuite(func() { @@ -28,7 +28,6 @@ apid.Config().SetDefault("test", "test") }) - func TestEvents(t *testing.T) { RegisterFailHandler(Fail) RunSpecs(t, "Config Suite")
diff --git a/config/config_test.go b/config/config_test.go index ea43766..6cba15d 100644 --- a/config/config_test.go +++ b/config/config_test.go
@@ -15,10 +15,10 @@ package config_test import ( + "github.com/apid/apid-core" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" "os" - "github.com/apid/apid-core" "time" )
diff --git a/data/data_test.go b/data/data_test.go index c7ea93b..ec20dbb 100644 --- a/data/data_test.go +++ b/data/data_test.go
@@ -49,7 +49,7 @@ _, err = apid.Data().DBVersionForID("common", "base") Expect(err).To(HaveOccurred()) }) - It("should be able to change versions of a datbase", func() { + It("should be able to change versions of a database", func() { var versions []string var dbs []apid.DB @@ -328,14 +328,14 @@ Ω(s[0].Id).Should(Equal("b7e0970c-4677-4b05-8105-5ea59fdcf4e7")) Ω(s[0].QuotaInterval).Should(Equal(int64(1))) Ω(s[0].SignedInt).Should(Equal(int(-1))) - Ω(s[0].SqlInt).Should(Equal(sql.NullInt64{-2, true})) + Ω(s[0].SqlInt).Should(Equal(sql.NullInt64{Int64: -2, Valid: true})) Ω(s[0].Ratio).Should(Equal(float64(0.5))) Ω(s[0].ShortFloat).Should(Equal(float32(0.6))) - Ω(s[0].SqlFloat).Should(Equal(sql.NullFloat64{0.7, true})) + Ω(s[0].SqlFloat).Should(Equal(sql.NullFloat64{Float64: 0.7, Valid: true})) Ω(s[0].CreatedAt).Should(Equal("2017-10-26 22:26:50.153+00:00")) - Ω(s[0].CreatedBy).Should(Equal(sql.NullString{"haoming", true})) + Ω(s[0].CreatedBy).Should(Equal(sql.NullString{String: "haoming", Valid: true})) Ω(s[0].UpdatedAt).Should(Equal([]byte("2017-10-26 22:26:50.153+00:00"))) - Ω(s[0].StringBlob).Should(Equal(sql.NullString{"2017-10-26 22:26:50.153+00:00", true})) + Ω(s[0].StringBlob).Should(Equal(sql.NullString{String: "2017-10-26 22:26:50.153+00:00", Valid: true})) Ω(s[0].NotInDb).Should(BeZero()) Ω(s[0].NotUsed).Should(BeZero())
diff --git a/events/event_manager.go b/events/event_manager.go index 87e7dea..0e4d7c3 100644 --- a/events/event_manager.go +++ b/events/event_manager.go
@@ -15,8 +15,8 @@ package events import ( - "sync" "reflect" + "sync" "github.com/apid/apid-core" )
diff --git a/events/events_suite_test.go b/events/events_suite_test.go index 01dc88c..d9c9fa5 100644 --- a/events/events_suite_test.go +++ b/events/events_suite_test.go
@@ -18,16 +18,15 @@ . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" - "testing" "github.com/apid/apid-core" "github.com/apid/apid-core/factory" + "testing" ) var _ = BeforeSuite(func() { apid.Initialize(factory.DefaultServicesFactory()) }) - func TestEvents(t *testing.T) { RegisterFailHandler(Fail) RunSpecs(t, "Events Suite")
diff --git a/events/events_test.go b/events/events_test.go index 877e385..7edfb38 100644 --- a/events/events_test.go +++ b/events/events_test.go
@@ -267,7 +267,7 @@ }) It("should publish PluginsInitialized event", func(done Done) { - dummyPluginData := getDummyPluginDataForTest(0); + dummyPluginData := getDummyPluginDataForTest(0) p := func(s apid.Services) (pd apid.PluginData, err error) { pd = dummyPluginData return @@ -304,7 +304,7 @@ } } apid.Events().ListenFunc(apid.ShutdownEventSelector, h) - <- apid.Events().Emit(apid.ShutdownEventSelector, apid.ShutdownEvent{"apid is going to shutdown"}) + <-apid.Events().Emit(apid.ShutdownEventSelector, apid.ShutdownEvent{Description: "apid is going to shutdown"}) close(done) }) @@ -314,7 +314,7 @@ countP := &count // create and register plugins, listen to shutdown event - for i:=0; i<pluginNum; i++ { + for i := 0; i < pluginNum; i++ { apid.RegisterPlugin(createDummyPlugin(i), getDummyPluginDataForTest(i)) h := func(event apid.Event) { if pie, ok := event.(apid.ShutdownEvent); ok { @@ -327,7 +327,6 @@ apid.Events().ListenFunc(apid.ShutdownEventSelector, h) } - apid.InitializePlugins("") apid.ShutdownPluginsAndWait() @@ -343,7 +342,7 @@ pd = dummyPluginData return } - apid.RegisterPlugin(p,dummyPluginData) + apid.RegisterPlugin(p, dummyPluginData) apidVersion := "dummy_version" @@ -362,7 +361,7 @@ }) }) -func createDummyPlugin(id int) apid.PluginInitFunc{ +func createDummyPlugin(id int) apid.PluginInitFunc { p := func(s apid.Services) (pd apid.PluginData, err error) { pd = getDummyPluginDataForTest(id) return
diff --git a/logger/logger.go b/logger/logger.go index 11f12e0..aee1786 100644 --- a/logger/logger.go +++ b/logger/logger.go
@@ -19,8 +19,8 @@ "os" "time" - "github.com/apid/apid-core" "github.com/Sirupsen/logrus" + "github.com/apid/apid-core" ) const (
diff --git a/util/util.go b/util/util.go index 4178030..8eeb709 100644 --- a/util/util.go +++ b/util/util.go
@@ -14,14 +14,14 @@ package util - import ( "github.com/google/uuid" "net/http" "net/url" "time" ) -const ConfigfwdProxyPortURL = "configcompletefwdp" + +const ConfigfwdProxyPortURL = "configcompletefwdp" func IsValidUUID(id string) bool { _, err := uuid.Parse(id) @@ -41,7 +41,7 @@ panic("Error parsing proxy URL") } tr = http.Transport{ - Proxy: http.ProxyURL(paURL), + Proxy: http.ProxyURL(paURL), } } return &tr
diff --git a/util/util_test.go b/util/util_test.go index b6c1093..da1c714 100644 --- a/util/util_test.go +++ b/util/util_test.go
@@ -18,11 +18,10 @@ . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" - - "net/http/httptest" "github.com/apid/apid-core/util" "math/rand" "net/http" + "net/http/httptest" "regexp" "sync/atomic" "testing" @@ -75,7 +74,7 @@ w.Header().Set("bar", "foo") })) tr = util.Transport(fwdPrxyServer.URL) - tr.MaxIdleConnsPerHost = maxIdleConnsPerHost + tr.MaxIdleConnsPerHost = maxIdleConnsPerHost var rspcnt int = 0 ch := make(chan *http.Response) client := &http.Client{Transport: tr}