0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

golangでOpenLDAPサーバへ接続する

Posted at

サーバを立てる

  • DockerでOpenLdapを389で起動します

認証する

Ldapモジュールをインストール


go get github.com/go-ldap/ldap

コード


package main

import (
	"crypto/tls"
	"errors"
	"fmt"
	"github.com/go-ldap/ldap"
)

func ExampleconnSearch() (bool, error) {

	ldapServer   := "ldap://localhost:389"
	err := errors.New("connection error")

	// ldapServerへの接続確認
	l, err := ldap.DialURL(ldapServer, ldap.DialWithTLSConfig(&tls.Config{InsecureSkipVerify: true}))
	// 接続失敗時のエラーハンドリング
	if err != nil {
		fmt.Printf("%s\n", "ldap connection error")
		return false, err
	}

	fmt.Printf("%s\n", "ldap connection success")
	defer l.Close()
	return true, nil
}

func main() {
	ExampleconnSearch()
}

実行結果

$ go run main.go
ldap connection success
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?