找到目录 golang 的文章 14 篇.


golang: 详解interface和nil

Posted on 2014-01-28 15:23:13 golang

摘要:

golang的nil在概念上和其它语言的null、None、nil、NULL一样,都指代零值或空值。nil是预先说明的标识符,也即通常意义上的关键字。在golang中,nil只能赋值给指针、channel、func、interface、map或slice类型的变量。如果未遵循这个规则,则会引发panic。

阅读全文

GDB调试Go程序

Posted on 2014-01-28 14:45:24 golang

摘要:

说明:作为一门静态语言,似乎支持调试是必须的,而且,Go初学者喜欢问的问题也是:大家都用什么IDE?怎么调试?

其实,Go是为多核和并发而生,真正的项目,你用单步调试,原本没问题的,可能会调出有问题。更好的调试方式是跟PHP这种语言一样,用打印的方式(日志或print)。

阅读全文

golang: 类型转换和类型断言

Posted on 2014-01-28 11:13:22 golang

摘要:

类型转换在程序设计中都是不可避免的问题。当然有一些语言将这个过程给模糊了,大多数时候开发者并不需要去关注这方面的问题。但是golang中的类型匹配是很严格的,不同的类型之间通常需要手动转换,编译器不会代你去做这个事。我之所以说通常需要手动转换,是因为interface类型作为一个特例,会有不同的处理方式。

阅读全文

Automatically start a local godoc web server

Posted on 2014-01-23 22:40:55 golang

Godoc is awesome, It allows you to browse all the documentation on your local machine by running the following command:

godoc -http=:8090

Once you do this you can happily browse through all the documentation offline. However, you can start this process as an upstart daemon and let it run in the background. All you have to do is create a file called /etc/init/godoc.conf with the following content:

#Upstart script to start godoc server
#*This obviously works on machines with upstart*
start on runlevel [2345]
stop on runlevel [06]

script
  export HOME=/home/roy/coding
  export GOROOT=$HOME/go
  export GOBIN=$GOROOT/bin
  export GOPATH=$HOME/gocode
  $GOBIN/godoc -http=:8090 -index=true
end script

You just need to make sure that the env vars are adjusted to your setup. Also, using -index=true runs a full text search on all your documentation (which is simply awesome). Now, you will have your godoc server at http://localhost:8090/ all the time.

On a related note, godoc can be used from the command line like:

#godoc <pkg name> Type/Func
godoc net Listener