Skip to content

Commit

Permalink
Merge pull request #14 from andy89923/feature/add-linter
Browse files Browse the repository at this point in the history
Feature: Add golangci-lint CI
  • Loading branch information
ianchen0119 authored Jan 11, 2024
2 parents ae747c9 + 14f6077 commit ccd503d
Show file tree
Hide file tree
Showing 85 changed files with 491 additions and 473 deletions.
47 changes: 47 additions & 0 deletions .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: golangci-lint

on:
push:
tags:
- v*
branches: [ main ]
pull_request:
branches: [ main ]

jobs:
golangci:
name: lint
runs-on: ubuntu-latest
strategy:
matrix:
go: [ '1.18' ]
steps:
- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: ${{ matrix.go }}
- uses: actions/checkout@v3
- name: Run golangci-lint
uses: golangci/golangci-lint-action@v3
with:
# Optional: version of golangci-lint to use in form of v1.2 or v1.2.3 or `latest` to use the latest version
version: v1.45.2

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

# Optional: golangci-lint command line arguments.
# args: --issues-exit-code=0

# Optional: show only new issues if it's a pull request. The default value is `false`.
# only-new-issues: true

# Optional: if set to true then the all caching functionality will be complete disabled,
# takes precedence over all other caching options.
# skip-cache: true

# Optional: if set to true then the action don't cache or restore ~/go/pkg.
# skip-pkg-cache: true

