소스 검색

refactor: use pointer receiver

This PR mainly fixes the SA4005 linter check to achieve effective assignment.

Signed-off-by: xjasonlyu <xjasonlyu@gmail.com>
xjasonlyu 1 년 전
부모
커밋
9e177392ae
2개의 변경된 파일21개의 추가작업 그리고 18개의 파일을 삭제
  1. 11 9
      internal/server/prome_init.go
  2. 10 9
      internal/server/rpc.go

+ 11 - 9
internal/server/prome_init.go

@@ -1,4 +1,4 @@
-// Copyright 2022 EMQ Technologies Co., Ltd.
+// Copyright 2022-2023 EMQ Technologies Co., Ltd.
 //
 // Licensed under the Apache License, Version 2.0 (the "License");
 // you may not use this file except in compliance with the License.
@@ -20,15 +20,17 @@ package server
 import (
 	"context"
 	"fmt"
-	"github.com/gorilla/mux"
-	"github.com/lf-edge/ekuiper/internal/conf"
-	"github.com/prometheus/client_golang/prometheus/promhttp"
 	"net/http"
 	"time"
+
+	"github.com/gorilla/mux"
+	"github.com/prometheus/client_golang/prometheus/promhttp"
+
+	"github.com/lf-edge/ekuiper/internal/conf"
 )
 
 func init() {
-	p := promeComp{}
+	p := &promeComp{}
 	servers["prometheus"] = p
 	components["prometheus"] = p
 }
@@ -37,11 +39,11 @@ type promeComp struct {
 	s *http.Server
 }
 
-func (p promeComp) register() {
+func (p *promeComp) register() {
 	// Do nothing
 }
 
-func (p promeComp) rest(r *mux.Router) {
+func (p *promeComp) rest(r *mux.Router) {
 	portPrometheus := conf.Config.Basic.PrometheusPort
 	portRest := conf.Config.Basic.RestPort
 	if portPrometheus == portRest {
@@ -52,7 +54,7 @@ func (p promeComp) rest(r *mux.Router) {
 	}
 }
 
-func (p promeComp) serve() {
+func (p *promeComp) serve() {
 	if conf.Config.Basic.Prometheus {
 		//Start prometheus service
 		portPrometheus := conf.Config.Basic.PrometheusPort
@@ -83,7 +85,7 @@ func (p promeComp) serve() {
 	}
 }
 
-func (p promeComp) close() {
+func (p *promeComp) close() {
 	if p.s != nil {
 		if err := p.s.Shutdown(context.TODO()); err != nil {
 			logger.Errorf("prometheus server shutdown error: %v", err)

+ 10 - 9
internal/server/rpc.go

@@ -22,32 +22,33 @@ import (
 	"context"
 	"encoding/json"
 	"fmt"
-	"github.com/lf-edge/ekuiper/internal/conf"
-	"github.com/lf-edge/ekuiper/internal/io/sink"
-	"github.com/lf-edge/ekuiper/internal/pkg/model"
-	"github.com/lf-edge/ekuiper/internal/topo/rule"
-	"github.com/lf-edge/ekuiper/pkg/infra"
 	"io"
 	"net/http"
 	"net/rpc"
 	"os"
 	"strings"
 	"time"
+
+	"github.com/lf-edge/ekuiper/internal/conf"
+	"github.com/lf-edge/ekuiper/internal/io/sink"
+	"github.com/lf-edge/ekuiper/internal/pkg/model"
+	"github.com/lf-edge/ekuiper/internal/topo/rule"
+	"github.com/lf-edge/ekuiper/pkg/infra"
 )
 
 const QueryRuleId = "internal-ekuiper_query_rule"
 
 func init() {
-	servers["rpc"] = rpcComp{}
+	servers["rpc"] = &rpcComp{}
 }
 
 type rpcComp struct {
 	s *http.Server
 }
 
-func (r rpcComp) register() {}
+func (r *rpcComp) register() {}
 
-func (r rpcComp) serve() {
+func (r *rpcComp) serve() {
 	// Start rpc service
 	server := new(Server)
 	portRpc := conf.Config.Basic.Port
@@ -73,7 +74,7 @@ func (r rpcComp) serve() {
 	initQuery()
 }
 
-func (r rpcComp) close() {
+func (r *rpcComp) close() {
 	if r.s != nil {
 		if err := r.s.Shutdown(context.TODO()); err != nil {
 			logger.Errorf("rpc server shutdown error: %v", err)