build: support .golangci.yaml
add .golangci.yaml and fix warning Signed-off-by: Tonghao Zhang <tonghao@bamaicloud.com>
This commit is contained in:
parent
1c5155e15a
commit
e6b9b84e24
|
@ -0,0 +1,128 @@
|
|||
---
|
||||
linters:
|
||||
disable-all: true
|
||||
enable:
|
||||
- goimports
|
||||
- gosimple
|
||||
- ineffassign # Detects when assignments to existing variables are not used
|
||||
- unconvert # Remove unnecessary type conversions
|
||||
- exportloopref # Checks for pointers to enclosing loop variables
|
||||
- tenv # Detects using os.Setenv instead of t.Setenv since Go 1.17
|
||||
- dupword # Checks for duplicate words in the source code
|
||||
- gofmt # Gofmt checks whether code was gofmt-ed
|
||||
- bodyclose # checks whether HTTP response body is closed successfully
|
||||
- misspell
|
||||
- staticcheck
|
||||
- typecheck
|
||||
- unused
|
||||
- loggercheck
|
||||
- nakedret
|
||||
- gofumpt
|
||||
- musttag
|
||||
- whitespace
|
||||
- dupword
|
||||
- gocritic
|
||||
- usestdlibvars
|
||||
- gosec
|
||||
- govet
|
||||
- nolintlint
|
||||
- unused
|
||||
- errcheck
|
||||
- errname
|
||||
- errorlint
|
||||
- fatcontext
|
||||
- gocheckcompilerdirectives
|
||||
- inamedparam
|
||||
|
||||
# Could be enabled later:
|
||||
# - gocyclo
|
||||
# - prealloc
|
||||
# - maligned
|
||||
|
||||
linters-settings:
|
||||
unused:
|
||||
# Mark all struct fields that have been written to as used.
|
||||
# Default: true
|
||||
field-writes-are-uses: false
|
||||
# Mark all local variables as used.
|
||||
# default: true
|
||||
local-variables-are-used: false
|
||||
misspell:
|
||||
# Correct spellings using locale preferences for US or UK.
|
||||
# Setting locale to US will correct the British spelling of 'colour' to 'color'.
|
||||
# Default is to use a neutral variety of English.
|
||||
locale: US
|
||||
gofumpt:
|
||||
# Choose whether to use the extra rules.
|
||||
# Default: false
|
||||
extra-rules: true
|
||||
# Module path which contains the source code being formatted.
|
||||
module-path: huatuo-bamai
|
||||
gocritic:
|
||||
enabled-tags:
|
||||
- diagnostic
|
||||
- style
|
||||
- performance
|
||||
- experimental
|
||||
- opinionated
|
||||
disabled-checks:
|
||||
- commentedOutCode
|
||||
- deferInLoop
|
||||
- evalOrder
|
||||
- exitAfterDefer
|
||||
- exposedSyncMutex
|
||||
- ifElseChain
|
||||
- importShadow
|
||||
- sloppyReassign
|
||||
- unnamedResult
|
||||
- whyNoLint
|
||||
- filepathJoin
|
||||
nolintlint:
|
||||
allow-unused: true
|
||||
gosec:
|
||||
# https://github.com/securego/gosec#available-rules
|
||||
#
|
||||
# The following issues surfaced when `gosec` linter
|
||||
# was enabled.
|
||||
# Disable G115:
|
||||
# "G115: integer overflow conversion int8 -> uint64 (gosec)"
|
||||
excludes:
|
||||
- G107
|
||||
- G115
|
||||
- G204
|
||||
- G401
|
||||
- G501
|
||||
exclude-dirs:
|
||||
- pkg/tracing
|
||||
- vendor
|
||||
issues:
|
||||
# List of regexps of issue texts to exclude.
|
||||
#
|
||||
# But independently of this option we use default exclude patterns,
|
||||
# it can be disabled by `exclude-use-default: false`.
|
||||
# To list all excluded by default patterns execute `golangci-lint run --help`
|
||||
#
|
||||
# Default: https://golangci-lint.run/usage/false-positives/#default-exclusions
|
||||
#
|
||||
# _xxx as used var.
|
||||
exclude:
|
||||
- "^(var|field) `_.*` is unused$"
|
||||
exclude-rules:
|
||||
- linters:
|
||||
- revive
|
||||
text: "if-return"
|
||||
- linters:
|
||||
- revive
|
||||
text: "empty-block"
|
||||
- linters:
|
||||
- revive
|
||||
text: "superfluous-else"
|
||||
- linters:
|
||||
- revive
|
||||
text: "unused-parameter"
|
||||
- linters:
|
||||
- revive
|
||||
text: "unreachable-code"
|
||||
- linters:
|
||||
- revive
|
||||
text: "redefines-builtin-id"
|
|
@ -16,36 +16,10 @@ package collector
|
|||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/binary"
|
||||
"io"
|
||||
"os"
|
||||
|
||||
"huatuo-bamai/internal/log"
|
||||
)
|
||||
|
||||
// xfs_util maps superblocks of XFS devices to retrieve
|
||||
// essential information from superblock.
|
||||
const (
|
||||
XFS_SB_MAGIC = 0x58465342
|
||||
XFSLABEL_MAX = 12
|
||||
)
|
||||
|
||||
// Construct the XFS superblock, hiding unused variables
|
||||
type xfsSuperBlock struct {
|
||||
SbMagicnum uint32
|
||||
SbBlocksize uint32
|
||||
_ [16]byte
|
||||
_ [7]uint64
|
||||
_ [4]uint32
|
||||
SbLogblocks uint32
|
||||
_ [6]uint16
|
||||
_ [XFSLABEL_MAX]byte
|
||||
_ [12]uint8
|
||||
_ [8]uint64
|
||||
_ [12]uint32
|
||||
_ [16]byte
|
||||
}
|
||||
|
||||
func fileLineCounter(filePath string) (int, error) {
|
||||
count := 0
|
||||
buf := make([]byte, 8*20*4096)
|
||||
|
@ -73,29 +47,3 @@ func fileLineCounter(filePath string) (int, error) {
|
|||
|
||||
return count, nil
|
||||
}
|
||||
|
||||
// Calculate the Xlog size from superblock
|
||||
func xfsLogSize(path string) (float64, error) {
|
||||
file, err := os.Open(path)
|
||||
if err != nil {
|
||||
log.Infof("open failed: %v", err)
|
||||
return -1, err
|
||||
}
|
||||
defer file.Close()
|
||||
|
||||
var sb xfsSuperBlock
|
||||
err = binary.Read(file, binary.BigEndian, &sb)
|
||||
if err != nil {
|
||||
log.Infof("read superblock failed: err%v", err)
|
||||
return -1, err
|
||||
}
|
||||
|
||||
// Check Magic Number of Super Block
|
||||
if sb.SbMagicnum != XFS_SB_MAGIC {
|
||||
log.Infof("Not a valid XFS superblock (Magic: 0x%x)", sb.SbMagicnum)
|
||||
return -1, err
|
||||
}
|
||||
|
||||
xlogBytes := float64(sb.SbLogblocks * sb.SbBlocksize)
|
||||
return xlogBytes, nil
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue