Skip to content

Commit

Permalink
happy lint
Browse files Browse the repository at this point in the history
  • Loading branch information
yuzhichang committed Apr 8, 2021
1 parent 234b013 commit 10513e1
Show file tree
Hide file tree
Showing 16 changed files with 109 additions and 108 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ jobs:
uses: golangci/golangci-lint-action@v2
with:
# Required: the version of golangci-lint is required and must be specified without patch version: we always use the latest patch version.
version: v1.37
version: v1.39

# Optional: working directory, useful for monorepos
# working-directory: somedir

# Optional: golangci-lint command line arguments.
args: --issues-exit-code=0 --disable=nakedret,exhaustivestruct,wrapcheck,paralleltest,rowserrcheck,cyclop
args: --issues-exit-code=0 --disable=nakedret,exhaustivestruct,wrapcheck,paralleltest,rowserrcheck,cyclop,scopelint,nilerr

# Optional: show only new issues if it's a pull request. The default value is `false`.
# only-new-issues: true
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ benchtest: pre
systest: build
bash go.test.sh
lint:
golangci-lint run --issues-exit-code=0 --disable=nakedret,exhaustivestruct,wrapcheck,paralleltest,rowserrcheck,cyclop
golangci-lint run --issues-exit-code=0 --disable=nakedret,exhaustivestruct,wrapcheck,paralleltest,rowserrcheck,cyclop,scopelint,nilerr
run: pre
go run cmd/clickhouse_sinker/main.go --local-cfg-dir conf/

Expand Down
8 changes: 4 additions & 4 deletions config/nacos.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,18 @@ func (ncm *NacosConfManager) Init(properties map[string]interface{}) (err error)

