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 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化
  • ¥15 Mirare PLUS 进行密钥认证?(详解)
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证
  • ¥20 想用ollama做一个自己的AI数据库
  • ¥15 关于qualoth编辑及缝合服装领子的问题解决方案探寻
  • ¥15 请问怎么才能复现这样的图呀