Skip to content

Commit

Permalink
upgrade packages version in go.mod and add golangci rules
Browse files Browse the repository at this point in the history
  • Loading branch information
free5gc-org committed Oct 5, 2021
1 parent 533ad32 commit 4705af7
Show file tree
Hide file tree
Showing 8 changed files with 1,096 additions and 51 deletions.
17 changes: 17 additions & 0 deletions .drone.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
kind: pipeline
name: development

steps:
- name: Check coding style
pull: never
image: drone/base:golangci-lint
depends_on: [ clone ]
commands:
- golangci-lint run ./...

- name: Unit test and build
pull: never
image: drone/base:gotest
depends_on: [ clone ]
commands:
- gotestsum ./... -v -cover -race
52 changes: 47 additions & 5 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ run:
# exit code when at least one issue was found, default is 1
issues-exit-code: 1
# include test files or not, default is true
tests: false
tests: true
# list of build tags, all linters use it. Default is empty list.
build-tags:
# which dirs to skip: issues from them won't be reported;
Expand Down Expand Up @@ -203,6 +203,33 @@ linters-settings:
whitespace:
multi-if: false # Enforces newlines (or comments) after every multi-line if statement
multi-func: false # Enforces newlines (or comments) after every multi-line function signature
gci:
local-prefixes: "github.com/free5gc"
misspell:
#locale: US
ignore-words:
whitespace:
multi-if: false # Enforces newlines (or comments) after every multi-line if statement
multi-func: false # Enforces newlines (or comments) after every multi-line function signature
wsl:
# If true append is only allowed to be cuddled if appending value is
# matching variables, fields or types on line above. Default is true.
strict-append: true
# Allow calls and assignments to be cuddled as long as the lines have any
# matching variables, fields or types. Default is true.
allow-assign-and-call: true
# Allow multiline assignments to be cuddled. Default is true.
allow-multiline-assign: true
# Allow declarations (var) to be cuddled.
allow-cuddle-declarations: false
# Allow trailing comments in ending of blocks
allow-trailing-comment: true
# Force newlines in end of case at this limit (0 = never).
force-case-trailing-whitespace: 0
# Force cuddling of err checks with err var assignment
force-err-cuddling: false
# Allow leading comments to be separated with empty liens
allow-separated-leading-comment: false
custom:
# Each custom linter should have a unique name.

Expand All @@ -222,12 +249,27 @@ linters:
# Additional
- lll
- godox
# - gomnd
#- maligned
#- nestif
#- gomnd
#- goconst
#- gocognit
# - gocognit
# - maligned
# - nestif
# - gomodguard
- nakedret
- gci
- misspell
- gofumpt
- whitespace
- unconvert
- predeclared
- noctx
- dogsled
- bodyclose
- asciicheck
#- stylecheck
# - unparam
# - wsl

#disable-all: false
fast: true
issues:
Expand Down
20 changes: 6 additions & 14 deletions aper.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ type perBitData struct {
}

