dongtu9823 2017-05-10 15:26 采纳率: 0%
浏览 81
已采纳

Golang:函数返回参数错误

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
}
  • 写回答

1条回答 默认 最新

  • dousilie9522 2017-05-10 15:34
    关注

    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
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 Attributeerror:super object has no attribute '__sklearn_tags__'_'
  • ¥15 逆置单链表输出不完整
  • ¥15 宇视vms-B200-A16@R启动不了,如下图所示,在软件工具搜不到,如何解决?(操作系统-linux)
  • ¥500 寻找一名电子工程师完成pcb主板设计(拒绝AI生成式答案)
  • ¥15 关于#mysql#的问题:UNION ALL(相关搜索:sql语句)
  • ¥15 matlab二位可视化能否针对不同数值范围分开分级?
  • ¥15 已经创建了模拟器但是不能用来运行app 怎么办😭自己搞两天了
  • ¥15 关于#极限编程#的问题,请各位专家解答!
  • ¥20 win11账户锁定时间设为0无法登录
  • ¥45 C#学生成绩管理系统