Skip to content

Commit

Permalink
fix lint warning
Browse files Browse the repository at this point in the history
  • Loading branch information
chengshiwen committed Aug 14, 2024
1 parent db3e474 commit 2a01513
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 34 deletions.
2 changes: 1 addition & 1 deletion backend/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ func (ib *Backend) Close() {
func (ib *Backend) GetHealth() interface{} {
health := struct {
Name string `json:"name"`
Url string `json:"url"` // nolint:golint
Url string `json:"url"` //nolint:all
Active bool `json:"active"`
Backlog bool `json:"backlog"`
Rewriting bool `json:"rewriting"`
Expand Down
6 changes: 3 additions & 3 deletions backend/circle.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ import (
)

type Circle struct {
CircleId int // nolint:golint
CircleId int //nolint:all
Name string
Backends []*Backend
router *consistent.Consistent
routerCache sync.Map
mapToBackend map[string]*Backend
}

func NewCircle(cfg *CircleConfig, pxcfg *ProxyConfig, circleId int) (ic *Circle) { // nolint:golint
func NewCircle(cfg *CircleConfig, pxcfg *ProxyConfig, circleId int) (ic *Circle) { //nolint:all
ic = &Circle{
CircleId: circleId,
Name: cfg.Name,
Expand Down Expand Up @@ -64,7 +64,7 @@ func (ic *Circle) GetHealth() interface{} {
}
wg.Wait()
circle := struct {
Id int `json:"id"` // nolint:golint
Id int `json:"id"` //nolint:all
Name string `json:"name"`
Active bool `json:"active"`
WriteOnly bool `json:"write_only"`
Expand Down
6 changes: 3 additions & 3 deletions backend/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ var (
ErrEmptyBackends = errors.New("backends cannot be empty")
ErrEmptyBackendName = errors.New("backend name cannot be empty")
ErrDuplicatedBackendName = errors.New("backend name duplicated")
ErrEmptyBackendUrl = errors.New("backend url cannot be empty") // nolint:golint
ErrEmptyBackendUrl = errors.New("backend url cannot be empty") //nolint:all
ErrEmptyBackendToken = errors.New("backend token cannot be empty")
ErrInvalidDBRPMapping = errors.New("invalid dbrp mapping")
)

type BackendConfig struct { // nolint:golint
type BackendConfig struct { //nolint:all
Name string `mapstructure:"name"`
Url string `mapstructure:"url"` // nolint:golint
Url string `mapstructure:"url"` //nolint:all
Token string `mapstructure:"token"`
WriteOnly bool `mapstructure:"write_only"`
}
Expand Down
21 changes: 12 additions & 9 deletions backend/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"
"log"
"net"
"net/http"
Expand Down Expand Up @@ -46,11 +45,11 @@ type QueryResult struct {
Err error
}

type HttpBackend struct { // nolint:golint
type HttpBackend struct { //nolint:all
client *http.Client
transport *http.Transport
Name string
Url string // nolint:golint
Url string //nolint:all
token string
interval int
running atomic.Value
Expand All @@ -60,15 +59,15 @@ type HttpBackend struct { // nolint:golint
writeOnly bool
}

func NewHttpBackend(cfg *BackendConfig, pxcfg *ProxyConfig) (hb *HttpBackend) { // nolint:golint
func NewHttpBackend(cfg *BackendConfig, pxcfg *ProxyConfig) (hb *HttpBackend) { //nolint:all
hb = NewSimpleHttpBackend(cfg)
hb.client = NewClient(strings.HasPrefix(cfg.Url, "https"), pxcfg.WriteTimeout)
hb.interval = pxcfg.CheckInterval
go hb.CheckActive()
return
}

func NewSimpleHttpBackend(cfg *BackendConfig) (hb *HttpBackend) { // nolint:golint
func NewSimpleHttpBackend(cfg *BackendConfig) (hb *HttpBackend) { //nolint:all
hb = &HttpBackend{
transport: NewTransport(strings.HasPrefix(cfg.Url, "https")),
Name: cfg.Name,
Expand Down Expand Up @@ -104,7 +103,7 @@ func NewTransport(tlsSkip bool) *http.Transport {

func CloneQueryRequest(r *http.Request) *http.Request {
cr := r.Clone(r.Context())
cr.Body = ioutil.NopCloser(&bytes.Buffer{})
cr.Body = io.NopCloser(&bytes.Buffer{})
return cr
}

Expand Down Expand Up @@ -194,6 +193,10 @@ func (hb *HttpBackend) WriteStream(org, bucket string, stream io.Reader, compres
q.Set("org", org)
q.Set("bucket", bucket)
req, err := http.NewRequest("POST", hb.Url+"/api/v2/write?"+q.Encode(), stream)
if err != nil {
log.Print("new request error: ", err)
return nil
}
hb.SetAuthorization(req)
if compressed {
req.Header.Add("Content-Encoding", "gzip")
Expand All @@ -212,7 +215,7 @@ func (hb *HttpBackend) WriteStream(org, bucket string, stream io.Reader, compres
}
log.Printf("write status code: %d, from: %s", resp.StatusCode, hb.Url)

respbuf, err := ioutil.ReadAll(resp.Body)
respbuf, err := io.ReadAll(resp.Body)
if err != nil {
log.Print("readall error: ", err)
return
Expand Down Expand Up @@ -264,7 +267,7 @@ func (hb *HttpBackend) QueryFlux(req *http.Request, w http.ResponseWriter) (err

CopyHeader(w.Header(), resp.Header)

p, err := ioutil.ReadAll(resp.Body)
p, err := io.ReadAll(resp.Body)
if err != nil {
log.Printf("flux read body error: %s", err)
return
Expand Down Expand Up @@ -316,7 +319,7 @@ func (hb *HttpBackend) Query(req *http.Request, w http.ResponseWriter, decompres
respBody = b
}

qr.Body, qr.Err = ioutil.ReadAll(respBody)
qr.Body, qr.Err = io.ReadAll(respBody)
if qr.Err != nil {
log.Printf("read body error: %s, the query is %s", qr.Err, q)
return
Expand Down
6 changes: 3 additions & 3 deletions backend/influxql.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ func ScanToken(data []byte, atEOF bool) (advance int, token []byte, err error) {
}

start := 0
for ; start < len(data) && data[start] == ' '; start++ {
for ; start < len(data) && data[start] == ' '; start++ { //revive:disable-line:empty-block
}
if start == len(data) {
return 0, nil, nil
Expand Down Expand Up @@ -300,7 +300,7 @@ func getDatabase(tokens []string, keyword string) (db string) {
return
}

func getRetentionPolicy(tokens []string, keyword string) (rp string) {
func getRetentionPolicy(tokens []string, _ string) (rp string) {
if len(tokens) == 0 {
return
}
Expand All @@ -326,7 +326,7 @@ func getRetentionPolicy(tokens []string, keyword string) (rp string) {
return
}

func getMeasurement(tokens []string, keyword string) (mm string) {
func getMeasurement(tokens []string, _ string) (mm string) {
if len(tokens) == 0 {
return
}
Expand Down
12 changes: 5 additions & 7 deletions backend/lineproto.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,22 +62,20 @@ func AppendNano(line []byte, precision string) []byte {
return append(line, '0', '0', '0', '0', '0', '0')
} else if precision == "s" {
return append(line, '0', '0', '0', '0', '0', '0', '0', '0', '0')
} else {
mul := models.GetPrecisionMultiplier(precision)
nano := BytesToInt64(line[pos+1:]) * mul
return append(line[:pos+1], Int64ToBytes(nano)...)
}
} else {
return append(line, []byte(" "+strconv.FormatInt(time.Now().UnixNano(), 10))...)
mul := models.GetPrecisionMultiplier(precision)
nano := BytesToInt64(line[pos+1:]) * mul
return append(line[:pos+1], Int64ToBytes(nano)...)
}
return append(line, []byte(" "+strconv.FormatInt(time.Now().UnixNano(), 10))...)
}

func Int64ToBytes(n int64) []byte {
return []byte(strconv.FormatInt(n, 10))
}

func BytesToInt64(buf []byte) int64 {
var res int64 = 0
var res int64
var length = len(buf)
for i := 0; i < length; i++ {
res = res*10 + int64(buf[i]-'0')
Expand Down
2 changes: 1 addition & 1 deletion backend/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func NewProxy(cfg *ProxyConfig) (ip *Proxy) {
for key, value := range cfg.DBRP.Mapping {
ip.dbrps[key] = strings.Split(value, cfg.DBRP.Separator)
}
rand.Seed(time.Now().UnixNano())
rand.New(rand.NewSource(time.Now().UnixNano()))
return
}

Expand Down
14 changes: 7 additions & 7 deletions service/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"compress/gzip"
"encoding/json"
"fmt"
"io/ioutil"
"io"
"log"
"mime"
"net/http"
Expand All @@ -34,15 +34,15 @@ func (mux *ServeMux) ServeHTTP(w http.ResponseWriter, r *http.Request) {
mux.ServeMux.ServeHTTP(w, r)
}

type HttpService struct { // nolint:golint
type HttpService struct { //nolint:all
ip *backend.Proxy
token string
writeTracing bool
queryTracing bool
pprofEnabled bool
}

func NewHttpService(cfg *backend.ProxyConfig) (hs *HttpService) { // nolint:golint
func NewHttpService(cfg *backend.ProxyConfig) (hs *HttpService) { //nolint:all
ip := backend.NewProxy(cfg)
hs = &HttpService{
ip: ip,
Expand All @@ -68,7 +68,7 @@ func (hs *HttpService) Register(mux *ServeMux) {
}
}

func (hs *HttpService) HandlerPing(w http.ResponseWriter, req *http.Request) {
func (hs *HttpService) HandlerPing(w http.ResponseWriter, _ *http.Request) {
w.WriteHeader(http.StatusNoContent)
}

Expand Down Expand Up @@ -112,7 +112,7 @@ func (hs *HttpService) HandlerQueryV2(w http.ResponseWriter, req *http.Request)
hs.WriteError(w, req, http.StatusBadRequest, err.Error())
return
}
rbody, err := ioutil.ReadAll(req.Body)
rbody, err := io.ReadAll(req.Body)
if err != nil {
hs.WriteError(w, req, http.StatusBadRequest, err.Error())
return
Expand All @@ -139,7 +139,7 @@ func (hs *HttpService) HandlerQueryV2(w http.ResponseWriter, req *http.Request)
return
}

req.Body = ioutil.NopCloser(bytes.NewBuffer(rbody))
req.Body = io.NopCloser(bytes.NewBuffer(rbody))
err = hs.ip.QueryFlux(w, req, org, qr)
if err != nil {
log.Printf("flux query error: %s, query: %s, spec: %s, org: %s, client: %s", err, qr.Query, qr.Spec, org, req.RemoteAddr)
Expand Down Expand Up @@ -227,7 +227,7 @@ func (hs *HttpService) handlerWrite(org, bucket, precision string, w http.Respon
defer b.Close()
body = b
}
p, err := ioutil.ReadAll(body)
p, err := io.ReadAll(body)
if err != nil {
hs.WriteError(w, req, http.StatusBadRequest, err.Error())
return
Expand Down

0 comments on commit 2a01513

Please sign in to comment.