如何在LDAP协议中使用Go

How can I use Go to call and manage Ldap protocol directly? are there any packages? or must I use udp and tcp?

There is no LDAP library in the Go standard libraries, but a quick Google search reveals several you could try:

This second one is actually a fork of the first one. On github you can always view the open issues, last update and forking network (https://github.com/mmitton/ldap/network) to get a pretty good sense of which library you should use when there is a lot of forking.

If you need a library for something omitted in the Go standard libraries there are several good places to look:

If all of those fail you and you don't feel up to creating your own implementation, keep in mind you can always use cgo to call C code (such as one of the many C LDAP libraries for example) from Go.

Thought I should add my ten cents here. It is an old post, but here it is nonetheless

I used the https://github.com/mavricknz/ldap library after using the mmitton/ldap one as mentioned by voidlogic above. The problem with the mmitton lib is that it does not handle escape characters very well in the filter.

The test filter: (&(objectClass=user)(cn=wickd(bracketTest )))

Escaped Filter:  (&(objectClass=user)(cn=wickd\28bracketTest \29))

The MMitton library just came back with a filter compile error even with the escaped filter. Loaded the Mavricknz lib and it worked. Even comes with EscapeFilter function! brilliance!

Anyhow... Thought I should post this for anyone that had the same struggle as I did :)

Additionally, for the server end of it, I wrote this package (in Go) a while ago: https://github.com/bradleypeabody/godap

It's not a full LDAP server but works well for implementing authentication on top of another data source (something I have been unable to find any other project that addresses).

It does a lot of "manage Ldap protocol directly" :)

I started to write a helper library for building server software capable of speaking the LDAP protocol. There are some usage samples included.

For a simple high-level ldap client, see go-ldap-client, go docs.

Most of the options on https://godoc.org/?q=ldap are just forks of another one, most of them are too low level or too limited (e.g. do not return errors which make it hard to troubleshoot issues).

If you want to provide LDAP based authentication on your web page, you may like the solution I created: go-ldapc is a LDAP Authentication Client Module, with only one API.

It's on github - sona-tar/go-ldapc.