1 / 15

杭州联云汽车科技

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.

tarak
Download Presentation

杭州联云汽车科技

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. GO 杭州联云汽车科技

  2. 安装 • 1 下载 • https://code.google.com/p/go/downloads/list • 2 双击安装 • http://golang.org/doc/install

  3. 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

  4. HELLO WORLD • hello.go package main import "fmt" func main() { fmt.Printf("Hello, world.\n") } CMD: go run hello.go

  5. 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) }

  6. 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

  7. WEB开发框架 • beego • 国人开发 类似python的tornado和php的ci • revel • 类似Java的play框架 • martini • web.go • goku • 国人开发 类似asp.net mvc

  8. GO and GUI • go walk • go-gtk • qml • More : http://blog.bluek404.net/122

  9. 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

  10. 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) } }) }

  11. GO AND CLOUD • 云计算语言 • go适用于大规模网络应用 • 并发控制 • goroutine 语言级别的并发协程 • channel 语言级别的队列

  12. 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"); • }

  13. 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 }

  14. 书籍 • Go Web 编程 • https://github.com/astaxie/build-web-application-with-golang • Go语言编程 • Go语言程序设计 • Go语言·云动力

  15. Q & A THANKS

More Related