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

将结构变量/名称添加到:=的左侧

How to shorten this code

access_log, err := os.OpenFile("log/access.log", os.O_CREATE|os.O_APPEND|os.O_WRONLY, 0660);
w.access_log = access_log

To something like this

w.access_log, err := os.OpenFile("log/access.log", os.O_CREATE|os.O_APPEND|os.O_WRONLY, 0660);

You need to assign (=), not declare (:=):

var error
w.access_log, err = os.OpenFile("log/access.log", os.O_CREATE|os.O_APPEND|os.O_WRONLY, 0660);

:= is for Short Variable declaration, and w.access_log is already declared (in w struct)

It is discussed in issue 6842.

近期文章

  • 等效于OpenSSL EVP对称EVP_aes_256_cbc
  • 如何设置NSDictionary的key值
  • java 编程实现学生成绩管理系统
  • 安全地终止handlefunc之外的请求
  • 在go html模板中创建循环的最佳方法是什么?
  • EXE之后的命令行参数
  • 在beegae中使用CSS
  • 为什么json.Marshal和json.Unmarshal具有不同的签名
  • 调用c函数时,“ import fmt”,“ import C”的顺序导致生成错误,为什么?
  • gvm在Ubuntu 14.04中设置GOPATH
  • 前往:在JSON响应中从数据库中复制各种类型的数据
  • 转到:使用有效负载/正文发布
  • 如何在Go中“转换”指针类型以匹配指向的值的类型?
  • 从reflect.Value去编码JSON
  • 在Go中为JSON指定分隔符
  • 如何从slice填充函数参数?
  • 重定向太多,但通过什么途径?
  • 用于多个站点的HTML模板
  • 转到:方法调用后对象不持久
  • golang系统日志失败:Unix系统日志传送错误

Copyright ©2022 我爱占星 All Rights Reserved.

浙ICP备2022030071号-1

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

友情链接:代码精华