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 一道python难题2
  • ¥15 一道python难题
  • ¥15 用matlab 设计一个不动点迭代法求解非线性方程组的代码
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler
  • ¥15 oracle集群安装出bug
  • ¥15 关于#python#的问题:自动化测试
  • ¥20 问题请教!vue项目关于Nginx配置nonce安全策略的问题
  • ¥15 教务系统账号被盗号如何追溯设备