go 学习笔记(4) ---项目结构
go install和go build之争。目前,IDEA插件和LiteIDE都采用了go build。Eclipse插件采用了go install。官方推荐go install方式编译项目,官方项目结构应该是
项目名称 |--bi |--pkg +--src
package main、func main() { }、func init() { }
go语言面向对象
// File Name: main.go package main import ( "fmt" ) type Human interface { Talk() } type Person struct { name string Human // Person is-a Human } func (p *Person) Talk() { fmt.Println("Hi, my name is", p.name) } type Citizen struct { country string person Person Human //B is-a A } func (c *Citizen) Talk() { fmt.Println("Hi, my name is", c.person.name) } func SpeakTo(h Human) { h.Talk() } func main() { p := Person{name: "Dave"} c := Citizen{person: Person{name: "Steve"}, country: "America"} SpeakTo(&p) SpeakTo(&c) }
go语言并发
// File Name: main.go package main import ( "fmt" ) var ch = make(chan string) func message() { msg := <-ch fmt.Println(msg) } func main() { go message() ch <- "Hello,CSP." }