1
0
mirror of https://github.com/go-micro/go-micro.git synced 2025-03-03 15:22:30 +02:00

improve code quality (#2128)

* Fix inefficient string comparison

* Fix unnecessary calls to Printf

* Canonicalize header key

* Replace `t.Sub(time.Now())` with `time.Until`

* Remove unnecessary blank (_) identifier

* Remove unnecessary use of slice

* Remove unnecessary comparison with bool
This commit is contained in:
Shubhendra Singh Chauhan 2021-02-25 14:00:35 +05:30 committed by GitHub
parent 0f0ace1a44
commit 26b859c4f9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 10 additions and 10 deletions

View File

@ -122,7 +122,7 @@ func (h *rpcHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
md["Host"] = r.Host
md["Method"] = r.Method
// get canonical headers
for k, _ := range r.Header {
for k := range r.Header {
// may be need to get all values for key like r.Header.Values() provide in go 1.14
md[textproto.CanonicalMIMEHeaderKey(k)] = r.Header.Get(k)
}

View File

@ -38,7 +38,7 @@ func serveWebsocket(ctx context.Context, w http.ResponseWriter, r *http.Request,
}
hdr := make(http.Header)
if proto, ok := r.Header["Sec-WebSocket-Protocol"]; ok {
if proto, ok := r.Header["Sec-Websocket-Protocol"]; ok {
for _, p := range proto {
switch p {
case "binary":

View File

@ -83,7 +83,7 @@ func Verify(rules []*Rule, acc *Account, res *Resource) error {
// not case sensitive.
func include(slice []string, val string) bool {
for _, s := range slice {
if strings.ToLower(s) == strings.ToLower(val) {
if strings.EqualFold(s, val) {
return true
}
}

View File

@ -379,7 +379,7 @@ func (r *rpcClient) Call(ctx context.Context, request Request, response interfac
} else {
// got a deadline so no need to setup context
// but we need to set the timeout we pass along
opt := WithRequestTimeout(d.Sub(time.Now()))
opt := WithRequestTimeout(time.Until(d))
opt(&callOpts)
}

View File

@ -15,7 +15,7 @@ func decode(r io.Reader) (uint8, []byte, error) {
header := make([]byte, 5)
// read the header
if _, err := r.Read(header[:]); err != nil {
if _, err := r.Read(header); err != nil {
return uint8(0), nil, err
}
@ -60,7 +60,7 @@ func encode(cf uint8, buf []byte, w io.Writer) error {
binary.BigEndian.PutUint32(header[1:], uint32(len(buf)))
// read the header
if _, err := w.Write(header[:]); err != nil {
if _, err := w.Write(header); err != nil {
return err
}

View File

@ -158,7 +158,7 @@ func TestConfigWatcherDirtyOverrite(t *testing.T) {
}
runtime.Gosched()
for i, _ := range ss {
for i := range ss {
k := fmt.Sprintf("key%d", i)
v := fmt.Sprintf("val%d", i)
equalS(t, conf.Get(k).String(""), v)

View File

@ -41,7 +41,7 @@ func (w *watcher) Next() (*source.ChangeSet, error) {
// try get the event
select {
case event, _ := <-w.fw.Events:
case event := <-w.fw.Events:
if event.Op == fsnotify.Rename {
// check existence of file, and add watch again
_, err := os.Stat(event.Name)

View File

@ -115,7 +115,7 @@ func (k *klog) Read() ([]runtime.LogRecord, error) {
logParams["tailLines"] = strconv.Itoa(int(k.options.Count))
}
if k.options.Stream == true {
if k.options.Stream {
logParams["follow"] = "true"
}

View File

@ -52,7 +52,7 @@ func ExampleToJSON() {
if err != nil {
panic(err)
}
fmt.Printf(string(b))
fmt.Print(string(b))
// Output: {"a":"xyz","b":{"c":456}}
}