package routes import ( "fmt" "log" "net/http" "github.com/flamego/template" "github.com/spf13/viper" "gopkg.in/ldap.v2" ) func GetTopIndex(t template.Template, data template.Data) { // create new LDAP connection l, err := ldap.Dial("tcp", fmt.Sprintf("%s:%d", viper.GetString("host"), viper.GetInt("port"))) if err != nil { log.Fatal(err) } defer l.Close() // bind as the admin user err = l.Bind(viper.GetString("bind_dn"), viper.GetString("bind_pw")) if err != nil { log.Fatal(err) } searchRequest := ldap.NewSearchRequest( viper.GetString("user.base_ou"), // The base dn to search ldap.ScopeWholeSubtree, ldap.NeverDerefAliases, 0, 0, false, "(&(objectClass=inetOrgPerson))", // The filter to apply []string{"dn", "uid", "displayName"}, // A list attributes to retrieve nil, ) sr, err := l.Search(searchRequest) if err != nil { log.Fatal(err) } data["results"] = sr data["title"] = "Dashboard" t.HTML(http.StatusOK, "index") }