go composite literal uses unkeyed fields错误

1:背景

go vet composite literal uses unkeyed fields错误

2:废话少说,直接上代码

Go 复制代码
//main里面调用GetLoginAuth封装的方法
authDetail, authErr := opMini.GetLoginAuth(ctx, openyun.LoginAuthParam{
    deviceId,
})


//对应方法类
type LoginAuthParam struct {
	DeviceId string
}

func () GetLoginAuth(ctx utils.Context, params LoginAuthParam) (t LoginAuthInfoData, err error) {

}

以上代码在本地可以正常运行,也能正常编译,但语法检查会报错:

在使用go vet进行语法检查时, 报了这么个错composite literal uses unkeyed fields

3:解决(增加对应字段key)

在调用时候需要加上对应的字段可名称,不能直接给值

Go 复制代码
//main里面调用GetLoginAuth封装的方法
authDetail, authErr := opMini.GetLoginAuth(ctx, openyun.LoginAuthParam{
    DeviceId:deviceId   //在调用时候需要加上对应的字段key  !!!!!!!!!!!!
})


//对应方法类
type LoginAuthParam struct {
	DeviceId string
}

func () GetLoginAuth(ctx utils.Context, params LoginAuthParam) (t LoginAuthInfoData, err error) {

}
相关推荐
VBA63371 分钟前
VBA之Word应用第四章第一节:段落集合Paragraphs对象(一)
开发语言
我是不会赢的21 分钟前
使用 decimal 包解决 go float 浮点数运算失真
开发语言·后端·golang·浮点数
续晋华22 分钟前
Go语言数据类型深度解析:位、字节与进制
golang·数据类型
胤祥矢量商铺37 分钟前
菜鸟笔记007 [...c(e), ...d(i)]数组的新用法
c语言·开发语言·javascript·笔记·illustrator插件
yuqifang37 分钟前
写一个简单的Java示例
java·后端
Re27539 分钟前
分库分表后主键总“撞车”?5种全局唯一ID方案让你不再头疼
后端
青红光硫化黑1 小时前
学习bug
开发语言·javascript·ecmascript
陈随易1 小时前
VSCode v1.103发布,AI编程任务列表,可用GPT 5和Claude 4.1
前端·后端·程序员
中等生1 小时前
Python的隐形枷锁:GIL如何"绑架"了你的多线程梦想
后端·python