Code Monkey home page Code Monkey logo

ldapool's Introduction

ldapool

Connection pooling encapsulated for go-ldap packets

The official package does not provide connection pooling by default. In some cases, we will generate too many requests and exceed the connection limit, resulting in an error of closed (connection lost).

This library will be aimed at solving this problem。

Use the example:

package main

import (
	"fmt"

	"github.com/eryajf/ldapool"
	"github.com/go-ldap/ldap/v3"
)

func main() {
	ldapConf := ldapool.LdapConfig{
		Url:       "ldap://localhost:389",
		BaseDN:    "dc=eryajf,dc=net",
		AdminDN:   "cn=admin,dc=eryajf,dc=net",
		AdminPass: "123456",
		MaxOpen:   30,
	}

	conn, err := ldapool.Open(ldapConf)
	if err != nil {
		panic(fmt.Sprintf("get conn failed:%v\n", err))
	}

	// Construct query request
	searchRequest := ldap.NewSearchRequest(
		ldapConf.BaseDN,
		ldap.ScopeWholeSubtree, ldap.NeverDerefAliases, 0, 0, false,
		"(&(objectClass=*))",
		[]string{},
		nil,
	)

	// Search through ldap built-in search
	sr, err := conn.Search(searchRequest)
	if err != nil {
		fmt.Printf("search err:%v\n", err)
	}
	// Refers to the entry that returns data. If it is greater than 0, the interface returns normally.
	if len(sr.Entries) > 0 {
		for _, v := range sr.Entries {
			fmt.Println(v.DN)
		}
	}
}

The above are examples of the use of the current package。

If you want to connect to more go-ldap library usage, you can refer to another project of mine. It is ldapctl.

Thanks to RoninZc, he wrote most of the code. I integrated it on the basis of it.

ldapool's People

Contributors

eryajf avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.