150 likes | 419 Views
GO. 杭州联云汽车科技. 安装. 1 下载 https://code.google.com/p/go/downloads/list 2 双击安装 http://golang.org/doc/install. IDE. 1 LiteIDE 2 ECLIPSE 3 IntelliJ IDEA 4 记事本 notepad++ sublime Text vim emacs https://github.com/astaxie/build-web-application-with-golang/blob/master/ebook/01.4.md. HELLO WORLD.
E N D
GO 杭州联云汽车科技
安装 • 1 下载 • https://code.google.com/p/go/downloads/list • 2 双击安装 • http://golang.org/doc/install
IDE • 1 LiteIDE • 2 ECLIPSE • 3 IntelliJ IDEA • 4 记事本 • notepad++ sublime Text vim emacs • https://github.com/astaxie/build-web-application-with-golang/blob/master/ebook/01.4.md
HELLO WORLD • hello.go package main import "fmt" func main() { fmt.Printf("Hello, world.\n") } CMD: go run hello.go
WEB版 HELLO WORLD package main import "net/http" import "fmt" import "html" func main() { http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { fmt.Fprintf(w, "Hello, %q", html.EscapeString(r.URL.Path)) }) http.ListenAndServe(":8080", nil) }
GO and Mysql • 数据库驱动 • https://code.google.com/p/go-mysql-driver/ • db,err := sql.Open("mysql","root:@tcp(127.0.0.1:3306)/test?charset=utf8"); stmt,err := db.Prepare("insert into test(install,day,aid)values(?,?,?)"); result,err := stmt.Exec(1,2,3); rows,err := db.Query("select * from test limit 0,5"); rows.Scan(&id,&install,&day,&aid); fmt.Print(id); http://www.freewebsys.com/blog/2012/06/17/article_18.html?type=/type/2
WEB开发框架 • beego • 国人开发 类似python的tornado和php的ci • revel • 类似Java的play框架 • martini • web.go • goku • 国人开发 类似asp.net mvc
GO and GUI • go walk • go-gtk • qml • More : http://blog.bluek404.net/122
GO GUI DEMO • go walk • go get github.com/lxn/walk • go get github.com/akavel/rsrc • rsrc -manifest walk.manifest -o rsrc.syso • go build • walk.exe • DEMO代码来源:https://github.com/lxn/walk/tree/master/examples/imageviewer
GO AND CRON • https://github.com/rk/go-cron func init() { cron.NewWeeklyJob(1, 23, 59, 59, func (*time.Time) { _, err := conn.Query("OPTIMIZE TABLE mytable;") if(err != nil) { println(err) } }) }
GO AND CLOUD • 云计算语言 • go适用于大规模网络应用 • 并发控制 • goroutine 语言级别的并发协程 • channel 语言级别的队列
package main • import ( • "fmt" • "sync" • "net/http" • ) • func main() { • var wg sync.WaitGroup • var urls = []string{ • "http://www.golang.org/", • "http://www.google.com/", • "http://www.baidu.com/", • } • for _, url := range urls { • wg.Add(1) • go func(url string) { • // Decrement the counter when the goroutine completes. • defer wg.Done() • // Fetch the URL. • http.Get(url) • fmt.Println(url); • }(url) • } • wg.Wait() • fmt.Println("over"); • }
package main import "fmt" func numberGen(start, count int, out chan<- int) { for i := 0; i < count; i++ { out <- start + i } close(out) } func printNumbers(in <-chan int, done chan<- bool) { for num := range in { fmt.Printf("%d\n", num) } done <- true } func main() { numberChan := make(chan int) done := make(chan bool) go numberGen(1, 10, numberChan) go printNumbers(numberChan, done) <-done }
书籍 • Go Web 编程 • https://github.com/astaxie/build-web-application-with-golang • Go语言编程 • Go语言程序设计 • Go语言·云动力
Q & A THANKS