...

Source file src/github.com/go-ldap/ldap/v3/del.go

Documentation: github.com/go-ldap/ldap/v3

     1  package ldap
     2  
     3  import (
     4  	"fmt"
     5  	ber "github.com/go-asn1-ber/asn1-ber"
     6  )
     7  
     8  // DelRequest implements an LDAP deletion request
     9  type DelRequest struct {
    10  	// DN is the name of the directory entry to delete
    11  	DN string
    12  	// Controls hold optional controls to send with the request
    13  	Controls []Control
    14  }
    15  
    16  func (req *DelRequest) appendTo(envelope *ber.Packet) error {
    17  	pkt := ber.Encode(ber.ClassApplication, ber.TypePrimitive, ApplicationDelRequest, req.DN, "Del Request")
    18  	pkt.Data.Write([]byte(req.DN))
    19  
    20  	envelope.AppendChild(pkt)
    21  	if len(req.Controls) > 0 {
    22  		envelope.AppendChild(encodeControls(req.Controls))
    23  	}
    24  
    25  	return nil
    26  }
    27  
    28  // NewDelRequest creates a delete request for the given DN and controls
    29  func NewDelRequest(DN string, Controls []Control) *DelRequest {
    30  	return &DelRequest{
    31  		DN:       DN,
    32  		Controls: Controls,
    33  	}
    34  }
    35  
    36  // Del executes the given delete request
    37  func (l *Conn) Del(delRequest *DelRequest) error {
    38  	msgCtx, err := l.doRequest(delRequest)
    39  	if err != nil {
    40  		return err
    41  	}
    42  	defer l.finishMessage(msgCtx)
    43  
    44  	packet, err := l.readPacket(msgCtx)
    45  	if err != nil {
    46  		return err
    47  	}
    48  
    49  	if packet.Children[1].Tag == ApplicationDelResponse {
    50  		err := GetLDAPError(packet)
    51  		if err != nil {
    52  			return err
    53  		}
    54  	} else {
    55  		return fmt.Errorf("ldap: unexpected response: %d", packet.Children[1].Tag)
    56  	}
    57  
    58  	return nil
    59  }
    60  

View as plain text