[Golang][程式設計週記].. 2015第六週

##雜七雜八感言: 最近工作都在弄Go的Server,應該之後會把心得整理一下. 發現用Go 來處理網路的相關封包,其實相當的方便又好用啊. ##筆記: ###[Golang] 一些有趣的package 跟 網站 pt: A path tracer written in Go. 一個用Goy做的光影追蹤程式,透過gopher 3D來繪圖. Dave Cheney: Visualising the Go garbage collector 一個工具可以使覺化Go GC的狀態圖.. Go Challenge: Learn Go by solving problems and getting feedback from Go experts! 怎麼快速學習程式語言?最好的方式就是拿它來解決問題,這邊每個月有一個問題提供出來~讓大家用Go來解決…. Fucking Go Date Format 列出一些讓人很困擾的Go Date format… Go concurrency is not parallelism: Real world lessons with Monte Carlo simulations 透過一些取樣方式來證明其實Goroutine並沒有那麼的並行…. JSON, interfaces, and go generate 關於Go裡面Json資料的處理方式….. Go: Socket-level Programming 教學文章… 用Go處理TCP或是UDP server/client其實相當簡單,可以處理的事情也幾乎都包好了.. 許多的細節.. 等我弄的差不多在整理文章….. Cockroachdb 大部份使用go完成的資料庫系統…. Githut: A SMALL PLACE TO DISCOVER LANGUAGES IN GITHUB 用圖形表示在Github觀察的現象,包含做多repostories 還有最多commit跟最多issue,也有最近最多人關注的部分…. A curated list of awesome Go frameworks, libraries and software http://awesome-go.com/ 有人記錄他覺得很棒的Go toolkit list根據他的分類.常常有忽然想到要什麼 toolkit 卻又想不到名字的窘境.. 看來maintain 自己一份toolkit list 也不錯…之前放 bookmark 後來放blog 還是一樣… 似乎有份list 比較重要.. 分門別類… tag Go-kit Peter 另外的list for morden enterprise. Go-kit.io 也是一份list gosms-Your own local SMS gateway Self host SMS system, sounds good, but I am using twilio for now. ###[Golang] 關於JSONRPC 心得筆記 利用JSONRPC package 可以很快速地建立一個JSON RPC Server/Client架構. 這裏有一個簡單的example可以參考,主要要注意的事情如下:...
繼續閱讀

[Golang]Study note about 'Taking Out The Trash talk'

What is this talk about Here is the talke Taking Out the Trash: Great talk about optimizing memory allocation. about Go memory optimize and GC. I have read it, and note my understanding as follow: ##Note: ###How does Go allocate / deallocate memory? Use stack for local variable and cleanup when return. Use heap when large local variale or compiler cannot approve are not referenced. It cleanup by GC. More detail in golangDoc- stack or heap Reserving Virtual Memmory Golang will reserve the virtual memory but not use it. If you want to know how much memory use by go need check “top” (check RES/RESIZE columns). (Refer to Dave Cheney:Visualising the Go garbage collector, you can see the system memory will not return by Go) When GC Run? Base on source code src/runtime/mgc0.c define the GOGC environment is 100. We could adjust it to change to GC period. The more...
繼續閱讀

[Golang]關於 Channels 的控制一些要注意的事項(一)

前言 學習Golang 讓人最興奮的大概就是它內建的 Concurrency 的支援,並且相當的容易使用. 但是最近在學習與使用的時候,發現發現 Goroutine 可以讓本來需要用到 40 秒的 Request 減少到1/3 左右的時間.進而可以進步到 5 秒左右.平常的應用上,幾乎已經離不開 Goroutine 與Channel。 但是最近遇到幾個例子,一開始覺得很不能理解,也不容易解決.也是讓我找了一些解決方式. 一般用法 Go Channel一般有兩種用法(當然有更多的使用方式可以用),一個是把channel當成資料來傳遞,另外的方式只是單純把channel當成是signal來等待或是啟動新的thread // 同時要處理多個可以同步運行的運算,利用channel來回傳結果 c := make(chan int) // Allocate a channel. go func() { result : = do_some_cal() c <- result }() c2 := make(chan int) // Allocate a channel. go func() { result : = do_some_cal2() c2 <- result }() totalResult := <-c2 + <-c fmt.Printf("result is %d"), totalResult) // 傳送訊號(signal)的方式 c := make(chan int) // Allocate a channel. go func() { list.Sort() c <- 1 // Send a signal; value does not matter. }() doSomethingForAWhile() <-c // Wait for sort to finish; discard sent value. 陷阱出現了 以上兩個方式相當的簡單,也相當直覺來使用.但是如果要跑goroutine的條件不是必要呢?也就是說不一定要透過go routine來同步執行很多的結果呢? c := make(chan int) //並不一定會進入go routine來計算,也就是說channel會是為空的. if needRoutine == true { go func() { result : = do_some_cal() c <- result }() } else { c <- 0 //note this kind will not work, because channels need input value in...
繼續閱讀

[Golang][程式設計週記].. 2015第五週

