zoukankan      html  css  js  c++  java
  • 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 !
    ")
    }

    添加缺失的“}”后,编译通过!

    到底提示的错误信息是什么呢? 原来是告知“不允许函数嵌套” 。

    好了,仅此记录出现过的错误。

  • 相关阅读:
    C++ 日期 & 时间
    C++ 引用
    C++ 指针
    C++ 字符串
    C++ 数组
    C++ 数字
    C++ 函数
    C++ 判断
    C++ 循环
    C++ 运算符
  • 原文地址:https://www.cnblogs.com/howDo/p/golang-nested-func-not-allowed.html
Copyright © 2011-2022 走看看