Skip to content

Commit 537128f

Browse files
authored
Merge pull request #71 from liggitt/godoc-gofmt
Update godoc, add gofmt check
2 parents 248a318 + 8eb4cf7 commit 537128f

File tree

16 files changed

+301
-90
lines changed

16 files changed

+301
-90
lines changed

.githooks/pre-push

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/usr/bin/env bash
2+
3+
# install from the root of the repo with:
4+
# ln -s ../../.githooks/pre-push .git/hooks/pre-push
5+
6+
make vet fmt lint

.travis.yml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,24 @@
11
language: go
2+
env:
3+
global:
4+
- VET_VERSIONS="1.5 1.6 tip"
5+
- LINT_VERSIONS="1.5 1.6 tip"
26
go:
37
- 1.2
48
- 1.3
59
- 1.4
610
- 1.5
11+
- 1.6
712
- tip
813
go_import_path: gopkg.in/ldap.v2
914
install:
1015
- go get gopkg.in/asn1-ber.v1
1116
- go get gopkg.in/ldap.v2
1217
- go get code.google.com/p/go.tools/cmd/cover || go get golang.org/x/tools/cmd/cover
18+
- go get github.com/golang/lint/golint || true
1319
- go build -v ./...
1420
script:
15-
- go test -v -cover ./...
21+
- make test
22+
- make fmt
23+
- if [[ "$VET_VERSIONS" == *"$TRAVIS_GO_VERSION"* ]]; then make vet; fi
24+
- if [[ "$LINT_VERSIONS" == *"$TRAVIS_GO_VERSION"* ]]; then make lint; fi

Makefile

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
.PHONY: default install build test quicktest fmt vet lint
2+
3+
default: fmt vet lint build quicktest
4+
5+
install:
6+
go get -t -v ./...
7+
8+
build:
9+
go build -v ./...
10+
11+
test:
12+
go test -v -cover ./...
13+
14+
quicktest:
15+
go test ./...
16+
17+
# Capture output and force failure when there is non-empty output
18+
fmt:
19+
@echo gofmt -l .
20+
@OUTPUT=`gofmt -l . 2>&1`; \
21+
if [ "$$OUTPUT" ]; then \
22+
echo "gofmt must be run on the following files:"; \
23+
echo "$$OUTPUT"; \
24+
exit 1; \
25+
fi
26+
27+
# Only run on go1.5+
28+
vet:
29+
go tool vet -atomic -bool -copylocks -nilfunc -printf -shadow -rangeloops -unreachable -unsafeptr -unusedresult .
30+
31+
# https://github.com/golang/lint
32+
# go get github.com/golang/lint/golint
33+
# Capture output and force failure when there is non-empty output
34+
# Only run on go1.5+
35+
lint:
36+
@echo golint ./...
37+
@OUTPUT=`golint ./... 2>&1`; \
38+
if [ "$$OUTPUT" ]; then \
39+
echo "golint errors:"; \
40+
echo "$$OUTPUT"; \
41+
exit 1; \
42+
fi

README.md

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,41 +13,39 @@ Import the latest version with:
1313

1414
import "gopkg.in/ldap.v2"
1515

16-
1716
## Required Libraries:
1817

1918
- gopkg.in/asn1-ber.v1
2019

21-
## Working:
20+
## Features:
2221

23-
- Connecting to LDAP server
22+
- Connecting to LDAP server (non-TLS, TLS, STARTTLS)
2423
- Binding to LDAP server
2524
- Searching for entries
26-
- Compiling string filters to LDAP filters
25+
- Filter Compile / Decompile
2726
- Paging Search Results
2827
- Modify Requests / Responses
2928
- Add Requests / Responses
3029
- Delete Requests / Responses
31-
- Better Unicode support
3230

3331
## Examples:
3432

3533
- search
3634
- modify
3735

38-
## Tests Implemented:
39-
40-
- Filter Compile / Decompile
41-
42-
## TODO:
36+
## Contributing:
4337

