import

import unuse package:
error : imported and not used: "os"

:= =

c := 1 // error non-declaration statement outside function body
d = 1 // error non-declaration statement outside function body

func test(){

c = 1 //undefined: should be c:=1

//d = 1

var f , d int

f,d = cal()

fmt.Println(c, f, d)

}


right using value declare and use

package main

import "fmt"

//var a := 0 //wrong
var a int = 0
//c := 1 //wrong
//d = 1 //wrong func cal(b int)(val1 int, val2 int){
fmt.Println(b)
val1 = 1
val2 = 2
return
}
func test(){
c := 1
//d = 1 //wrong
var f , d int
f,d = cal(1)
fmt.Println(c, f, d)
}
func main() {
fmt.Println("Hello, world var")
}

declear not use

./right.go:14: c declared and not used

type struct init using () ,instead of {} ,which {} is the right usage

type Response struct {
Code string `json:"code"`
Body string `json:"body"`
}
//not like this ()
//Response("OK", "ECHO: " + method + " ~ " + params)
//right usage {}
Response{"OK", "ECHO: " + method + " ~ " + params}

如何理解以下代码:

type IpcClient struct {
conn chan string
}
func (client *IpcClient)Call(method, params string)(resp *Response, err error){
}
  • (client *IpcClient) -- 调用的对象要是 IpcClient struct
  • (method, params string) -- 参数,前面是参数名,后面是参数类型,两种同类别省略写法。
  • (resp *Response, err error) 参数返回值,返回值的第一个参数,类型为 Response struct 对象指针, 返回值的第二个参数,类型为 error 类型,

wrong not using go keyworld when call async func

golang常见错误的更多相关文章

  1. Go的50度灰:Golang新开发者要注意的陷阱和常见错误

    Go的50度灰:Golang新开发者要注意的陷阱和常见错误 http://colobu.com/2015/09/07/gotchas-and-common-mistakes-in-go-golang/

  2. Go的50度灰:Golang新开发者要注意的陷阱和常见错误(转)

    目录 [−] 初级 开大括号不能放在单独的一行 未使用的变量 未使用的Imports 简式的变量声明仅可以在函数内部使用 使用简式声明重复声明变量 偶然的变量隐藏Accidental Variable ...

  3. [转载]Go的50度灰:Golang新开发者要注意的陷阱和常见错误

    初级 开大括号不能放在单独的一行 未使用的变量 未使用的Imports 简式的变量声明仅可以在函数内部使用 使用简式声明重复声明变量 偶然的变量隐藏Accidental Variable Shadow ...

  4. Golang新开发者要注意的陷阱和常见错误

    转自:http://colobu.com/2015/09/07/gotchas-and-common-mistakes-in-go-golang/ 目录 [−] 初级 开大括号不能放在单独的一行 未使 ...

  5. GO 新开发者要注意的陷阱和常见错误

    转自:http://colobu.com/2015/09/07/gotchas-and-common-mistakes-in-go-golang/ 初级 开大括号不能放在单独的一行 未使用的变量 未使 ...

  6. goroutine的使用与常见错误

    goroutine的使用时常见错误 goroutine是Golang 的核心之一,在使用时,一般都要配合channel一起使用. 在使用时,经常会遇到一些错误,包括: 不输出 输出与希望输出不一致 a ...

  7. 100 个常见错误「GitHub 热点速览 v.22.35」

    本周的特推非常得延续上周的特点--会玩,向别人家的女朋友发送早安.这个错误是如何发生的呢?如何有效避免呢?自己用 daily_morning 免部署.定制一个早安小助手给女友吧. 除了生活中的错误,工 ...

  8. 初识JAVA(二)(送给Java和安卓初学者)----常见错误

    博主接着上篇的来讲哦,以后的更新中,博主会出一些练习题,有兴趣的可以做做然后吧代码粘贴到下面,大家可以一起研究学习,一起进步,本篇文章主要讲的是: 一.常见错误 二.连接上篇一起的训练 无论是什么方向 ...

  9. ubuntu 常见错误--Could not get lock /var/lib/dpkg/lock

    ubuntu 常见错误--Could not get lock /var/lib/dpkg/lock 通过终端安装程序sudo apt-get install xxx时出错:E: Could not ...

随机推荐

  1. while循环与 for循环

    import turtle turtle.setup(600,400,0,0) turtle.bgcolor('red') turtle.color('yellow') turtle.fillcolo ...

  2. Map集合练习题

    (Map)已知某学校的教学课程内容安排如下: 完成下列要求:1) 使用一个Map,以老师的名字作为键,以老师教授的课程名作为值,表示上述课程安排.2) 增加了一位新老师Allen 教JDBC3) Lu ...

  3. 练习 HashSet 去重复

    package com.rf.xs.list; import java.util.HashSet; public class Person { private String name; private ...

  4. LIMIT用法

    select * from employees order by hire_date DESC LIMIT 0,3; 直接给语句说明:根据hire_date 降序排列,LIMIT 第一个参数表示从第几 ...

  5. 东芝L10安装Centos5.5

    为什么安装5.5:因为高版本的需要PAE设定但是老电脑不支持,偶又不想重新编译内核,so... 1.  安装之前需要把电脑格式化(我是整机安装Linux),否则会报not enough space l ...

  6. Python03(Linux和Python简介)

    Trainning-day02回顾1.rmdir : 删除空文件夹2.rm :删除文件或者文件夹 -r 删除目录以及其内容 -i 删除前的提示 -f 强制删除3.通配符 * 匹配任意多个任意字符 ?匹 ...

  7. java面向对象编程(九)--final

    1.final概念 final可以修饰变量或者方法.在某些情况下,程序员可能有以下需求: a.当不希望父类的某个方法被子类覆盖(override)时,可以用final关键字修饰. b.当不希望类的某个 ...

  8. win7安装python3.6.1及scrapy

    ---恢复内容开始--- 第一篇博客,记录自己自学python的过程及问题. 首先下载python3.6.1及所需资料 百度云:https://pan.baidu.com/s/1geOEp6z 密码: ...

  9. key单片机按键抖动

    //write by:cyt //Time:2017-2-10 //Porject Name:key shake_destory #include<reg51.h> #define GPI ...

  10. 服务器配置+wordpress建站(小白)

    一. 安装好centos7.2系统后,登录centos系统输入如下命令: yum install -y wget && wget -O install.sh http://downlo ...