我正在尝试从其他目录调用方法,但收到一条错误消息,指出该方法不存在。我有第一个字母大写的方法。
我有以下目录结构
[laptop@laptop src]$ tree
.
??? hello
? ??? hello.go
??? remote_method
? ??? remoteMethod.go
Run Code Online (Sandbox Code Playgroud)
我的主要人员在hello.go中,并尝试从remote_method包中调用函数
package main
import
(
"remote_method"
)
func main() {
mm := remote_method.NewObject()
mm.MethodCall()
}
Run Code Online (Sandbox Code Playgroud)
remoteMethod.go具有以下内容
package remote_method
import (
.....
)
type DeclaredType struct {
randomMap (map[string][](chan int))
}
func NewObject() DeclaredType {
var randomMap (map[string][](chan int))
m := DeclaredType{randomMap}
return m
}
func MethodCall(m DeclaredType, param1 string, param2 string, param3 string, param4 string) {
// Code to be run
}
Run Code Online (Sandbox Code Playgroud)
我得到错误
mm.MethodCall undefined (type remote_method.DeclaredType has no field or method MethodCall)
Run Code Online (Sandbox Code Playgroud)
有人可以帮助我找出为什么该方法不可见或我可以找到任何可能的方法。TIA
将MethodCall()注册为DeclaredType中的接收者。
remote_method.go
package remote_method
import (
.....
)
type DeclaredType struct {
randomMap (map[string][](chan int))
}
func NewObject() DeclaredType {
var randomMap (map[string][](chan int))
m := DeclaredType{randomMap}
return m
}
func (d DeclaredType) MethodCall(m DeclaredType, param1 string, param2 string, param3 string, param4 string) {
// Code to be run
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
49 次 |
| 最近记录: |