Golang-经验>关于 http: multiple registrations for /xxx/ 错误的解决办法

本文介绍了在Golang编程中遇到http: multiple registrations for /xxx/错误的原因及解决方法,错误通常由同一文件路径的多次注册引起。解决办法是确保只注册一次handler函数,避免重复执行http.FileServer()导致的路径注册冲突。
摘要由CSDN通过智能技术生成

关于 http: multiple registrations for /xxx/ 错误的解决办法

一、起因

出现错误的情况:

http: multiple registrations for ./
http: multiple registrations for /img/ 
http: multiple registrations for /xxx/ 

一般都是因为在所写的Golang代码中,多次注册同一文件路径导致的,比如下面这段代码就会出现这样的报错

func handler(){
   
	http.Handle("/img/", http.FileServer(http.Dir("www")))
}

func main(){
   
	http.HandleFunc("/",handler)
	log.Fatal(http.ListenAndServe
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值