This is an automated email from the ASF dual-hosted git repository.
alexstocks pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/dubbo-go-samples.git
The following commit(s) were added to refs/heads/master by this push:
new c31618b Fix: go vet error in game sample&custom logger sample (#269)
c31618b is described below
commit c31618bc0798271842cb78a05595102d97ae1fd4
Author: 氕氘氚 <[email protected]>
AuthorDate: Mon Oct 4 13:09:30 2021 +0800
Fix: go vet error in game sample&custom logger sample (#269)
* fix: go vet error in game sample&custom logger
* style: sort imports
---
game/go-server-game/cmd/server.go | 5 +++--
game/go-server-game/{cmd => pkg}/consumer.go | 2 +-
game/go-server-game/{cmd => pkg}/provider.go | 2 +-
game/go-server-gate/cmd/server.go | 11 ++++++-----
game/go-server-gate/{cmd => pkg}/consumer.go | 2 +-
game/go-server-gate/{cmd => pkg}/provider.go | 2 +-
.../game/go-server-game/tests/integration/main_test.go | 4 ++--
.../game/go-server-gate/tests/integration/main_test.go | 4 ++--
logger/custom/cmd/main.go | 13 +++++++------
9 files changed, 24 insertions(+), 21 deletions(-)
diff --git a/game/go-server-game/cmd/server.go
b/game/go-server-game/cmd/server.go
index 90b05fc..dd63197 100644
--- a/game/go-server-game/cmd/server.go
+++ b/game/go-server-game/cmd/server.go
@@ -32,13 +32,14 @@ import (
)
import (
+ "github.com/apache/dubbo-go-samples/game/go-server-game/pkg"
"github.com/apache/dubbo-go-samples/game/pkg/pojo"
)
func init() {
- config.SetProviderService(new(BasketballService))
+ config.SetProviderService(new(pkg.BasketballService))
- config.SetConsumerService(GateBasketball)
+ config.SetConsumerService(pkg.GateBasketball)
hessian.RegisterPOJO(&pojo.Result{})
}
diff --git a/game/go-server-game/cmd/consumer.go
b/game/go-server-game/pkg/consumer.go
similarity index 98%
rename from game/go-server-game/cmd/consumer.go
rename to game/go-server-game/pkg/consumer.go
index 9581b49..e59ac65 100644
--- a/game/go-server-game/cmd/consumer.go
+++ b/game/go-server-game/pkg/consumer.go
@@ -15,7 +15,7 @@
* limitations under the License.
*/
-package main
+package pkg
import "github.com/apache/dubbo-go-samples/game/pkg/consumer/gate"
diff --git a/game/go-server-game/cmd/provider.go
b/game/go-server-game/pkg/provider.go
similarity index 99%
rename from game/go-server-game/cmd/provider.go
rename to game/go-server-game/pkg/provider.go
index 489e083..bd668d7 100644
--- a/game/go-server-game/cmd/provider.go
+++ b/game/go-server-game/pkg/provider.go
@@ -15,7 +15,7 @@
* limitations under the License.
*/
-package main
+package pkg
import (
"context"
diff --git a/game/go-server-gate/cmd/server.go
b/game/go-server-gate/cmd/server.go
index 6697c85..f6f912e 100644
--- a/game/go-server-gate/cmd/server.go
+++ b/game/go-server-gate/cmd/server.go
@@ -37,13 +37,14 @@ import (
)
import (
+ "github.com/apache/dubbo-go-samples/game/go-server-gate/pkg"
"github.com/apache/dubbo-go-samples/game/pkg/pojo"
)
func init() {
- config.SetProviderService(new(BasketballService))
+ config.SetProviderService(new(pkg.BasketballService))
- config.SetConsumerService(GameBasketball)
+ config.SetConsumerService(pkg.GameBasketball)
hessian.RegisterPOJO(&pojo.Result{})
}
@@ -82,7 +83,7 @@ func initSignal() {
func startHttp() {
http.HandleFunc("/login", func(w http.ResponseWriter, r *http.Request) {
- res, err := Login(context.TODO(), r.URL.Query().Get("name"))
+ res, err := pkg.Login(context.TODO(), r.URL.Query().Get("name"))
if err != nil {
responseWithOrigin(w, r, 200, []byte(err.Error()))
return
@@ -103,7 +104,7 @@ func startHttp() {
}
var info pojo.Info
json.Unmarshal(reqBody, &info)
- res, err := Score(context.TODO(), info.Name,
strconv.Itoa(info.Score))
+ res, err := pkg.Score(context.TODO(), info.Name,
strconv.Itoa(info.Score))
if err != nil {
responseWithOrigin(w, r, 200, []byte(err.Error()))
return
@@ -118,7 +119,7 @@ func startHttp() {
})
http.HandleFunc("/rank", func(w http.ResponseWriter, r *http.Request) {
- res, err := Rank(context.TODO(), r.URL.Query().Get("name"))
+ res, err := pkg.Rank(context.TODO(), r.URL.Query().Get("name"))
if err != nil {
responseWithOrigin(w, r, 200, []byte(err.Error()))
return
diff --git a/game/go-server-gate/cmd/consumer.go
b/game/go-server-gate/pkg/consumer.go
similarity index 99%
rename from game/go-server-gate/cmd/consumer.go
rename to game/go-server-gate/pkg/consumer.go
index a7cffa9..fa06663 100644
--- a/game/go-server-gate/cmd/consumer.go
+++ b/game/go-server-gate/pkg/consumer.go
@@ -15,7 +15,7 @@
* limitations under the License.
*/
-package main
+package pkg
import (
"context"
diff --git a/game/go-server-gate/cmd/provider.go
b/game/go-server-gate/pkg/provider.go
similarity index 99%
rename from game/go-server-gate/cmd/provider.go
rename to game/go-server-gate/pkg/provider.go
index 8dac483..4499992 100644
--- a/game/go-server-gate/cmd/provider.go
+++ b/game/go-server-gate/pkg/provider.go
@@ -15,7 +15,7 @@
* limitations under the License.
*/
-package main
+package pkg
import (
"context"
diff --git a/integrate_test/game/go-server-game/tests/integration/main_test.go
b/integrate_test/game/go-server-game/tests/integration/main_test.go
index 0cc0613..bec92b9 100644
--- a/integrate_test/game/go-server-game/tests/integration/main_test.go
+++ b/integrate_test/game/go-server-game/tests/integration/main_test.go
@@ -30,11 +30,11 @@ import (
)
import (
- game "github.com/apache/dubbo-go-samples/game/go-server-game/cmd"
+ "github.com/apache/dubbo-go-samples/game/go-server-game/pkg"
"github.com/apache/dubbo-go-samples/game/pkg/pojo"
)
-var gameProvider = game.BasketballService{}
+var gameProvider = pkg.BasketballService{}
func TestMain(m *testing.M) {
config.SetConsumerService(gameProvider)
diff --git a/integrate_test/game/go-server-gate/tests/integration/main_test.go
b/integrate_test/game/go-server-gate/tests/integration/main_test.go
index 8f34a3b..9d19d5b 100644
--- a/integrate_test/game/go-server-gate/tests/integration/main_test.go
+++ b/integrate_test/game/go-server-gate/tests/integration/main_test.go
@@ -30,11 +30,11 @@ import (
)
import (
- gate "github.com/apache/dubbo-go-samples/game/go-server-gate/cmd"
+ "github.com/apache/dubbo-go-samples/game/go-server-gate/pkg"
"github.com/apache/dubbo-go-samples/game/pkg/pojo"
)
-var gateProvider = gate.BasketballService{}
+var gateProvider = pkg.BasketballService{}
func TestMain(m *testing.M) {
config.SetConsumerService(gateProvider)
diff --git a/logger/custom/cmd/main.go b/logger/custom/cmd/main.go
index 0d77e84..dcb0484 100644
--- a/logger/custom/cmd/main.go
+++ b/logger/custom/cmd/main.go
@@ -63,23 +63,23 @@ func (c *customLogger) Fatal(args ...interface{}) {
}
func (c *customLogger) Infof(fmts string, args ...interface{}) {
- fmt.Printf("\033[1;32;40m%s\033[0m\n", fmt.Sprintf(fmts, args))
+ fmt.Printf("\033[1;32;40m%s\033[0m\n", fmt.Sprintf(fmts, args...))
}
func (c *customLogger) Warnf(fmts string, args ...interface{}) {
- fmt.Printf("\033[1;33;40m%s\033[0m\n", fmt.Sprintf(fmts, args))
+ fmt.Printf("\033[1;33;40m%s\033[0m\n", fmt.Sprintf(fmts, args...))
}
func (c *customLogger) Errorf(fmts string, args ...interface{}) {
- fmt.Printf("\033[1;31;40m%s\033[0m\n", fmt.Sprintf(fmts, args))
+ fmt.Printf("\033[1;31;40m%s\033[0m\n", fmt.Sprintf(fmts, args...))
}
func (c *customLogger) Debugf(fmts string, args ...interface{}) {
- fmt.Printf("\033[1;34;40m%s\033[0m\n", fmt.Sprintf(fmts, args))
+ fmt.Printf("\033[1;34;40m%s\033[0m\n", fmt.Sprintf(fmts, args...))
}
func (c *customLogger) Fatalf(fmts string, args ...interface{}) {
- fmt.Printf("\033[1;31;40m%s\033[0m\n", fmt.Sprintf(fmts, args))
+ fmt.Printf("\033[1;31;40m%s\033[0m\n", fmt.Sprintf(fmts, args...))
os.Exit(1)
}
@@ -87,7 +87,8 @@ func main() {
config.SetProviderService(&GreeterProvider{})
config.Load()
logger.SetLogger(&customLogger{})
- ctx, _ := context.WithTimeout(context.Background(), time.Second*3)
+ ctx, cancel := context.WithTimeout(context.Background(), time.Second*3)
+ defer cancel()
for {
select {
case <-ctx.Done():