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

}
相关推荐
小妖同学学AI10 分钟前
Rust 深度解析:基本类型的“精确”艺术
开发语言·后端·rust
我命由我1234514 分钟前
Guava - Guava 基本工具 Preconditions、Optional
java·服务器·开发语言·后端·java-ee·guava·后端框架
Python私教27 分钟前
Rust 快速入门:从零到上手的系统指南
开发语言·后端·rust
JosieBook36 分钟前
【SpringBoot】30 核心功能 - 单元测试 - JUnit5 单元测试简介与常用注解实战详解
spring boot·后端·单元测试
cj63411815042 分钟前
网卡驱动架构以及源码分析
java·后端
Sincerelyplz44 分钟前
【JDK新特性】分代ZGC到底做了哪些优化?
java·jvm·后端
zs宝1 小时前
Java 限流简易实现
后端
ouliten1 小时前
C++笔记:std::variant
开发语言·c++·笔记
Joker100851 小时前
仓颉 String 内存表示:从 UTF-8 小对象到零拷贝子串的完整旅程
开发语言
REDcker2 小时前
C++项目 OpenSSL 依赖最佳实践
开发语言·c++