1
0
mirror of https://github.com/go-micro/go-micro.git synced 2025-06-18 22:17:44 +02:00

fix: some linting issues (#2563)

This commit is contained in:
David Brouwer
2022-09-30 16:27:07 +02:00
committed by GitHub
parent 47e6a8d725
commit 85c0b0b8eb
221 changed files with 1025 additions and 1283 deletions

View File

@ -34,14 +34,14 @@ const (
)
var (
// supported json codecs
// supported json codecs.
jsonCodecs = []string{
"application/grpc+json",
"application/json",
"application/json-rpc",
}
// support proto codecs
// support proto codecs.
protoCodecs = []string{
"application/grpc",
"application/grpc+proto",
@ -66,7 +66,7 @@ func (b *buffer) Write(_ []byte) (int, error) {
return 0, nil
}
// strategy is a hack for selection
// strategy is a hack for selection.
func strategy(services []*registry.Service) selector.Strategy {
return func(_ []*registry.Service) selector.Next {
// ignore input to this function, use services above
@ -141,7 +141,7 @@ func (h *rpcHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
if isStream(r, service) {
// drop older context as it can have timeouts and create new
// md, _ := metadata.FromContext(cx)
//serveWebsocket(context.TODO(), w, r, service, c)
// serveWebsocket(context.TODO(), w, r, service, c)
if err := serveWebsocket(cx, w, r, service, c); err != nil {
logger.Log(log.ErrorLevel, err)
}
@ -260,7 +260,7 @@ func hasCodec(ct string, codecs []string) bool {
// requestPayload takes a *http.Request.
// If the request is a GET the query string parameters are extracted and marshaled to JSON and the raw bytes are returned.
// If the request method is a POST the request body is read and returned
// If the request method is a POST the request body is read and returned.
func requestPayload(r *http.Request) ([]byte, error) {
var err error
@ -430,7 +430,7 @@ func requestPayload(r *http.Request) ([]byte, error) {
if jsonbody != nil {
dstmap[ps[0]] = jsonbody
} else {
// old unexpected behaviour
// old unexpected behavior
dstmap[ps[0]] = bodybuf
}
} else {
@ -438,7 +438,7 @@ func requestPayload(r *http.Request) ([]byte, error) {
if jsonbody != nil {
em[ps[len(ps)-1]] = jsonbody
} else {
// old unexpected behaviour
// old unexpected behavior
em[ps[len(ps)-1]] = bodybuf
}
for i := len(ps) - 2; i > 0; i-- {
@ -460,7 +460,6 @@ func requestPayload(r *http.Request) ([]byte, error) {
//fallback to previous unknown behaviour
return bodybuf, nil
}
return []byte{}, nil

View File

@ -12,8 +12,7 @@ import (
)
func TestRequestPayloadFromRequest(t *testing.T) {
// our test event so that we can validate serialising / deserializing of true protos works
// our test event so that we can validate serializing / deserializing of true protos works
protoEvent := go_api.Event{
Name: "Test",
}
@ -85,7 +84,6 @@ func TestRequestPayloadFromRequest(t *testing.T) {
})
t.Run("extracting params from a GET request", func(t *testing.T) {
r, err := http.NewRequest("GET", "http://localhost/my/path", nil)
if err != nil {
t.Fatalf("Failed to created http.Request: %v", err)
@ -105,7 +103,6 @@ func TestRequestPayloadFromRequest(t *testing.T) {
})
t.Run("GET request with no params", func(t *testing.T) {
r, err := http.NewRequest("GET", "http://localhost/my/path", nil)
if err != nil {
t.Fatalf("Failed to created http.Request: %v", err)

View File

@ -19,7 +19,7 @@ import (
"go-micro.dev/v4/selector"
)
// serveWebsocket will stream rpc back over websockets assuming json
// serveWebsocket will stream rpc back over websockets assuming json.
func serveWebsocket(ctx context.Context, w http.ResponseWriter, r *http.Request, service *router.Route, c client.Client) (err error) {
var op ws.OpCode
@ -151,7 +151,7 @@ func serveWebsocket(ctx context.Context, w http.ResponseWriter, r *http.Request,
}
}
// writeLoop
// writeLoop.
func writeLoop(rw io.ReadWriter, stream client.Stream) error {
// close stream when done
defer stream.Close()