千万不要用window自带文本编辑器编辑配置文件或者代码
1 引言
用windows自带的text文本在最前面会带入看不到的BOM,导致异常
2 代码
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | package main import ( "strings" "fmt" ) func main(){ line := "// mysql数据库链接配置" if strings .EqualFold(line[:2], "//" ){ fmt .Println( "this is comment" ) } else { fmt .Println( "this is not comment" ) } } |
运行结果如下:
1 2 3 4 | # command-line-arguments test \ test \testFilterRemark.go:17:11: invalid BOM in the middle of the file Compilation finished with exit code 2 |
如果改为:(在文本上是看不出差异性的)
1 2 3 4 5 6 7 8 | func main(){ line := "// mysql数据库链接配置" if strings .EqualFold(line[:2], "//" ){ fmt .Println( "this is comment" ) } else { fmt .Println( "this is not comment" ) } } |
运行结果如下:
1 2 3 | this is comment Process finished with exit code 0 |
3.扩展资料
1.不要使用Windows自带记事本写代码( http://rabbitfeet.net/archives/144.html)
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步