The following code gives:
runtime.main: call to external function main.main
runtime.main: main.main: not defined
runtime.main: undefined: main.main
I messed up with the return argument, but why?
Requesting:
fmt.Println( reflect.TypeOf(l))
gives *ldap.Conn as type
The code works without trying to return the object
package main
import (
"fmt"
"log"
"gopkg.in/ldap.v2"
)
var Ldap1 = "10.0.0.1"
var Lport1 = 389
var Prpl1 = "cn=admin,dc=Example,dc=com"
var Pass1 = "password"
func Bindldap(ldaphost string, port int, principal string, password string) *ldap.Conn {
l, err := ldap.Dial("tcp", fmt.Sprintf("%s:%d", ldaphost, port))
if err != nil {
log.Fatal(err)
}
defer l.Close()
err = l.Bind(principal, password)
if err != nil {
log.Fatal(err)
}
return l
}
func Main() {
a := Bindldap(Ldap1, Lport1, Prpl1, Pass1)
//do something with a
}
You error messages are telling you it's looking for a function called main
in your main
package. You called your entry point Main
(Note the caps). Try this:
func main() {
a := Bindldap(Ldap1, Lport1, Prpl1, Pass1)
//do something with a
}