我爱占星网 我爱占星网
首页
编程
java
php
前端
首页 编程 java php 前端

Printf错误。可能是新的吗? [重复]

This question already has an answer here:

  • Formatted errors.New 1 answer

I've grown fond of the Printf of fmt and log

Is there a way I can use it with errors.New?

I tried the following:

return errors.New(fmt.Printf("User %v already exists", dbcfg.Username))

</div>

You can use fmt.Sprintf to format things into a string and fmt.Errorf to format into error.

近期文章

  • 如何在go中调用另一个函数?
  • 如何对init()函数进行基准测试
  • 在NewX函数上返回指针背后有充分的理由吗? [重复]
  • 如何在Go lang中读取config.json?
  • 同步Go例程有什么需要
  • 如何使用反射获取切片数据?
  • 在go中从另一个函数调用变量
  • 字符串和整数串联问题golang
  • 尝试将数据解组到Golang中的接口
  • 如何将DATE转换为salesforce中的数据类型DATE
  • 去样式指南? [关闭]
  • 高朗的布尔型
  • Golang解组JSON列表
  • 具有自己实现的处理程序的服务器未连续侦听
  • Golang异步和CPU使用率
  • 是否有任何便捷的方法来获取没有类型断言的JSON元素?
  • Golang HTML中继器
  • 为什么我不能键入assert空接口?
  • go中的结构的内存分配
  • Golang在将“ {}”主体解码为struct时不产生错误

Copyright ©2022 我爱占星 All Rights Reserved.

浙ICP备2022030071号-1

部分图文来自网络,如有侵犯您的版权,请告诉我们删除

友情链接:代码精华