var clientDir string
if v, ok := properties["clientDir"]; ok {
clientDir = v.(string)
clientDir, _ = v.(string)
} else {
clientDir = "/tmp/nacos"
}
var namespaceID string //Neither DEFAULT_NAMESPACE_ID("public") nor namespace name work!
group := constant.DEFAULT_GROUP //Empty string doesn't work!
var ok bool
if _, ok = properties["namespaceId"]; ok {
namespaceID = properties["namespaceId"].(string)
namespaceID, _ = properties["namespaceId"].(string)
}
if _, ok = properties["group"]; ok {
group = properties["group"].(string)
group, _ = properties["group"].(string)
}
cc := constant.ClientConfig{
NamespaceId: namespaceID,
Expand All @@ -77,7 +77,7 @@ func (ncm *NacosConfManager) Init(properties map[string]interface{}) (err error)

ncm.group = group
if _, ok = properties["dataId"]; ok {
ncm.dataID = properties["dataId"].(string)
ncm.dataID, _ = properties["dataId"].(string)
}
return
}
Expand Down
2 changes: 1 addition & 1 deletion docs/dev/introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Refers to [design](./design.md) for how it works.
- [x] UInt8, UInt16, UInt32, UInt64, Int8, Int16, Int32, Int64
- [x] Float32, Float64
- [x] String, FixedString, LowCardinality(String)
- [x] Date, DateTime, DateTime64. Support [these layouts](https://github.com/housepower/clickhouse_sinker/blob/master/parser/parser.go).
- [x] Date, DateTime, DateTime64. Automatically detect [these date formats](https://github.com/housepower/clickhouse_sinker/blob/master/parser/parser.go).
- [x] Array(T), where T is one of above basic types
- [x] Nullable(T), where T is one of above basic types
- [x] [ElasticDateTime](https://www.elastic.co/guide/en/elasticsearch/reference/current/date.html) => Int64 (2019-12-16T12:10:30Z => 1576498230)
Expand Down
2 changes: 1 addition & 1 deletion model/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func (bs *BatchSys) TryCommit() error {
// ensure groups be committed orderly
LOOP:
for e := bs.groups.Front(); e != nil; {
grp := e.Value.(*BatchGroup)
grp, _ := e.Value.(*BatchGroup)
if atomic.LoadInt32(&grp.PendWrite) != 0 {
break LOOP
}
Expand Down
7 changes: 4 additions & 3 deletions output/clickhouse.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,8 +245,8 @@ func (c *ClickHouse) ChangeSchema(newKeys *sync.Map) (err error) {
log.Warnf("number of columns reaches upper limit %d", maxDims)
return false
}
strKey := key.(string)
strVal := value.(string)
strKey, _ := key.(string)
strVal, _ := value.(string)
switch strVal {
case "int":
strVal = "Nullable(Int64)"
Expand Down Expand Up @@ -292,7 +292,8 @@ func (c *ClickHouse) getDistTbls() (distTbls []string, err error) {
taskCfg := &c.cfg.Task
chCfg := &c.cfg.Clickhouse
conn := pool.GetConn(0)
query := fmt.Sprintf(`SELECT name FROM system.tables WHERE engine='Distributed' AND database='%s' AND match(create_table_query, 'Distributed.*\'%s\',\s*\'%s\'')`, chCfg.DB, chCfg.DB, taskCfg.TableName)
query := fmt.Sprintf(`SELECT name FROM system.tables WHERE engine='Distributed' AND database='%s' AND match(create_table_query, 'Distributed.*\'%s\',\s*\'%s\'')`,
chCfg.DB, chCfg.DB, taskCfg.TableName)
log.Infof("%s: executing sql=> %s", taskCfg.Name, query)

var rows *sql.Rows
Expand Down
14 changes: 7 additions & 7 deletions parser/csv.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ var _ Parser = (*CsvParser)(nil)

// CsvParser implementation to parse input from a CSV format per RFC 4180
type CsvParser struct {
pp *ParserPool
pp *Pool
}

// Parse extract a list of comma-separated values from the data
Expand All @@ -51,7 +51,7 @@ func (p *CsvParser) Parse(bs []byte) (metric model.Metric, err error) {

// CsvMetic
type CsvMetric struct {
pp *ParserPool
pp *Pool
values []string
}

Expand Down Expand Up @@ -106,7 +106,7 @@ func (c *CsvMetric) GetArray(key string, t string) interface{} {
var err error
var array []string
var r *csv.Reader
val := c.GetString(key, false).(string)
val, _ := c.GetString(key, false).(string)
valLen := len(val)
if val == "" || val[0] != '[' || val[valLen-1] != ']' {
goto QUIT
Expand Down Expand Up @@ -151,26 +151,26 @@ QUIT:
func (c *CsvMetric) GetDate(key string, nullable bool) interface{} {
_ = nullable // nullable can not be supported with csv

val := c.GetString(key, false).(string)
val, _ := c.GetString(key, false).(string)
t, _ := c.pp.ParseDateTime(key, val)
return t
}

func (c *CsvMetric) GetDateTime(key string, nullable bool) interface{} {
val := c.GetString(key, false).(string)
val, _ := c.GetString(key, false).(string)
t, _ := c.pp.ParseDateTime(key, val)
return t
}

func (c *CsvMetric) GetDateTime64(key string, nullable bool) interface{} {
val := c.GetString(key, false).(string)
val, _ := c.GetString(key, false).(string)
t, _ := c.pp.ParseDateTime(key, val)
return t
}

func (c *CsvMetric) GetElasticDateTime(key string, nullable bool) interface{} {
_ = nullable // nullable can not be supported with csv
val := c.GetString(key, false).(string)
val, _ := c.GetString(key, false).(string)
t, _ := time.Parse(time.RFC3339, val)

return t.Unix()
Expand Down
46 changes: 23 additions & 23 deletions parser/csv_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@ func TestCsvInt(t *testing.T) {

var exp, act int64
exp = 1536813227
act = metric.GetInt("its", false).(int64)
act, _ = metric.GetInt("its", false).(int64)
require.Equal(t, exp, act)

exp = 0
act = metric.GetInt("not_exist", false).(int64)
act, _ = metric.GetInt("not_exist", false).(int64)
require.Equal(t, exp, act)

act = metric.GetInt("not_exist", true).(int64)
act, _ = metric.GetInt("not_exist", true).(int64)
require.Equal(t, exp, act)
}

Expand All @@ -50,14 +50,14 @@ func TestCsvFloat(t *testing.T) {

var exp, act float64
exp = 0.11
act = metric.GetFloat("percent", false).(float64)
act, _ = metric.GetFloat("percent", false).(float64)
require.Equal(t, exp, act)

exp = 0.0
act = metric.GetFloat("not_exist", false).(float64)
act, _ = metric.GetFloat("not_exist", false).(float64)
require.Equal(t, exp, act)

act = metric.GetFloat("not_exist", true).(float64)
act, _ = metric.GetFloat("not_exist", true).(float64)
require.Equal(t, exp, act)
}

Expand All @@ -70,14 +70,14 @@ func TestCsvString(t *testing.T) {

var exp, act string
exp = `escaped_"ws`
act = metric.GetString("channel", false).(string)
act, _ = metric.GetString("channel", false).(string)
require.Equal(t, exp, act)

exp = ""
act = metric.GetString("not_exist", false).(string)
act, _ = metric.GetString("not_exist", false).(string)
require.Equal(t, exp, act)

act = metric.GetString("not_exist", true).(string)
act, _ = metric.GetString("not_exist", true).(string)
require.Equal(t, exp, act)
}

Expand All @@ -90,7 +90,7 @@ func TestCsvDate(t *testing.T) {

var exp, act time.Time
exp = time.Date(2019, 12, 16, 0, 0, 0, 0, time.Local)
act = metric.GetDate("date1", false).(time.Time)
act, _ = metric.GetDate("date1", false).(time.Time)
require.Equal(t, exp, act)
}

Expand All @@ -103,7 +103,7 @@ func TestCsvDateTime(t *testing.T) {

var exp, act time.Time
exp = time.Date(2019, 12, 16, 12, 10, 30, 0, time.UTC)
act = metric.GetDateTime("time_sec_rfc3339_1", false).(time.Time)
act, _ = metric.GetDateTime("time_sec_rfc3339_1", false).(time.Time)
require.Equal(t, exp, act)

exp = time.Date(2019, 12, 16, 12, 10, 30, 0, time.FixedZone("CST", 8*60*60)).In(time.UTC)
Expand All @@ -115,7 +115,7 @@ func TestCsvDateTime(t *testing.T) {
require.Equal(t, exp, act)

exp = time.Time{}
act = metric.GetDateTime("not_exist", false).(time.Time)
act, _ = metric.GetDateTime("not_exist", false).(time.Time)
require.Equal(t, exp, act)
}

Expand All @@ -128,7 +128,7 @@ func TestCsvDateTime64(t *testing.T) {

var exp, act time.Time
exp = time.Date(2019, 12, 16, 12, 10, 30, 123000000, time.UTC)
act = metric.GetDateTime64("time_ms_rfc3339_1", false).(time.Time)
act, _ = metric.GetDateTime64("time_ms_rfc3339_1", false).(time.Time)
require.Equal(t, exp, act)

exp = time.Date(2019, 12, 16, 12, 10, 30, 123000000, time.FixedZone("CST", 8*60*60)).In(time.UTC)
Expand All @@ -140,7 +140,7 @@ func TestCsvDateTime64(t *testing.T) {
require.Equal(t, exp, act)

exp = time.Time{}
act = metric.GetDateTime64("not_exist", false).(time.Time)
act, _ = metric.GetDateTime64("not_exist", false).(time.Time)
require.Equal(t, exp, act)
}

Expand All @@ -155,14 +155,14 @@ func TestCsvElasticDateTime(t *testing.T) {
// {"date": "2019-12-16T12:10:30Z"}
// TZ=UTC date -d @1576498230 => Mon 16 Dec 2019 12:10:30 PM UTC
exp = 1576498230
act = metric.GetElasticDateTime("time_sec_rfc3339_1", false).(int64)
act, _ = metric.GetElasticDateTime("time_sec_rfc3339_1", false).(int64)
require.Equal(t, exp, act)

exp = -62135596800
act = metric.GetElasticDateTime("not_exist", false).(int64)
act, _ = metric.GetElasticDateTime("not_exist", false).(int64)
require.Equal(t, exp, act)

act = metric.GetElasticDateTime("not_exist", true).(int64)
act, _ = metric.GetElasticDateTime("not_exist", true).(int64)
require.Equal(t, exp, act)
}

Expand All @@ -173,27 +173,27 @@ func TestCsvArray(t *testing.T) {
metric, err := parser.Parse(csvSample)
require.Nil(t, err)

actI := metric.GetArray("array_int", "int").([]int64)
actI, _ := metric.GetArray("array_int", "int").([]int64)
expI := []int64{1, 2, 3}
require.Equal(t, expI, actI)

actF := metric.GetArray("array_float", "float").([]float64)
actF, _ := metric.GetArray("array_float", "float").([]float64)
expF := []float64{1.1, 2.2, 3.3}
require.Equal(t, expF, actF)

actS := metric.GetArray("array_string", "string").([]string)
actS, _ := metric.GetArray("array_string", "string").([]string)
expS := []string{"aa", "bb", "cc"}
require.Equal(t, expS, actS)

actIE := metric.GetArray("array_empty", "int").([]int64)
actIE, _ := metric.GetArray("array_empty", "int").([]int64)
expIE := []int64{}
require.Equal(t, expIE, actIE)

actFE := metric.GetArray("array_empty", "float").([]float64)
actFE, _ := metric.GetArray("array_empty", "float").([]float64)
expFE := []float64{}
require.Equal(t, expFE, actFE)

actSE := metric.GetArray("array_empty", "string").([]string)
actSE, _ := metric.GetArray("array_empty", "string").([]string)
expSE := []string{}
require.Equal(t, expSE, actSE)
}
14 changes: 7 additions & 7 deletions parser/fastjson.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ var _ Parser = (*FastjsonParser)(nil)

// FastjsonParser, parser for get data in json format
type FastjsonParser struct {
pp *ParserPool
pp *Pool
fjp fastjson.Parser
}

Expand All @@ -44,7 +44,7 @@ func (p *FastjsonParser) Parse(bs []byte) (metric model.Metric, err error) {
}

type FastjsonMetric struct {
pp *ParserPool
pp *Pool
value *fastjson.Value
}

Expand Down Expand Up @@ -136,7 +136,7 @@ func (c *FastjsonMetric) GetDate(key string, nullable bool) interface{} {
return nil
}

val := c.GetString(key, false).(string)
val, _ := c.GetString(key, false).(string)
t, _ := c.pp.ParseDateTime(key, val)
return t
}
Expand All @@ -146,11 +146,11 @@ func (c *FastjsonMetric) GetDateTime(key string, nullable bool) interface{} {
return nil
}

if v := c.GetFloat(key, false).(float64); v != 0 {
if v, _ := c.GetFloat(key, false).(float64); v != 0 {
return time.Unix(int64(v), int64(v*1e9)%1e9)
}

val := c.GetString(key, false).(string)
val, _ := c.GetString(key, false).(string)
t, _ := c.pp.ParseDateTime(key, val)
return t
}
Expand All @@ -160,11 +160,11 @@ func (c *FastjsonMetric) GetDateTime64(key string, nullable bool) interface{} {
return nil
}

if v := c.GetFloat(key, false).(float64); v != 0 {
if v, _ := c.GetFloat(key, false).(float64); v != 0 {
return time.Unix(int64(v), int64(v*1e9)%1e9)
}

val := c.GetString(key, false).(string)
val, _ := c.GetString(key, false).(string)
t, _ := c.pp.ParseDateTime(key, val)
return t
}
Expand Down
Loading

0 comments on commit 10513e1

Please sign in to comment.