我试图使用Go参数函数作为它的描述在以下链接友好API的功能选项 -但我得到一个类型错误,我不知道为什么。
我在这里添加我的代码以供您审阅:
错误信息是:
prog.go:35:18:不能将端口(类型func(*Server))用作NewServer参数中的func(*Server)类型错误
发布于 2018-06-21 01:47:57
正如JimB所指出的,签名需要完全匹配,包括返回值。在示例代码中,要么存在端口返回错误,例如:
port := func(srv *Server) error {
srv.Port = 8080
return nil
}https://play.golang.org/p/LYb846jBD-m
或从NewServer定义中删除错误:
func NewServer(name string, options ...func(srv *Server)) *Serverhttps://stackoverflow.com/questions/50958365
复制相似问题