golang build error: syntax error: nested func not allowed
在笔记本中写了一个简易web程序,但是编译失败,提示“syntax error: nested func not allowed” 。
不明白什么意思,幸好代码量小,原来是方法的末尾的“}”丢了!
package main import "fmt" import "net/http" func main() { http.HandleFunc("/", hello) err := http.ListenAndServe(":8080", nil) if err != nil { fmt.Println(err) } } func hello(rw http.ResponseWriter, r *http.Request) { fmt.Fprintf(rw, "Hello lao yu !\n") }
添加缺失的“}”后,编译通过!
到底提示的错误信息是什么呢? 原来是告知“不允许函数嵌套” 。
好了,仅此记录出现过的错误。
老虞,Gopher,golang主页:http://howdo.cnblogs.com/
【推荐】还在用 ECharts 开发大屏?试试这款永久免费的开源 BI 工具!
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步