摘要:
Go has pointers, but no pointer arithmetic.Struct fields can be accessed through a struct pointer. The indirection through the pointer is transparent.... 阅读全文
posted @ 2014-10-26 23:30
wuhn
阅读(138)
评论(0)
推荐(0)
摘要:
Struct fields are accessed using a dot.package main import "fmt"type Vertex struct { X int Y int}func main() { v := Vertex{1, 2} v.X = 4 ... 阅读全文
posted @ 2014-10-26 23:26
wuhn
阅读(168)
评论(0)
推荐(0)
摘要:
Astructis a collection of fields.(And atypedeclaration does what you'd expect.)package main import "fmt"type Vertext struct { X int Y int}func ... 阅读全文
posted @ 2014-10-26 23:24
wuhn
阅读(159)
评论(0)
推荐(0)
摘要:
As a simple way to play with functions and loops, implement the square root function using Newton's method.In this case, Newton's method is to approxi... 阅读全文
posted @ 2014-10-26 23:22
wuhn
阅读(346)
评论(0)
推荐(0)
摘要:
Variables declared inside anifshort statement are also available inside any of theelseblocks.package main import ( "fmt" "math")func pow(x, n, ... 阅读全文
posted @ 2014-10-26 23:06
wuhn
阅读(147)
评论(0)
推荐(0)
摘要:
Likefor, theifstatement can start with a short statement to execute before the condition.Variables declared by the statement are only in scope until t... 阅读全文
posted @ 2014-10-26 23:02
wuhn
阅读(156)
评论(0)
推荐(0)
摘要:
Theifstatement looks as it does in C or Java, except that the( )are gone and the{ }are required.(Sound familiar?)package main import ( "fmt" "m... 阅读全文
posted @ 2014-10-26 22:54
wuhn
阅读(169)
评论(0)
推荐(0)
摘要:
If you omit the loop condition it loops forever, so an infinite loop is compactly(简洁地;紧密地;细密地) expressed.package main func main() { for { ... 阅读全文
posted @ 2014-10-26 22:49
wuhn
阅读(119)
评论(0)
推荐(0)
摘要:
At that point you can drop the semicolons(分号): C'swhileis spelledforin Go.package main import "fmt"func main() { sum := 1 for sum < 1000 { ... 阅读全文
posted @ 2014-10-26 22:47
wuhn
阅读(145)
评论(0)
推荐(0)
摘要:
As in C or Java, you can leave the pre and post statements empty.package main import "fmt"func main() { sum := 1 for ; sum < 1000; { sum... 阅读全文
posted @ 2014-10-26 22:45
wuhn
阅读(144)
评论(0)
推荐(0)
摘要:
Go has only one looping construct, theforloop.The basicforloop looks as it does in C or Java, except that the( )are gone (they are not even optional) ... 阅读全文
posted @ 2014-10-26 22:42
wuhn
阅读(165)
评论(0)
推荐(0)
摘要:
Numeric constants are high-precisionvalues.An untyped constant takes the type needed by its context.Try printingneedInt(Big)too.package main import "f... 阅读全文
posted @ 2014-10-26 20:51
wuhn
阅读(397)
评论(0)
推荐(0)
摘要:
The expressionT(v)converts the valuevto the typeT.Some numeric conversions:var i int = 42var f float64 = float64(i)var u uint = uint(f)Or, put more si... 阅读全文
posted @ 2014-10-26 20:39
wuhn
阅读(145)
评论(0)
推荐(0)
摘要:
Go's basic types areboolstringint int8 int16 int32 int64uint uint8 uint16 uint32 uint64 uintptrbyte // alias for uint8rune // alias for int32 ... 阅读全文
posted @ 2014-10-26 20:08
wuhn
阅读(172)
评论(0)
推荐(0)
摘要:
Inside a function, the:=short assignment statement can be used in place of avardeclaration with implicit type.Outside a function, every construct begi... 阅读全文
posted @ 2014-10-26 20:02
wuhn
阅读(182)
评论(0)
推荐(0)
摘要:
A var declaration can include initializers, one per variable.If an initializer is present, the type can be omitted; the variable will take the type of... 阅读全文
posted @ 2014-10-26 19:55
wuhn
阅读(132)
评论(0)
推荐(0)
摘要:
Thevarstatement declares a list of variables; as in function argument lists, the type is last.package main import "fmt"var i intvar c, python, java bo... 阅读全文
posted @ 2014-10-26 19:53
wuhn
阅读(120)
评论(0)
推荐(0)
摘要:
A function can return any number of results.This function returns two strings.package mainimport "fmt"func swap(x, y string) (string, string) { ret... 阅读全文
posted @ 2014-10-26 19:47
wuhn
阅读(152)
评论(0)
推荐(0)
摘要:
import后面接的是目录的名字,而不是所谓包的名字,并且如果一个目录下面还有目录的话都必须要写进去,比如:import "MyPackage"import "MyPackage/MyInnerPackage"在这里讲明白了import后面接的是目录名而不是文件名更不是所谓的包名,那么一个目录下面的... 阅读全文
posted @ 2014-10-26 17:12
wuhn
阅读(236)
评论(0)
推荐(0)
摘要:
安装Go语言开发环境实例代码 - 详述Go语言安装所在需要的工作:安装C语言工具,安装Mercurial,更新go到新版本等操作实例。安装go环境1、简介Go是一个开源项目,采用BSD授权协议。 该文档介绍如何获取Go源代码,如何编译,以及如何运行Go程序。目前有两种方式使用Go语言。这里主要讲述如... 阅读全文
posted @ 2014-10-26 14:38
wuhn
阅读(339)
评论(0)
推荐(0)
摘要:
Go语言简介 - Go语言是由Google开发的一个开源项目,目的之一为了提高开发人员的编程效率。Go语言简介Go语言是由Google开发的一个开源项目,目的之一为了提高开发人员的编程效率。 Go语言语法灵活、简洁、清晰、高效。它对的并发特性可以方便地用于多核处理器和网络开发,同时灵活新颖的类型系统... 阅读全文
posted @ 2014-10-26 14:35
wuhn
阅读(373)
评论(0)
推荐(0)
摘要:
When running the command:+ mvn site site:stage -DskipTests -DskipTest -DskipITsyou get an error:[ERROR] Failed to execute goal org.apache.maven.plugin... 阅读全文
posted @ 2014-10-26 14:31
wuhn
阅读(1298)
评论(0)
推荐(0)
摘要:
其实golang的工程管理还是挺简单的,完全使用目录结构还有package名来推导工程结构和构建顺序。当然,首先要说的是环境变量$GOPATH,项目构建全靠它。这么说吧,想要构建一个项目,就要将这个项目添加到$GOPATH中,多个项目用";"分隔。Golang项目目录下一般有三个子目录:src存放源... 阅读全文
posted @ 2014-10-26 11:11
wuhn
阅读(13379)
评论(0)
推荐(2)
摘要:
原本不打算介绍GOPATH,然而,总是有初学者问一些关于GOPATH的问题,因此在这里再介绍一下GOPATHGOPATH环境变量用于指定这样一些目录:除$GOROOT之外的包含Go项目源代码和二进制文件的目录。go install和go 工具会用到GOPATH:作为编译后二进制的存放目的地和impo... 阅读全文
posted @ 2014-10-26 11:02
wuhn
阅读(589)
评论(0)
推荐(0)
摘要:
项目目录结构如何组织,一般语言都是没有规定。但Go语言这方面做了规定,这样可以保持一致性1、一般的,一个Go项目在GOPATH下,会有如下三个目录:|--bin|--pkg|--src其中,bin存放编译后的可执行文件;pkg存放编译后的包文件;src存放项目源文件。一般,bin和pkg目录可以不创... 阅读全文
posted @ 2014-10-26 10:59
wuhn
阅读(435)
评论(0)
推荐(0)

浙公网安备 33010602011771号