mirror of
				https://github.com/go-micro/go-micro.git
				synced 2025-10-30 23:27:41 +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:
		
				
					committed by
					
						 GitHub
						GitHub
					
				
			
			
				
	
			
			
			
						parent
						
							0f0ace1a44
						
					
				
				
					commit
					26b859c4f9
				
			| @@ -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) | ||||
| 	} | ||||
|   | ||||
| @@ -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": | ||||
|   | ||||
| @@ -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 | ||||
| 		} | ||||
| 	} | ||||
|   | ||||
| @@ -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) | ||||
| 	} | ||||
|  | ||||
|   | ||||
| @@ -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 | ||||
| 	} | ||||
|  | ||||
|   | ||||
| @@ -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) | ||||
|   | ||||
| @@ -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) | ||||
|   | ||||
| @@ -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" | ||||
| 		} | ||||
|  | ||||
|   | ||||
| @@ -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}} | ||||
| } | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user