diff --git a/docker/script/run_format.sh b/docker/script/run_format.sh index 36d371a22..77458ac38 100755 --- a/docker/script/run_format.sh +++ b/docker/script/run_format.sh @@ -15,7 +15,7 @@ popd export PATH=$PATH:/go/bin -for subdir in blockcache storage cli lcnode +for subdir in proto blockcache storage cli lcnode do pushd ${CurrentPath}/../../${subdir} go generate ./... diff --git a/proto/admin_proto.go b/proto/admin_proto.go index 6bf3bee75..18139ba4f 100644 --- a/proto/admin_proto.go +++ b/proto/admin_proto.go @@ -999,12 +999,12 @@ type ClientReportLimitInfo struct { FactorMap map[uint32]*ClientLimitInfo Host string Status uint8 - reserved string + _ string // reserved } func NewClientReportLimitInfo() *ClientReportLimitInfo { return &ClientReportLimitInfo{ - FactorMap: make(map[uint32]*ClientLimitInfo, 0), + FactorMap: make(map[uint32]*ClientLimitInfo), } } @@ -1015,13 +1015,13 @@ type LimitRsp2Client struct { HitTriggerCnt uint8 FactorMap map[uint32]*ClientLimitInfo Magnify map[uint32]uint32 - reserved string + _ string // reserved } func NewLimitRsp2Client() *LimitRsp2Client { limit := &LimitRsp2Client{ - FactorMap: make(map[uint32]*ClientLimitInfo, 0), - Magnify: make(map[uint32]uint32, 0), + FactorMap: make(map[uint32]*ClientLimitInfo), + Magnify: make(map[uint32]uint32), } return limit } diff --git a/proto/extent_key.go b/proto/extent_key.go index baaeea1c3..8ca77131c 100644 --- a/proto/extent_key.go +++ b/proto/extent_key.go @@ -239,11 +239,6 @@ func (k *ExtentKey) MarshalBinaryExt(data []byte) { // MarshalBinary marshals the binary format of the extent key. func (k *ExtentKey) MarshalBinary(v3 bool) ([]byte, error) { - extLen := ExtentLength - if v3 { - extLen += ExtentVerFieldSize - } - buf := bytes.NewBuffer(make([]byte, 0, ExtentLength)) if err := binary.Write(buf, binary.BigEndian, k.FileOffset); err != nil { return nil, err diff --git a/proto/lifecycle.go b/proto/lifecycle.go index e84aa1ff1..4b4b2f563 100644 --- a/proto/lifecycle.go +++ b/proto/lifecycle.go @@ -122,7 +122,7 @@ type BatchDentries struct { func NewBatchDentries() *BatchDentries { return &BatchDentries{ - dentries: make(map[uint64]*ScanDentry, 0), + dentries: make(map[uint64]*ScanDentry), } } @@ -146,6 +146,6 @@ func (f *BatchDentries) BatchGetAndClear() (map[uint64]*ScanDentry, []uint64) { for i := range f.dentries { inodes = append(inodes, i) } - f.dentries = make(map[uint64]*ScanDentry, 0) + f.dentries = make(map[uint64]*ScanDentry) return dentries, inodes } diff --git a/proto/mount_options.go b/proto/mount_options.go index 0640bb9fe..710b2e3be 100644 --- a/proto/mount_options.go +++ b/proto/mount_options.go @@ -187,7 +187,7 @@ func ParseMountOptions(opts []MountOption, cfg *config.Config) { opts[i].value = v } } - fmt.Println(fmt.Sprintf("keyword[%v] value[%v] type[%T]", opts[i].keyword, opts[i].value, v)) + fmt.Printf("keyword[%v] value[%v] type[%T]\n", opts[i].keyword, opts[i].value, v) case int64: if opts[i].cmdlineValue != "" { @@ -199,7 +199,7 @@ func ParseMountOptions(opts []MountOption, cfg *config.Config) { opts[i].value = v } } - fmt.Println(fmt.Sprintf("keyword[%v] value[%v] type[%T]", opts[i].keyword, opts[i].value, v)) + fmt.Printf("keyword[%v] value[%v] type[%T]\n", opts[i].keyword, opts[i].value, v) case bool: if opts[i].cmdlineValue != "" { @@ -211,10 +211,10 @@ func ParseMountOptions(opts []MountOption, cfg *config.Config) { opts[i].value = v } } - fmt.Println(fmt.Sprintf("keyword[%v] value[%v] type[%T]", opts[i].keyword, opts[i].value, v)) + fmt.Printf("keyword[%v] value[%v] type[%T]\n", opts[i].keyword, opts[i].value, v) default: - fmt.Println(fmt.Sprintf("keyword[%v] unknown type[%T]", opts[i].keyword, v)) + fmt.Printf("keyword[%v] unknown type[%T]\n", opts[i].keyword, v) } } } diff --git a/proto/packet.go b/proto/packet.go index 2f97ae176..2a108c002 100644 --- a/proto/packet.go +++ b/proto/packet.go @@ -707,14 +707,10 @@ func (p *Packet) MarshalHeader(out []byte) { if p.Opcode == OpRandomWriteVer || p.ExtentType&MultiVersionFlag > 0 { binary.BigEndian.PutUint64(out[util.PacketHeaderSize:util.PacketHeaderSize+8], p.VerSeq) } - return } func (p *Packet) IsVersionList() bool { - if p.ExtentType&VersionListFlag == VersionListFlag { - return true - } - return false + return p.ExtentType&VersionListFlag == VersionListFlag } // UnmarshalHeader unmarshals the packet header. @@ -943,9 +939,6 @@ func (p *Packet) ReadFromConnWithVer(c net.Conn, timeoutSec int) (err error) { } } - if p.Size < 0 { - return syscall.EBADMSG - } size := p.Size if p.IsReadOperation() && p.ResultCode == OpInitResultCode { size = 0 @@ -990,9 +983,6 @@ func (p *Packet) ReadFromConn(c net.Conn, timeoutSec int) (err error) { } } - if p.Size < 0 { - return syscall.EBADMSG - } size := p.Size if (p.Opcode == OpRead || p.Opcode == OpStreamRead || p.Opcode == OpExtentRepairRead || p.Opcode == OpStreamFollowerRead) && p.ResultCode == OpInitResultCode { size = 0 diff --git a/proto/perm_action.go b/proto/perm_action.go index e0b6022f0..2c841f394 100644 --- a/proto/perm_action.go +++ b/proto/perm_action.go @@ -21,8 +21,8 @@ import ( ) var ( - actionRegexp = regexp.MustCompile("^action:((oss:(\\w+))|(posix:(\\w)+))$") - actionPrefixRegexp = regexp.MustCompile("^action:((oss)|(posix)):") + actionRegexp = regexp.MustCompile(`^action:((oss:(\w+))|(posix:(\w)+))$`) + actionPrefixRegexp = regexp.MustCompile(`^action:((oss)|(posix)):`) ) type Action string @@ -380,12 +380,12 @@ const ( ) var ( - permRegexp = regexp.MustCompile("^perm:((builtin:((.*/*)([^/]*):*)(Writable|ReadOnly))|(custom:(\\w)+))$") - builtinPermRegexp = regexp.MustCompile("^perm:builtin:((.*/*)([^/]*):*)(Writable|ReadOnly)$") - builtinWritablePermRegexp = regexp.MustCompile("^perm:builtin:((.*/*)([^/]*):*)Writable$") - builtinReadOnlyPermRegexp = regexp.MustCompile("^perm:builtin:((.*/*)([^/]*):*)ReadOnly$") - customPermRegexp = regexp.MustCompile("^perm:custom:(\\w)+$") - subdirRegexp = regexp.MustCompile("((.*/*)([^/]*)):(Writable|ReadOnly)$") + permRegexp = regexp.MustCompile(`^perm:((builtin:((.*/*)([^/]*):*)(Writable|ReadOnly))|(custom:(\w)+))$`) + builtinPermRegexp = regexp.MustCompile(`^perm:builtin:((.*/*)([^/]*):*)(Writable|ReadOnly)$`) + builtinWritablePermRegexp = regexp.MustCompile(`^perm:builtin:((.*/*)([^/]*):*)Writable$`) + builtinReadOnlyPermRegexp = regexp.MustCompile(`^perm:builtin:((.*/*)([^/]*):*)ReadOnly$`) + customPermRegexp = regexp.MustCompile(`^perm:custom:(\w)+$`) + subdirRegexp = regexp.MustCompile(`((.*/*)([^/]*)):(Writable|ReadOnly)$`) ) func ParsePermission(value string) Permission { diff --git a/proto/transaction.go b/proto/transaction.go index 632190560..b6ee78163 100644 --- a/proto/transaction.go +++ b/proto/transaction.go @@ -607,8 +607,8 @@ const initTmId = -1 func NewTransactionInfo(timeout int64, txType uint32) *TransactionInfo { return &TransactionInfo{ Timeout: timeout, - TxInodeInfos: make(map[uint64]*TxInodeInfo, 0), - TxDentryInfos: make(map[string]*TxDentryInfo, 0), + TxInodeInfos: make(map[uint64]*TxInodeInfo), + TxDentryInfos: make(map[string]*TxDentryInfo), TmID: initTmId, TxType: txType, State: TxStateInit, @@ -616,10 +616,7 @@ func NewTransactionInfo(timeout int64, txType uint32) *TransactionInfo { } func (txInfo *TransactionInfo) IsInitialized() bool { - if txInfo.TxID != "" { - return true - } - return false + return txInfo.TxID != "" } func (txInfo *TransactionInfo) String() string { diff --git a/proto/user_proto.go b/proto/user_proto.go index 60e94bea6..d280ba8fc 100644 --- a/proto/user_proto.go +++ b/proto/user_proto.go @@ -187,7 +187,6 @@ func (policy *UserPolicy) IsAuthorizedS3(volume, api string) bool { if builtinReadOnlyPermRegexp.MatchString(perm) && !contain(api, WriteS3Api) { return true } - return false } return false } diff --git a/proto/version.go b/proto/version.go index 335743308..e17b7e36a 100644 --- a/proto/version.go +++ b/proto/version.go @@ -5,6 +5,9 @@ import ( "runtime" ) +//TODO: remove this later. +//go:generate golangci-lint run --issues-exit-code=1 -D errcheck -E bodyclose . + var ( Version string CommitID string