From 2eea0c0a703e32b904741d52c9e2c9ae836c14b0 Mon Sep 17 00:00:00 2001 From: Samuel Stauffer Date: Wed, 19 Mar 2014 14:22:55 -0700 Subject: Use error instead of *Error --- bind.go | 4 ++-- conn.go | 10 +++++----- filter.go | 10 +++++----- filter_test.go | 4 ++-- ldap.go | 8 ++++---- ldap_test.go | 16 ++++++++-------- modify.go | 4 ++-- search.go | 8 ++++---- 8 files changed, 32 insertions(+), 32 deletions(-) diff --git a/bind.go b/bind.go index 742d90b..545748f 100644 --- a/bind.go +++ b/bind.go @@ -10,7 +10,7 @@ import ( "github.com/SpruceHealth/asn1-ber" ) -func (l *Conn) Bind(username, password string) *Error { +func (l *Conn) Bind(username, password string) error { messageID := l.nextMessageID() packet := ber.Encode(ber.ClassUniversal, ber.TypeConstructed, ber.TagSequence, nil, "LDAP Request") @@ -41,7 +41,7 @@ func (l *Conn) Bind(username, password string) *Error { if l.Debug { if err := addLDAPDescriptions(packet); err != nil { - return NewError(ErrorDebugging, err.Err) + return err } ber.PrintPacket(packet) } diff --git a/conn.go b/conn.go index 02fbbdc..ebf87c1 100644 --- a/conn.go +++ b/conn.go @@ -45,7 +45,7 @@ type Conn struct { // Dial connects to the given address on the given network using net.Dial // and then returns a new Conn for the connection. -func Dial(network, addr string) (*Conn, *Error) { +func Dial(network, addr string) (*Conn, error) { c, err := net.Dial(network, addr) if err != nil { return nil, NewError(ErrorNetwork, err) @@ -57,7 +57,7 @@ func Dial(network, addr string) (*Conn, *Error) { // DialTLS connects to the given address on the given network using tls.Dial // and then returns a new Conn for the connection. -func DialTLS(network, addr string, config *tls.Config) (*Conn, *Error) { +func DialTLS(network, addr string, config *tls.Config) (*Conn, error) { c, err := tls.Dial(network, addr, config) if err != nil { return nil, NewError(ErrorNetwork, err) @@ -118,7 +118,7 @@ func (l *Conn) nextMessageID() uint64 { } // StartTLS sends the command to start a TLS session and then creates a new TLS Client -func (l *Conn) StartTLS(config *tls.Config) *Error { +func (l *Conn) StartTLS(config *tls.Config) error { messageID := l.nextMessageID() if l.isTLS { @@ -144,7 +144,7 @@ func (l *Conn) StartTLS(config *tls.Config) *Error { if l.Debug { if err := addLDAPDescriptions(packet); err != nil { - return NewError(ErrorDebugging, err.Err) + return err } ber.PrintPacket(packet) } @@ -158,7 +158,7 @@ func (l *Conn) StartTLS(config *tls.Config) *Error { return nil } -func (l *Conn) sendMessage(packet *ber.Packet) (chan *ber.Packet, *Error) { +func (l *Conn) sendMessage(packet *ber.Packet) (chan *ber.Packet, error) { if l.isClosing { return nil, NewError(ErrorNetwork, errors.New("ldap: connection closed")) } diff --git a/filter.go b/filter.go index 9d01d28..63f5d07 100644 --- a/filter.go +++ b/filter.go @@ -49,7 +49,7 @@ var FilterSubstringsMap = map[uint64]string{ FilterSubstringsFinal: "Substrings Final", } -func CompileFilter(filter string) (*ber.Packet, *Error) { +func CompileFilter(filter string) (*ber.Packet, error) { if len(filter) == 0 || filter[0] != '(' { return nil, NewError(ErrorFilterCompile, errors.New("ldap: filter does not start with an '('")) } @@ -63,7 +63,7 @@ func CompileFilter(filter string) (*ber.Packet, *Error) { return packet, nil } -func DecompileFilter(packet *ber.Packet) (ret string, err *Error) { +func DecompileFilter(packet *ber.Packet) (ret string, err error) { defer func() { if r := recover(); r != nil { err = NewError(ErrorFilterDecompile, errors.New("ldap: error decompiling filter")) @@ -136,7 +136,7 @@ func DecompileFilter(packet *ber.Packet) (ret string, err *Error) { return } -func compileFilterSet(filter string, pos int, parent *ber.Packet) (int, *Error) { +func compileFilterSet(filter string, pos int, parent *ber.Packet) (int, error) { for pos < len(filter) && filter[pos] == '(' { child, newPos, err := compileFilter(filter, pos+1) if err != nil { @@ -152,9 +152,9 @@ func compileFilterSet(filter string, pos int, parent *ber.Packet) (int, *Error) return pos + 1, nil } -func compileFilter(filter string, pos int) (*ber.Packet, int, *Error) { +func compileFilter(filter string, pos int) (*ber.Packet, int, error) { var packet *ber.Packet - var err *Error + var err error defer func() { if r := recover(); r != nil { diff --git a/filter_test.go b/filter_test.go index 70f5aa3..1df4814 100644 --- a/filter_test.go +++ b/filter_test.go @@ -31,13 +31,13 @@ func TestFilter(t *testing.T) { for _, i := range testFilters { filter, err := CompileFilter(i.filterStr) if err != nil { - t.Errorf("Problem compiling %s - %s", i.filterStr, err.String()) + t.Errorf("Problem compiling %s - %s", i.filterStr, err.Error()) } else if filter.Tag != uint8(i.filterType) { t.Errorf("%q Expected %q got %q", i.filterStr, FilterMap[uint64(i.filterType)], FilterMap[uint64(filter.Tag)]) } else { o, err := DecompileFilter(filter) if err != nil { - t.Errorf("Problem compiling %s - %s", i.filterStr, err.String()) + t.Errorf("Problem compiling %s - %s", i.filterStr, err.Error()) } else if i.filterStr != o { t.Errorf("%q expected, got %q", i.filterStr, o) } diff --git a/ldap.go b/ldap.go index e62e559..bb84279 100644 --- a/ldap.go +++ b/ldap.go @@ -150,7 +150,7 @@ var LDAPResultCodeMap = map[uint8]string{ } // Adds descriptions to an LDAP Response packet for debugging -func addLDAPDescriptions(packet *ber.Packet) (err *Error) { +func addLDAPDescriptions(packet *ber.Packet) (err error) { defer func() { if r := recover(); r != nil { err = NewError(ErrorDebugging, errors.New("ldap: cannot process packet to add descriptions")) @@ -264,7 +264,7 @@ func addDefaultLDAPResponseDescriptions(packet *ber.Packet) { } } -func DebugBinaryFile(FileName string) *Error { +func DebugBinaryFile(FileName string) error { file, err := ioutil.ReadFile(FileName) if err != nil { return NewError(ErrorDebugging, err) @@ -282,11 +282,11 @@ type Error struct { ResultCode uint8 } -func (e *Error) String() string { +func (e *Error) Error() string { return fmt.Sprintf("LDAP Result Code %d %q: %s", e.ResultCode, LDAPResultCodeMap[e.ResultCode], e.Err.Error()) } -func NewError(resultCode uint8, err error) *Error { +func NewError(resultCode uint8, err error) error { return &Error{ResultCode: resultCode, Err: err} } diff --git a/ldap_test.go b/ldap_test.go index 48023f1..31cfbf0 100644 --- a/ldap_test.go +++ b/ldap_test.go @@ -20,7 +20,7 @@ func TestConnect(t *testing.T) { fmt.Printf("TestConnect: starting...\n") l, err := Dial("tcp", fmt.Sprintf("%s:%d", ldapServer, ldapPort)) if err != nil { - t.Errorf(err.String()) + t.Errorf(err.Error()) return } defer l.Close() @@ -31,7 +31,7 @@ func TestSearch(t *testing.T) { fmt.Printf("TestSearch: starting...\n") l, err := Dial("tcp", fmt.Sprintf("%s:%d", ldapServer, ldapPort)) if err != nil { - t.Errorf(err.String()) + t.Errorf(err.Error()) return } defer l.Close() @@ -45,7 +45,7 @@ func TestSearch(t *testing.T) { sr, err := l.Search(searchRequest) if err != nil { - t.Errorf(err.String()) + t.Errorf(err.Error()) return } @@ -56,14 +56,14 @@ func TestSearchWithPaging(t *testing.T) { fmt.Printf("TestSearchWithPaging: starting...\n") l, err := Dial("tcp", fmt.Sprintf("%s:%d", ldapServer, ldapPort)) if err != nil { - t.Errorf(err.String()) + t.Errorf(err.Error()) return } defer l.Close() err = l.Bind("", "") if err != nil { - t.Errorf(err.String()) + t.Errorf(err.Error()) return } @@ -75,7 +75,7 @@ func TestSearchWithPaging(t *testing.T) { nil) sr, err := l.SearchWithPaging(searchRequest, 5) if err != nil { - t.Errorf(err.String()) + t.Errorf(err.Error()) return } @@ -91,7 +91,7 @@ func testMultiGoroutineSearch(t *testing.T, l *Conn, results chan *SearchResult, nil) sr, err := l.Search(searchRequest) if err != nil { - t.Errorf(err.String()) + t.Errorf(err.Error()) results <- nil return } @@ -102,7 +102,7 @@ func TestMultiGoroutineSearch(t *testing.T) { fmt.Printf("TestMultiGoroutineSearch: starting...\n") l, err := Dial("tcp", fmt.Sprintf("%s:%d", ldapServer, ldapPort)) if err != nil { - t.Errorf(err.String()) + t.Errorf(err.Error()) return } defer l.Close() diff --git a/modify.go b/modify.go index 92621e3..00cf37d 100644 --- a/modify.go +++ b/modify.go @@ -111,7 +111,7 @@ func NewModifyRequest( } } -func (l *Conn) Modify(modifyRequest *ModifyRequest) *Error { +func (l *Conn) Modify(modifyRequest *ModifyRequest) error { messageID := l.nextMessageID() packet := ber.Encode(ber.ClassUniversal, ber.TypeConstructed, ber.TagSequence, nil, "LDAP Request") packet.AppendChild(ber.NewInteger(ber.ClassUniversal, ber.TypePrimative, ber.TagInteger, messageID, "MessageID")) @@ -137,7 +137,7 @@ func (l *Conn) Modify(modifyRequest *ModifyRequest) *Error { if l.Debug { if err := addLDAPDescriptions(packet); err != nil { - return NewError(ErrorDebugging, err.Err) + return err } ber.PrintPacket(packet) } diff --git a/search.go b/search.go index 372e5b5..01757ce 100644 --- a/search.go +++ b/search.go @@ -172,7 +172,7 @@ type SearchRequest struct { Controls []Control } -func (s *SearchRequest) encode() (*ber.Packet, *Error) { +func (s *SearchRequest) encode() (*ber.Packet, error) { request := ber.Encode(ber.ClassApplication, ber.TypeConstructed, ApplicationSearchRequest, nil, "Search Request") request.AppendChild(ber.NewString(ber.ClassUniversal, ber.TypePrimative, ber.TagOctetString, s.BaseDN, "Base DN")) request.AppendChild(ber.NewInteger(ber.ClassUniversal, ber.TypePrimative, ber.TagEnumerated, uint64(s.Scope), "Scope")) @@ -216,7 +216,7 @@ func NewSearchRequest( } } -func (l *Conn) SearchWithPaging(searchRequest *SearchRequest, pagingSize uint32) (*SearchResult, *Error) { +func (l *Conn) SearchWithPaging(searchRequest *SearchRequest, pagingSize uint32) (*SearchResult, error) { if searchRequest.Controls == nil { searchRequest.Controls = make([]Control, 0) } @@ -270,7 +270,7 @@ func (l *Conn) SearchWithPaging(searchRequest *SearchRequest, pagingSize uint32) return searchResult, nil } -func (l *Conn) Search(searchRequest *SearchRequest) (*SearchResult, *Error) { +func (l *Conn) Search(searchRequest *SearchRequest) (*SearchResult, error) { messageID := l.nextMessageID() packet := ber.Encode(ber.ClassUniversal, ber.TypeConstructed, ber.TagSequence, nil, "LDAP Request") packet.AppendChild(ber.NewInteger(ber.ClassUniversal, ber.TypePrimative, ber.TagInteger, messageID, "MessageID")) @@ -312,7 +312,7 @@ func (l *Conn) Search(searchRequest *SearchRequest) (*SearchResult, *Error) { if l.Debug { if err := addLDAPDescriptions(packet); err != nil { - return nil, NewError(ErrorDebugging, err.Err) + return nil, err } ber.PrintPacket(packet) } -- cgit v1.2.3