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) {

}
相关推荐
大大杰哥4 小时前
Java 日志框架详解:SLF4J + Logback 从入门到实战
java·开发语言·logback
神奇小汤圆4 小时前
Kafka性能调优:从10万到100万条/秒的实战经验
后端
ylscode4 小时前
黑客利用 GHOSTYNETWORKS 和 OMEGATECH 托管 JS 恶意软件基础设施
开发语言·安全·php·安全威胁分析
爱吃生蚝的于勒4 小时前
QT开发第二章——信号和槽
c语言·开发语言·c++·qt
xcLeigh4 小时前
Python入门:Python3 operator模块全面学习教程
开发语言·python·学习·教程·python3·operator
non-action_pilgrim4 小时前
Go 高并发踩坑:关于在 for 循环里使用 time.After 后所进行的问题分析
golang
Gopher_HBo4 小时前
接入层LVS
后端
404号扳手4 小时前
Java 基础知识(六)
java·后端
大叔带刺4 小时前
使用python创建自己的专属星座签名APP:Name2Constell
开发语言·python·pygame
z落落4 小时前
C# 类与对象、字段、静态与非静态+四大访问修饰符
开发语言·c#