func perTrace(level int, s string) {

_, file, line, ok := runtime.Caller(1)
if !ok {
logger.AperLog.Debugln(s)
Expand All @@ -32,7 +31,6 @@ func perBitLog(numBits uint64, byteOffset uint64, bitsOffset uint, value interfa
}
return fmt.Sprintf(" [PER got %2d bits, byteOffset(after): %d, bitsOffset(after): %d, value: 0x%0x]",
numBits, byteOffset, bitsOffset, reflect.ValueOf(value).Bytes())

}

// GetBitString is to get BitString with desire size from source byte array with bit offset
Expand Down Expand Up @@ -90,7 +88,7 @@ func GetBitsValue(srcBytes []byte, bitsOffset uint, numBits uint) (value uint64,
value <<= 8
value |= uint64(uint(dstBytes[i]))
}
if numBitsOff := uint(numBits & 0x7); numBitsOff != 0 {
if numBitsOff := (numBits & 0x7); numBitsOff != 0 {
var mask uint = (1 << numBitsOff) - 1
value <<= numBitsOff
value |= uint64(uint(dstBytes[len(dstBytes)-1]>>(8-numBitsOff)) & mask)
Expand All @@ -104,12 +102,11 @@ func (pd *perBitData) bitCarry() {
}

func (pd *perBitData) getBitString(numBits uint) (dstBytes []byte, err error) {

dstBytes, err = GetBitString(pd.bytes[pd.byteOffset:], pd.bitsOffset, numBits)
if err != nil {
return
}
pd.bitsOffset += uint(numBits)
pd.bitsOffset += numBits

pd.bitCarry()
perTrace(1, perBitLog(uint64(numBits), pd.byteOffset, pd.bitsOffset, dstBytes))
Expand All @@ -128,7 +125,6 @@ func (pd *perBitData) getBitsValue(numBits uint) (value uint64, err error) {
}

func (pd *perBitData) parseAlignBits() error {

if (pd.bitsOffset & 0x7) > 0 {
alignBits := 8 - ((pd.bitsOffset) & 0x7)
perTrace(2, fmt.Sprintf("Aligning %d bits", alignBits))
Expand Down Expand Up @@ -282,16 +278,15 @@ func (pd *perBitData) parseBitString(extensed bool, lowerBoundPtr *int64, upperB
}
perTrace(1, perBitLog(uint64(ub), pd.byteOffset, pd.bitsOffset, bitString.Bytes))
} else {
if byte, err := pd.getBitString(uint(ub)); err != nil {
if bytes, err := pd.getBitString(uint(ub)); err != nil {
logger.AperLog.Warnf("PD GetBitString error: %+v", err)
return bitString, err
} else {
bitString.Bytes = byte
bitString.Bytes = bytes
}
}
perTrace(2, fmt.Sprintf("Decoded BIT STRING (length = %d): %0.8b", ub, bitString.Bytes))
return bitString, nil

}
repeat := false
for {
Expand Down Expand Up @@ -334,6 +329,7 @@ func (pd *perBitData) parseBitString(extensed bool, lowerBoundPtr *int64, upperB
}
return bitString, nil
}

func (pd *perBitData) parseOctetString(extensed bool, lowerBoundPtr *int64, upperBoundPtr *int64) (
OctetString, error) {
var lb, ub, sizeRange int64 = 0, -1, -1
Expand Down Expand Up @@ -375,7 +371,6 @@ func (pd *perBitData) parseOctetString(extensed bool, lowerBoundPtr *int64, uppe
}
perTrace(2, fmt.Sprintf("Decoded OCTET STRING (length = %d): 0x%0x", ub, octetString))
return octetString, nil

}
repeat := false
for {
Expand Down Expand Up @@ -540,7 +535,6 @@ func (pd *perBitData) parseEnumerated(extensed bool, lowerBoundPtr *int64, upper
}
perTrace(2, fmt.Sprintf("Decoded ENUMERATED Value : %d", value))
return

}

func (pd *perBitData) parseSequenceOf(sizeExtensed bool, params fieldParameters, sliceType reflect.Type) (
Expand Down Expand Up @@ -612,6 +606,7 @@ func (pd *perBitData) getChoiceIndex(extensed bool, upperBoundPtr *int64) (prese
}
return
}

func getReferenceFieldValue(v reflect.Value) (value int64, err error) {
fieldType := v.Type()
switch v.Kind() {
Expand All @@ -637,7 +632,6 @@ func getReferenceFieldValue(v reflect.Value) (value int64, err error) {
}

func (pd *perBitData) parseOpenType(v reflect.Value, params fieldParameters) error {

pdOpenType := &perBitData{[]byte(""), 0, 0}
repeat := false
for {
Expand Down Expand Up @@ -875,7 +869,6 @@ func parseField(v reflect.Value, pd *perBitData, params fieldParameters) error {
perTrace(2, fmt.Sprintf("Decoded PrintableString : \"%s\"", printableString))
return nil
}

}
return fmt.Errorf("unsupported: " + v.Type().String())
}
Expand Down Expand Up @@ -935,5 +928,4 @@ func UnmarshalWithParams(b []byte, value interface{}, params string) error {
v := reflect.ValueOf(value).Elem()
pd := &perBitData{b, 0, 0}
return parseField(v, pd, parseFieldParameters(params))

}

0 comments on commit 4705af7

Please sign in to comment.