44-
- [x] Add Requests / Responses
45-
- [x] Delete Requests / Responses
46-
- [x] Modify DN Requests / Responses
47-
- [ ] Compare Requests / Responses
48-
- [ ] Implement Tests / Benchmarks
38+
Bug reports and pull requests are welcome!
4939

40+
Before submitting a pull request, please make sure tests and verification scripts pass:
41+
```
42+
make all
43+
```
5044

45+
To set up a pre-push hook to run the tests and verify scripts before pushing:
46+
```
47+
ln -s ../../.githooks/pre-push .git/hooks/pre-push
48+
```
5149

5250
---
5351
The Go gopher was designed by Renee French. (http://reneefrench.blogspot.com/)

add.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,11 @@ import (
1616
"gopkg.in/asn1-ber.v1"
1717
)
1818

19+
// Attribute represents an LDAP attribute
1920
type Attribute struct {
21+
// Type is the name of the LDAP attribute
2022
Type string
23+
// Vals are the LDAP attribute values
2124
Vals []string
2225
}
2326

@@ -32,8 +35,11 @@ func (a *Attribute) encode() *ber.Packet {
3235
return seq
3336
}
3437

38+
// AddRequest represents an LDAP AddRequest operation
3539
type AddRequest struct {
36-
DN string
40+
// DN identifies the entry being added
41+
DN string
42+
// Attributes list the attributes of the new entry
3743
Attributes []Attribute
3844
}
3945

@@ -48,17 +54,20 @@ func (a AddRequest) encode() *ber.Packet {
4854
return request
4955
}
5056

57+
// Attribute adds an attribute with the given type and values
5158
func (a *AddRequest) Attribute(attrType string, attrVals []string) {
5259
a.Attributes = append(a.Attributes, Attribute{Type: attrType, Vals: attrVals})
5360
}
5461

62+
// NewAddRequest returns an AddRequest for the given DN, with no attributes
5563
func NewAddRequest(dn string) *AddRequest {
5664
return &AddRequest{
5765
DN: dn,
5866
}
5967

6068
}
6169

70+
// Add performs the given AddRequest
6271
func (l *Conn) Add(addRequest *AddRequest) error {
6372
packet := ber.Encode(ber.ClassUniversal, ber.TypeConstructed, ber.TagSequence, nil, "LDAP Request")
6473
packet.AppendChild(ber.NewInteger(ber.ClassUniversal, ber.TypePrimitive, ber.TagInteger, l.nextMessageID(), "MessageID"))

bind.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,22 @@ import (
1010
"gopkg.in/asn1-ber.v1"
1111
)
1212

13+
// SimpleBindRequest represents a username/password bind operation
1314
type SimpleBindRequest struct {
15+
// Username is the name of the Directory object that the client wishes to bind as
1416
Username string
17+
// Password is the credentials to bind with
1518
Password string
19+
// Controls are optional controls to send with the bind request
1620
Controls []Control
1721
}
1822

23+
// SimpleBindResult contains the response from the server
1924
type SimpleBindResult struct {
2025
Controls []Control
2126
}
2227

28+
// NewSimpleBindRequest returns a bind request
2329
func NewSimpleBindRequest(username string, password string, controls []Control) *SimpleBindRequest {
2430
return &SimpleBindRequest{
2531
Username: username,
@@ -39,6 +45,7 @@ func (bindRequest *SimpleBindRequest) encode() *ber.Packet {
3945
return request
4046
}
4147

48+
// SimpleBind performs the simple bind operation defined in the given request
4249
func (l *Conn) SimpleBind(simpleBindRequest *SimpleBindRequest) (*SimpleBindResult, error) {
4350
packet := ber.Encode(ber.ClassUniversal, ber.TypeConstructed, ber.TagSequence, nil, "LDAP Request")
4451
packet.AppendChild(ber.NewInteger(ber.ClassUniversal, ber.TypePrimitive, ber.TagInteger, l.nextMessageID(), "MessageID"))
@@ -90,6 +97,7 @@ func (l *Conn) SimpleBind(simpleBindRequest *SimpleBindRequest) (*SimpleBindResu
9097
return result, nil
9198
}
9299

100+
// Bind performs a bind with the given username and password
93101
func (l *Conn) Bind(username, password string) error {
94102
packet := ber.Encode(ber.ClassUniversal, ber.TypeConstructed, ber.TagSequence, nil, "LDAP Request")
95103
packet.AppendChild(ber.NewInteger(ber.ClassUniversal, ber.TypePrimitive, ber.TagInteger, l.nextMessageID(), "MessageID"))

conn.go

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,27 @@ import (
1717
)
1818

1919
const (
20-
MessageQuit = 0
21-
MessageRequest = 1
20+
// MessageQuit causes the processMessages loop to exit
21+
MessageQuit = 0
22+
// MessageRequest sends a request to the server
23+
MessageRequest = 1
24+
// MessageResponse receives a response from the server
2225
MessageResponse = 2
23-
MessageFinish = 3
24-
MessageTimeout = 4
26+
// MessageFinish indicates the client considers a particular message ID to be finished
27+
MessageFinish = 3
28+
// MessageTimeout indicates the client-specified timeout for a particular message ID has been reached
29+
MessageTimeout = 4
2530
)
2631

32+
// PacketResponse contains the packet or error encountered reading a response
2733
type PacketResponse struct {
34+
// Packet is the packet read from the server
2835
Packet *ber.Packet
29-
Error error
36+
// Error is an error encountered while reading
37+
Error error
3038
}
3139

40+
// ReadPacket returns the packet or an error
3241
func (pr *PacketResponse) ReadPacket() (*ber.Packet, error) {
3342
if (pr == nil) || (pr.Packet == nil && pr.Error == nil) {
3443
return nil, NewError(ErrorNetwork, errors.New("ldap: could not retrieve response"))
@@ -37,8 +46,10 @@ func (pr *PacketResponse) ReadPacket() (*ber.Packet, error) {
3746
}
3847

3948
type messageContext struct {
40-
id int64
41-
done chan struct{}
49+
id int64
50+
// close(done) should only be called from finishMessage()
51+
done chan struct{}
52+
// close(responses) should only be called from processMessages(), and only sent to from sendResponse()
4253
responses chan *PacketResponse
4354
}
4455

@@ -140,6 +151,7 @@ func NewConn(conn net.Conn, isTLS bool) *Conn {
140151
}
141152
}
142153

154+
// Start initializes goroutines to read responses and process messages
143155
func (l *Conn) Start() {
144156
go l.reader()
145157
go l.processMessages()
@@ -167,7 +179,7 @@ func (l *Conn) Close() {
167179
l.wgClose.Wait()
168180
}
169181

170-
// Sets the time after a request is sent that a MessageTimeout triggers
182+
// SetTimeout sets the time after a request is sent that a MessageTimeout triggers
171183
func (l *Conn) SetTimeout(timeout time.Duration) {
172184
if timeout > 0 {
173185
l.requestTimeout = timeout
@@ -253,15 +265,14 @@ func (l *Conn) sendMessageWithFlags(packet *ber.Packet, flags sendMessageFlags)
253265
l.Debug.Printf("flags&startTLS = %d", flags&startTLS)
254266
if l.isStartingTLS {
255267
l.messageMutex.Unlock()
256-
return nil, NewError(ErrorNetwork, errors.New("ldap: connection is in startls phase."))
268+
return nil, NewError(ErrorNetwork, errors.New("ldap: connection is in startls phase"))
257269
}
258270
if flags&startTLS != 0 {
259271
if l.outstandingRequests != 0 {
260272
l.messageMutex.Unlock()
261273
return nil, NewError(ErrorNetwork, errors.New("ldap: cannot StartTLS with outstanding requests"))
262-
} else {
263-
l.isStartingTLS = true
264274
}
275+
l.isStartingTLS = true
265276
}
266277
l.outstandingRequests++
267278

0 commit comments

Comments
 (0)