# Optional: if set to true then the action don't cache or restore ~/.cache/go-build.
# skip-build-cache: true
5 changes: 3 additions & 2 deletions cdr/asn/ber_marshal.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ func (i int64Encoder) Len() int {
func (i int64Encoder) Encode(dst []byte) {
n := i.Len()
// i2 := i

for j := 0; j < n; j++ {
dst[n-1-j] = byte(i)
i >>= 8
Expand Down Expand Up @@ -279,7 +278,9 @@ func makeField(v reflect.Value, params fieldParameters) (encoder, error) {
tempParams := parseFieldParameters(structType.Field(i).Tag.Get("ber"))
if tempParams.optional {
if v.Field(i).IsNil() {
//berTrace(3, fmt.Sprintf("Field \"%s\" in %s is OPTIONAL and not present", structType.Field(i).Name, structType))
//berTrace(
// 3, fmt.Sprintf("Field \"%s\" in %s is OPTIONAL and not present", structType.Field(i).Name, structType)
// )
s[i] = bytesEncoder(nil)
continue
} /*else {
Expand Down
83 changes: 41 additions & 42 deletions cdr/asn/ber_unmarshal.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ func parseTagAndLength(bytes []byte) (r tagAndLen, off int, e error) {
}
if off > 10 {
e = fmt.Errorf("tag number is too large")
return
return r, off, e
}
}

if off >= len(bytes) {
// fmt.Println(bytes)
e = fmt.Errorf("panic")
return
return r, off, e
}
if bytes[off] <= 127 {
r.len = int64(bytes[off])
Expand All @@ -40,21 +40,21 @@ func parseTagAndLength(bytes []byte) (r tagAndLen, off int, e error) {
// fmt.Println("len", len)
if len > 3 {
e = fmt.Errorf("length is too large")
return
return r, off, e
}
off++
var val int64
val, e = parseInt64(bytes[off : off+len])
if e != nil {
return
return r, off, e
}
// fmt.Println("bytes[off : off+len]", bytes[off : off+len], "val", val)

r.len = int64(val)
off += len
}

return
return r, off, e
}

func parseBitString(bytes []byte) (r BitString, e error) {
Expand All @@ -66,7 +66,7 @@ func parseBitString(bytes []byte) (r BitString, e error) {
func parseInt64(bytes []byte) (r int64, e error) {
if len(bytes) > 8 {
e = fmt.Errorf("out of range of int64")
return
return r, e
}

minus := false
Expand Down Expand Up @@ -97,7 +97,7 @@ func parseInt64(bytes []byte) (r int64, e error) {
r = -r - 1
}

return
return r, e
}

func parseBool(b byte) (bool, error) {
Expand Down Expand Up @@ -128,9 +128,9 @@ func ParseField(v reflect.Value, bytes []byte, params fieldParameters) error {
// We deal with the structures defined in this package first.
switch fieldType {
case BitStringType:
val, err := parseBitString(bytes[talOff:])
if err != nil {
return err
val, parse_err := parseBitString(bytes[talOff:])
if parse_err != nil {
return parse_err
}

v.Set(reflect.ValueOf(val))
Expand All @@ -142,9 +142,9 @@ func ParseField(v reflect.Value, bytes []byte, params fieldParameters) error {
v.Set(reflect.ValueOf(val))
return nil
case EnumeratedType:
val, err := parseInt64(bytes[talOff:])
val, parse_err := parseInt64(bytes[talOff:])
if err != nil {
return err
return parse_err
}

v.Set(reflect.ValueOf(Enumerated(val)))
Expand All @@ -156,15 +156,15 @@ func ParseField(v reflect.Value, bytes []byte, params fieldParameters) error {
}
switch val := v; val.Kind() {
case reflect.Bool:
if parsedBool, err := parseBool(bytes[talOff]); err != nil {
return err
if parsedBool, parse_err := parseBool(bytes[talOff]); err != nil {
return parse_err
} else {
val.SetBool(parsedBool)
return nil
}
case reflect.Int, reflect.Int32, reflect.Int64:
if parsedInt, err := parseInt64(bytes[talOff:]); err != nil {
return err
if parsedInt, parse_err := parseInt64(bytes[talOff:]); err != nil {
return parse_err
} else {
val.SetInt(parsedInt)
return nil
Expand Down Expand Up @@ -239,25 +239,25 @@ func ParseField(v reflect.Value, bytes []byte, params fieldParameters) error {
current := 0
next := int64(0)
for ; offset < totalLen; offset = next {
tal, talOff, err := parseTagAndLength(bytes[offset:])
if err != nil {
return err
talNow, talOffNow, parse_err := parseTagAndLength(bytes[offset:])
if parse_err != nil {
return parse_err
}
next = int64(offset) + int64(talOff) + tal.len
next = int64(offset) + int64(talOffNow) + talNow.len
if next > totalLen {
return fmt.Errorf("type value out of range")
}
if offset >= next {
fmt.Println("bytes offset", offset, "next", next, "talOff", talOff, "tal.len", tal.len)
fmt.Println("bytes offset", offset, "next", next, "talOff", talOffNow, "tal.len", talNow.len)
}

for ; current < structType.NumField(); current++ {
// for open type reference
if params.openType {
return fmt.Errorf("OpenType is not implemented")
}
if *structParams[current].tagNumber == tal.tagNumber {
if err := ParseField(val.Field(current), bytes[offset:next], structParams[current]); err != nil {
if *structParams[current].tagNumber == talNow.tagNumber {
if err = ParseField(val.Field(current), bytes[offset:next], structParams[current]); err != nil {
return err
}
break
Expand All @@ -271,11 +271,11 @@ func ParseField(v reflect.Value, bytes []byte, params fieldParameters) error {
} else {
next := int64(0)
for ; offset < totalLen; offset = next {
tal, talOff, err := parseTagAndLength(bytes[offset:])
if err != nil {
return err
talNow, talOffNow, parse_err := parseTagAndLength(bytes[offset:])
if parse_err != nil {
return parse_err
}
next = offset + int64(talOff) + tal.len
next = offset + int64(talOffNow) + talNow.len
if next > totalLen {
return fmt.Errorf("type value out of range")
}
Expand All @@ -286,9 +286,9 @@ func ParseField(v reflect.Value, bytes []byte, params fieldParameters) error {
if params.openType {
return fmt.Errorf("OpenType is not implemented")
}
if *structParams[current].tagNumber == tal.tagNumber {
if err := ParseField(val.Field(current), bytes[offset:next], structParams[current]); err != nil {
return err
if *structParams[current].tagNumber == talNow.tagNumber {
if parse_err1 := ParseField(val.Field(current), bytes[offset:next], structParams[current]); parse_err1 != nil {
return parse_err1
}
break
}
Expand All @@ -304,11 +304,11 @@ func ParseField(v reflect.Value, bytes []byte, params fieldParameters) error {
var valArray [][]byte
var next int64
for offset := int64(talOff); offset < int64(len(bytes)); offset = next {
tal, talOff, err := parseTagAndLength(bytes[offset:])
talNow, talOffNow, err := parseTagAndLength(bytes[offset:])
if err != nil {
return err
}
next = offset + int64(talOff) + tal.len
next = offset + int64(talOffNow) + talNow.len
if next > int64(len(bytes)) {
return fmt.Errorf("type value out of range")
}
Expand Down Expand Up @@ -364,16 +364,15 @@ func ParseField(v reflect.Value, bytes []byte, params fieldParameters) error {
// written to the corresponding element in the struct.
//
// The following tags on struct fields have special meaning to Unmarshal:
//
// optional OPTIONAL tag in SEQUENCE
// sizeLB set the minimum value of size constraint
// sizeUB set the maximum value of value constraint
// valueLB set the minimum value of size constraint
// valueUB set the maximum value of value constraint
// default sets the default value
// openType specifies the open Type
// referenceFieldName the string of the reference field for this type (only if openType used)
// referenceFieldValue the corresponding value of the reference field for this type (only if openType used)
// optional OPTIONAL tag in SEQUENCE
// sizeLB set the minimum value of size constraint
// sizeUB set the maximum value of value constraint
// valueLB set the minimum value of size constraint
// valueUB set the maximum value of value constraint
// default sets the default value
// openType specifies the open Type
// referenceFieldName the string of the reference field for this type (only if openType used)
// referenceFieldValue the corresponding value of the reference field for this type (only if openType used)
//
// Other ASN.1 types are not supported; if it encounters them,
// Unmarshal returns a parse error.
Expand Down
24 changes: 12 additions & 12 deletions cdr/cdrConvert/sbiToCdr.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,41 +16,41 @@ func MultiUnitUsageToCdr(multiUnitUsageList []models.MultipleUnitUsage) []cdrTyp
for _, multiUnitUsage := range multiUnitUsageList {
usedUnitContainer := UsedUnitContainerToCdr(multiUnitUsage.UsedUnitContainer)
cdrMultiUnitUsage := cdrType.MultipleUnitUsage{
cdrType.RatingGroupId{
int64(multiUnitUsage.RatingGroup),
RatingGroup: cdrType.RatingGroupId{
Value: int64(multiUnitUsage.RatingGroup),
},
usedUnitContainer,
&cdrType.NetworkFunctionName{
asn.IA5String(multiUnitUsage.UPFID),
UsedUnitContainers: usedUnitContainer,
UPFID: &cdrType.NetworkFunctionName{
Value: asn.IA5String(multiUnitUsage.UPFID),
},
// TODO convert PDUAddress, not exist in current spec
nil,
MultihomedPDUAddress: nil,
}
cdrMultiUnitUsageList = append(cdrMultiUnitUsageList, cdrMultiUnitUsage)
}

return cdrMultiUnitUsageList
}

// TODO: Only convert Local Sequence Number, Uplink, Downlink, Total Volumn,
// Service Specific Units currently.
// TODO
// Only convert Local Sequence Number, Uplink, Downlink, Total Volumn, Service Specific Units currently.
func UsedUnitContainerToCdr(usedUnitContainerList []models.UsedUnitContainer) []cdrType.UsedUnitContainer {
cdrUsedUnitContainerList := make([]cdrType.UsedUnitContainer, 0, len(usedUnitContainerList))

for _, usedUnitContainer := range usedUnitContainerList {
serviceSpecificUnits := int64(usedUnitContainer.ServiceSpecificUnits)
cdrUsedUnitContainer := cdrType.UsedUnitContainer{
LocalSequenceNumber: &cdrType.LocalSequenceNumber{
int64(usedUnitContainer.LocalSequenceNumber),
Value: int64(usedUnitContainer.LocalSequenceNumber),
},
DataVolumeUplink: &cdrType.DataVolumeOctets{
int64(usedUnitContainer.UplinkVolume),
Value: int64(usedUnitContainer.UplinkVolume),
},
DataVolumeDownlink: &cdrType.DataVolumeOctets{
int64(usedUnitContainer.DownlinkVolume),
Value: int64(usedUnitContainer.DownlinkVolume),
},
DataTotalVolume: &cdrType.DataVolumeOctets{
int64(usedUnitContainer.TotalVolume),
Value: int64(usedUnitContainer.TotalVolume),
},
ServiceSpecificUnits: &serviceSpecificUnits,
}
Expand Down
Loading

0 comments on commit ccd503d

Please sign in to comment.