株式会社ヴァンデミックシステム

Blog

<スポンサーリンク>

サーバを立てる

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

https://qiita.com/yuta_vamdemic/items/53cd67eea5af71ffd08a

認証する

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

<スポンサーリンク>

コメントを残す

Allowed tags:  you may use these HTML tags and attributes: <a href="">, <strong>, <em>, <h1>, <h2>, <h3>
Please note:  all comments go through moderation.

*

日本語が含まれない投稿は無視されますのでご注意ください。(スパム対策)