##雜七雜八感言: 令人開心的事情,總算在工作上把某些專案推坑Golang… 可以更專心的學習跟使用Golang… ##筆記: ###[Golang] 一些有趣的package 跟 網站 [Golang][Gala] Final list of Gala 最後進入final 名單的Gala 2015競爭者,Docket竟然被踢掉了… [Golang][Gala] http://gophergala.com/blog/gopher/gala/2015/02/03/winners/ 最後的獲勝者出線了…. [Golang]Go Report Card: A report card for your Go application 根據你github上面的go project給予一些分數,評分依據根據gofmt, go vet, go lint與 gocyclo. 挺有趣的,很多時候issue越多並不代表分數不高喔… [Golang] Beego 的教學(tutorial) First,Second, Third, Git 這是之前又介紹過MVC架構的Web Framework Beego的教學.Beego被許多大公司所使用(Weibo, Taobao, Tudou….),算是很棒的架構,有機會可以好好學習. [Golang]Moving from Node.js to Go at Bowery Bowery這家公司把他們平台從Node.js換到Go的經歷.裡面有提到以下的優點: Easy to write cross-platform code, Faster deployment, Concurrency primitives, Integrated testing framework, Standard library and Developer workflow tools are more powerful. [Golang] Go HTTP request router benchmark and comparison 有各種Go Webframework的效能比較,幾個值得注意的事情是net/http 的ServerMux並不會有最好的效能.而martini雖然效能最差,但是擴展性是最高的. 也可以順便知道有多少web framework…. (Beego, go-json-rest, Denco, Gocraft Web, Goji, Gorilla Mux, http.ServeMux, HttpRouter, HttpTreeMux, Kocha-urlrouter, Martini, Pat, TigerTonic, Traffic) [Livehouse.in] 關於c9s的slideshare “Get Merge!” Get Merge [Golang] Sample Email Sender using SocketLabs 不錯的寄信範例程式使用Go [Golang] 關於Session的學習 要開始弄martini關於authorication的部分,首先最簡單的除了SSL之外,就使用session了. Martini session 提供了一個相當簡單的方式來使用. 首先可以參考這段教學影片,其實相當的簡單易用,也可以設定哪些網址才需要透過session. [Golang] 關於Go與CGI的搭配 本來的討論是希望讓Go可以取代PHP在Apache中的地位,主要可以達成以下的結果: 可以多個process,彼此獨立 一個process 出事情不會影響到全部的系統. 是開始尋找有沒有類似的結果,如下: Deploying Go web services behind Nginx under Debian or Ubuntu 讓你架起來nginx之後,每一個CGI去執行Go Apache - mod_go 恩… 就是Apache 裡面可以直接跑Go….....
繼續閱讀

[Golang][程式設計週記].. 2015第四週

##雜七雜八感言: 啊… 我覺得我blog樣板好醜啊….應該要改成Patrick類似的… 本來想加回廣告的… 後來看到每天流量沒有破百…. 算了…. ##筆記: 以下是關於本週的學習筆記… ###[Golang] 一些有趣的package 跟 網站 goth: Package goth provides a simple, clean, and idiomatic way to write authentication packages for Go web applications. 可以很快速地使用OAuth跟OAuth2的工具. switcher: Run SSH and HTTP(S) on the same port 可以同一個communication port 同時接受http跟https 或是ssh,透過protocol 不同, 比如說原本跑http的port 80,可以透過switcher把https的request導到另外一個process $ switcher –listen :80 –ssh 127.0.0.1:22 –default 127.0.0.1:8080 總覺得會是很有用的東西…. deck: Slide Decks 可以透過markup language來做投影片,挺有趣的. Docket - Custom docker registry that allows for deploys through bittorrent 有神人在Gopher Gala Golang 48 hour hackathon的作品.. 很特別的點子是.. 透過bittorrent來deploy go iOS.App() 一個關於如何用Go在iOS上面寫App的討論串,有不少成果可以看. goIosHelloWorld: a go ios hello world project Using Go in mobile apps: How I learned Go while integrating it into my iOS and Android app 記錄了如何用Go寫Android/iOS的App,一開始有先介紹如何使用cgo接下來就是如何寫出App. Gopher Gala 2015 hackathon 第一屆的Gopher hackathon,優勝者會在02/03揭曉,挺多有趣的專案說… ImgurGo: An open source image uploader by the Imgur team 這次Gala參賽作品.. imgur 團隊用go寫了圖片上傳網站… 還支援AWS… cool freegeoip: IP geolocation web server http://freegeoip.net 一個工具可以讓你用ip找到位址,只有第一次使用的時候會把資料庫下載下來.其他查詢都很快. Excellent Open Source Go Projects Go open source project 大排名,第一名竟然是Go-github.docker落到第十名…. : Hound: Lightning...
繼續閱讀

[Golang] Enable HTTPS in martini using martini-contrib/secure

實在有點懶得用中文來寫了… 讓我用英文寫這篇吧… Before this.. I am learning about golang on server backend side programming via martini. I want to write a RESTful server communicate via JSON. Currently my framework as follow: Host on: Heroku DB: MongoDB Web framework: maritini Here is the note about how I add martini-secure HTTPS in martini. Working step with martini-secure 1. Create a SSL key using generate_cert.go You need create your localhost SSL key (or purchase one from CA) using generate_cert.go. I am not sure how to get this package, so I just download this source code and run it locally. go run generate_cert.go --host="localhost" You will get file “key.pem” and “cert.pem”, just put in your web side source code. 2. Apply martini-secure in martini program. It is very easy to add SSL as a plugin in martini, here is some code. At first I would like to host two services as follow: HTTP: port...
繼續閱讀