Skip to content

Commit 4f900ee

Browse files
authored
lint fixes (#28)
* Fix linting issues * more lint fixes
1 parent 38b4e5c commit 4f900ee

File tree

14 files changed

+169
-180
lines changed

14 files changed

+169
-180
lines changed

.travis.yml

Lines changed: 34 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,39 @@
11
language: go
22
matrix:
3-
include:
4-
- go: 1.2.x
5-
env: GOOS=linux GOARCH=amd64
6-
- go: 1.2.x
7-
env: GOOS=linux GOARCH=386
8-
- go: 1.2.x
9-
env: GOOS=windows GOARCH=amd64
10-
- go: 1.2.x
11-
env: GOOS=windows GOARCH=386
12-
- go: 1.3.x
13-
- go: 1.4.x
14-
- go: 1.5.x
15-
- go: 1.6.x
16-
- go: 1.7.x
17-
- go: 1.8.x
18-
- go: 1.9.x
19-
- go: 1.10.x
20-
- go: 1.11.x
21-
- go: 1.12.x
22-
- go: 1.13.x
23-
env: GOOS=linux GOARCH=amd64
24-
- go: 1.13.x
25-
env: GOOS=linux GOARCH=386
26-
- go: 1.13.x
27-
env: GOOS=windows GOARCH=amd64
28-
- go: 1.13.x
29-
env: GOOS=windows GOARCH=386
30-
- go: tip
3+
include:
4+
- go: 1.2.x
5+
env: GOOS=linux GOARCH=amd64
6+
- go: 1.2.x
7+
env: GOOS=linux GOARCH=386
8+
- go: 1.2.x
9+
env: GOOS=windows GOARCH=amd64
10+
- go: 1.2.x
11+
env: GOOS=windows GOARCH=386
12+
- go: 1.3.x
13+
- go: 1.4.x
14+
- go: 1.5.x
15+
- go: 1.6.x
16+
- go: 1.7.x
17+
- go: 1.8.x
18+
- go: 1.9.x
19+
- go: 1.10.x
20+
- go: 1.11.x
21+
- go: 1.12.x
22+
- go: 1.13.x
23+
- go: 1.14.x
24+
env: GOOS=linux GOARCH=amd64
25+
- go: 1.14.x
26+
env: GOOS=linux GOARCH=386
27+
- go: 1.14.x
28+
env: GOOS=windows GOARCH=amd64
29+
- go: 1.14.x
30+
env: GOOS=windows GOARCH=386
31+
- go: tip
3132
go_import_path: gopkg.in/asn-ber.v1
3233
install:
33-
- go list -f '{{range .Imports}}{{.}} {{end}}' ./... | xargs go get -v
34-
- go list -f '{{range .TestImports}}{{.}} {{end}}' ./... | xargs go get -v
35-
- go get code.google.com/p/go.tools/cmd/cover || go get golang.org/x/tools/cmd/cover
36-
- go build -v ./...
34+
- go list -f '{{range .Imports}}{{.}} {{end}}' ./... | xargs go get -v
35+
- go list -f '{{range .TestImports}}{{.}} {{end}}' ./... | xargs go get -v
36+
- go get code.google.com/p/go.tools/cmd/cover || go get golang.org/x/tools/cmd/cover
37+
- go build -v ./...
3738
script:
38-
- go test -v -cover ./... || go test -v ./...
39+
- go test -v -cover ./... || go test -v ./...

ber.go

Lines changed: 64 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -145,20 +145,20 @@ var TypeMap = map[Type]string{
145145
TypeConstructed: "Constructed",
146146
}
147147

148-
var Debug bool = false
148+
var Debug = false
149149

150150
func PrintBytes(out io.Writer, buf []byte, indent string) {
151-
data_lines := make([]string, (len(buf)/30)+1)
152-
num_lines := make([]string, (len(buf)/30)+1)
151+
dataLines := make([]string, (len(buf)/30)+1)
152+
numLines := make([]string, (len(buf)/30)+1)
153153

154154
for i, b := range buf {
155-
data_lines[i/30] += fmt.Sprintf("%02x ", b)
156-
num_lines[i/30] += fmt.Sprintf("%02d ", (i+1)%100)
155+
dataLines[i/30] += fmt.Sprintf("%02x ", b)
156+
numLines[i/30] += fmt.Sprintf("%02d ", (i+1)%100)
157157
}
158158

159-
for i := 0; i < len(data_lines); i++ {
160-
out.Write([]byte(indent + data_lines[i] + "\n"))
161-
out.Write([]byte(indent + num_lines[i] + "\n\n"))
159+
for i := 0; i < len(dataLines); i++ {
160+
_, _ = out.Write([]byte(indent + dataLines[i] + "\n"))
161+
_, _ = out.Write([]byte(indent + numLines[i] + "\n\n"))
162162
}
163163
}
164164

@@ -171,20 +171,20 @@ func PrintPacket(p *Packet) {
171171
}
172172

173173
func printPacket(out io.Writer, p *Packet, indent int, printBytes bool) {
174-
indent_str := ""
174+
indentStr := ""
175175

176-
for len(indent_str) != indent {
177-
indent_str += " "
176+
for len(indentStr) != indent {
177+
indentStr += " "
178178
}
179179

180-
class_str := ClassMap[p.ClassType]
180+
classStr := ClassMap[p.ClassType]
181181

182-
tagtype_str := TypeMap[p.TagType]
182+
tagTypeStr := TypeMap[p.TagType]
183183

184-
tag_str := fmt.Sprintf("0x%02X", p.Tag)
184+
tagStr := fmt.Sprintf("0x%02X", p.Tag)
185185

186186
if p.ClassType == ClassUniversal {
187-
tag_str = tagMap[p.Tag]
187+
tagStr = tagMap[p.Tag]
188188
}
189189

190190
value := fmt.Sprint(p.Value)
@@ -194,18 +194,18 @@ func printPacket(out io.Writer, p *Packet, indent int, printBytes bool) {
194194
description = p.Description + ": "
195195
}
196196

197-
fmt.Fprintf(out, "%s%s(%s, %s, %s) Len=%d %q\n", indent_str, description, class_str, tagtype_str, tag_str, p.Data.Len(), value)
197+
_, _ = fmt.Fprintf(out, "%s%s(%s, %s, %s) Len=%d %q\n", indentStr, description, classStr, tagTypeStr, tagStr, p.Data.Len(), value)
198198

199199
if printBytes {
200-
PrintBytes(out, p.Bytes(), indent_str)
200+
PrintBytes(out, p.Bytes(), indentStr)
201201
}
202202

203203
for _, child := range p.Children {
204204
printPacket(out, child, indent+1, printBytes)
205205
}
206206
}
207207

208-
// ReadPacket reads a single Packet from the reader
208+
// ReadPacket reads a single Packet from the reader.
209209
func ReadPacket(reader io.Reader) (*Packet, error) {
210210
p, _, err := readPacket(reader)
211211
if err != nil {
@@ -241,7 +241,7 @@ func encodeInteger(i int64) []byte {
241241

242242
var j int
243243
for ; n > 0; n-- {
244-
out[j] = (byte(i >> uint((n-1)*8)))
244+
out[j] = byte(i >> uint((n-1)*8))
245245
j++
246246
}
247247

@@ -273,7 +273,7 @@ func DecodePacket(data []byte) *Packet {
273273
}
274274

275275
// DecodePacketErr decodes the given bytes into a single Packet
276-
// If a decode error is encountered, nil is returned
276+
// If a decode error is encountered, nil is returned.
277277
func DecodePacketErr(data []byte) (*Packet, error) {
278278
p, _, err := readPacket(bytes.NewBuffer(data))
279279
if err != nil {
@@ -282,7 +282,7 @@ func DecodePacketErr(data []byte) (*Packet, error) {
282282
return p, nil
283283
}
284284

285-
// readPacket reads a single Packet from the reader, returning the number of bytes read
285+
// readPacket reads a single Packet from the reader, returning the number of bytes read.
286286
func readPacket(reader io.Reader) (*Packet, int, error) {
287287
identifier, length, read, err := readHeader(reader)
288288
if err != nil {
@@ -344,7 +344,7 @@ func readPacket(reader io.Reader) (*Packet, int, error) {
344344
if MaxPacketLengthBytes > 0 && int64(length) > MaxPacketLengthBytes {
345345
return nil, read, fmt.Errorf("length %d greater than maximum %d", length, MaxPacketLengthBytes)
346346
}
347-
content := make([]byte, length, length)
347+
content := make([]byte, length)
348348
if length > 0 {
349349
_, err := io.ReadFull(reader, content)
350350
if err != nil {
@@ -461,24 +461,24 @@ func (p *Packet) AppendChild(child *Packet) {
461461
p.Children = append(p.Children, child)
462462
}
463463

464-
func Encode(ClassType Class, TagType Type, Tag Tag, Value interface{}, Description string) *Packet {
464+
func Encode(classType Class, tagType Type, tag Tag, value interface{}, description string) *Packet {
465465
p := new(Packet)
466466

467-
p.ClassType = ClassType
468-
p.TagType = TagType
469-
p.Tag = Tag
467+
p.ClassType = classType
468+
p.TagType = tagType
469+
p.Tag = tag
470470
p.Data = new(bytes.Buffer)
471471

472472
p.Children = make([]*Packet, 0, 2)
473473

474-
p.Value = Value
475-
p.Description = Description
474+
p.Value = value
475+
p.Description = description
476476

477-
if Value != nil {
478-
v := reflect.ValueOf(Value)
477+
if value != nil {
478+
v := reflect.ValueOf(value)
479479

480-
if ClassType == ClassUniversal {
481-
switch Tag {
480+
if classType == ClassUniversal {
481+
switch tag {
482482
case TagOctetString:
483483
sv, ok := v.Interface().(string)
484484

@@ -496,8 +496,8 @@ func Encode(ClassType Class, TagType Type, Tag Tag, Value interface{}, Descripti
496496
p.Data.Write(bv)
497497
}
498498
}
499-
} else if ClassType == ClassContext {
500-
switch Tag {
499+
} else if classType == ClassContext {
500+
switch tag {
501501
case TagEnumerated:
502502
bv, ok := v.Interface().([]byte)
503503
if ok {
@@ -514,46 +514,46 @@ func Encode(ClassType Class, TagType Type, Tag Tag, Value interface{}, Descripti
514514
return p
515515
}
516516

517-
func NewSequence(Description string) *Packet {
518-
return Encode(ClassUniversal, TypeConstructed, TagSequence, nil, Description)
517+
func NewSequence(description string) *Packet {
518+
return Encode(ClassUniversal, TypeConstructed, TagSequence, nil, description)
519519
}
520520

521-
func NewBoolean(ClassType Class, TagType Type, Tag Tag, Value bool, Description string) *Packet {
521+
func NewBoolean(classType Class, tagType Type, tag Tag, value bool, description string) *Packet {
522522
intValue := int64(0)
523523

524-
if Value {
524+
if value {
525525
intValue = 1
526526
}
527527

528-
p := Encode(ClassType, TagType, Tag, nil, Description)
528+
p := Encode(classType, tagType, tag, nil, description)
529529

530-
p.Value = Value
530+
p.Value = value
531531
p.Data.Write(encodeInteger(intValue))
532532

533533
return p
534534
}
535535

536-
// NewLDAPBoolean returns a RFC 4511-compliant Boolean packet
537-
func NewLDAPBoolean(ClassType Class, TagType Type, Tag Tag, Value bool, Description string) *Packet {
536+
// NewLDAPBoolean returns a RFC 4511-compliant Boolean packet.
537+
func NewLDAPBoolean(classType Class, tagType Type, tag Tag, value bool, description string) *Packet {
538538
intValue := int64(0)
539539

540-
if Value {
540+
if value {
541541
intValue = 255
542542
}
543543

544-
p := Encode(ClassType, TagType, Tag, nil, Description)
544+
p := Encode(classType, tagType, tag, nil, description)
545545

546-
p.Value = Value
546+
p.Value = value
547547
p.Data.Write(encodeInteger(intValue))
548548

549549
return p
550550
}
551551

552-
func NewInteger(ClassType Class, TagType Type, Tag Tag, Value interface{}, Description string) *Packet {
553-
p := Encode(ClassType, TagType, Tag, nil, Description)
552+
func NewInteger(classType Class, tagType Type, tag Tag, value interface{}, description string) *Packet {
553+
p := Encode(classType, tagType, tag, nil, description)
554554

555-
p.Value = Value
556-
switch v := Value.(type) {
555+
p.Value = value
556+
switch v := value.(type) {
557557
case int:
558558
p.Data.Write(encodeInteger(int64(v)))
559559
case uint:
@@ -583,38 +583,38 @@ func NewInteger(ClassType Class, TagType Type, Tag Tag, Value interface{}, Descr
583583
return p
584584
}
585585

586-
func NewString(ClassType Class, TagType Type, Tag Tag, Value, Description string) *Packet {
587-
p := Encode(ClassType, TagType, Tag, nil, Description)
586+
func NewString(classType Class, tagType Type, tag Tag, value, description string) *Packet {
587+
p := Encode(classType, tagType, tag, nil, description)
588588

589-
p.Value = Value
590-
p.Data.Write([]byte(Value))
589+
p.Value = value
590+
p.Data.Write([]byte(value))
591591

592592
return p
593593
}
594594

595-
func NewGeneralizedTime(ClassType Class, TagType Type, Tag Tag, Value time.Time, Description string) *Packet {
596-
p := Encode(ClassType, TagType, Tag, nil, Description)
595+
func NewGeneralizedTime(classType Class, tagType Type, tag Tag, value time.Time, description string) *Packet {
596+
p := Encode(classType, tagType, tag, nil, description)
597597
var s string
598-
if Value.Nanosecond() != 0 {
599-
s = Value.Format(`20060102150405.000000Z`) // FIXME how many fractional?
598+
if value.Nanosecond() != 0 {
599+
s = value.Format(`20060102150405.000000000Z`)
600600
} else {
601-
s = Value.Format(`20060102150405Z`)
601+
s = value.Format(`20060102150405Z`)
602602
}
603603
p.Value = s
604604
p.Data.Write([]byte(s))
605-
return p
605+
return p
606606
}
607607

608-
func NewReal(ClassType Class, TagType Type, Tag Tag, Value interface{}, Description string) *Packet {
609-
p := Encode(ClassType, TagType, Tag, nil, Description)
608+
func NewReal(classType Class, tagType Type, tag Tag, value interface{}, description string) *Packet {
609+
p := Encode(classType, tagType, tag, nil, description)
610610

611-
switch v := Value.(type) {
611+
switch v := value.(type) {
612612
case float64:
613-
p.Data.Write(encodeFloat(float64(v)))
613+
p.Data.Write(encodeFloat(v))
614614
case float32:
615615
p.Data.Write(encodeFloat(float64(v)))
616616
default:
617617
panic(fmt.Sprintf("Invalid type %T, expected float{64|32}", v))
618618
}
619619
return p
620-
}
620+
}

0 commit comments

Comments
 (0)