作者热门文章
- r - 以节省内存的方式增长 data.frame
- ruby-on-rails - ruby/ruby on rails 内存泄漏检测
- android - 无法解析导入android.support.v7.app
- UNIX 域套接字与共享内存(映射文件)
我正在尝试创建一个将显示用户 IP 的 go 应用。
我无法弄清楚我的日志控制台错误:
go:14: not enough arguments in call to getJsonRes
Go 应用代码:
package main
import (
"encoding/json"
"net/http"
"fmt"
)
type Addrs struct {
ip string
}
func handler(w http.ResponseWriter, r *http.Request) {
response, err := getJsonRes()
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
w.Header().Set("Content-Type", "application/json")
fmt.Fprintf(w, string(response))
}
func main() {
http.HandleFunc("/", handler)
}
func getJsonRes(r *http.Request)([]byte, error ) {
ip := Addrs{ r.RemoteAddr }
return json.MarshalIndent(ip, "", " ")
}
最佳答案
你的函数
func getJsonRes(r *http.Request)([]byte, 错误 )
获取请求指针并返回字节数组和/或错误。
在这条线上
响应,错误 := getJsonRes()
您可以不带任何参数地调用它。您可能打算执行以下操作
响应,错误 := getJsonRes(r)
关于go - 调用中没有足够的参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30268749/
对于我的问题,我找不到更好的措辞。 在我的应用程序中的某个时刻,我设置了一些非常密集的动画。问题是,在高端设备上,动画运行流畅且赏心悦目。另一方面,我测试过的一台低端设备在制作动画时表现非常糟糕。 试
我正在修补 OTP 模块 ( yubico_pam ),并尝试访问管理员选择的控制标志(例如必需,足够, ETC)。 有什么想法吗?这是否可行(无需解析文件)? 最佳答案 无法在 API 中查询此信息
我有一些为 Linux 编写的 C 代码,依赖于套接字和 arpa/inet.h 以及 libusb.h,我想在 MinGW 下为 Windows 编译它。 (请注意,当前项目只有一个非常简单的 Ma
我是一名优秀的程序员,十分优秀!