Time of Update: 2018-08-01
import ( "fmt" "sort")type MapSorter []Itemtype Item struct { Key string Val int64}func NewMapSorter(m map[string]int64) MapSorter { ms := make(MapSorter, 0, len(m)) for k, v := range m { ms = append(ms,
Time of Update: 2018-08-08
很多人認為 monkey 補丁只能在動態語言,比如 Ruby 和 Python 中才存在。但是,這並不對。因為電腦只是很笨的機器,我們總能讓它做我們想讓它做的事兒!讓我們看看 Go 中的函數是怎麼工作的,並且,我們如何在運行時修改它們。本文會用到大量的 Intel 彙編,所以,我假設你可以讀彙編代碼,或者在讀本文時正拿著[參考手冊](https://software.intel.com/en-us/articles/introduction-to-x64-assembly).**如果你對
Time of Update: 2018-08-07
介面型函數:指的是用函數實現介面,這樣在調用的時候就會非常簡便,這種函數為介面型函數,這種方式適用於只有一個函數的介面。 定義一個類型,這個類型只定義了函數的參數列表,函數參數列表與介面定義的方法一致:type HandlerFunc func(k, v interface{})然後這個類型去實現介面,實現的函數調用自己func (hf HandlerFunc) Do(k, v interface{}) {hf(k, v) //
Time of Update: 2018-07-31
簡介當前主機資訊: Ubuntu16.04 x86_64root@JDu4e00u53f7:~# uname -aLinux JDu4e00u53f7 4.4.0-62-generic #83-Ubuntu SMP Wed Jan 18 14:10:15 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux我們需要準備的環境有:cURLDocker ComposeDockerGolangNodejs安裝安裝cURLsudo apt-get install curl
Time of Update: 2018-08-07
前言在 .NET 中主要有兩種動態產生並編譯的方式,一種是通過 System.Linq.Expressions 命名空間中的 LambdaExpression 類的 CompileToMethod(...) 方法,但是這種方法只支援動態編譯到靜態方法,因為這個限制我們只能放棄它而採用 Emitting 產生編譯方案,雖然 Emitting 方案強大但是實現起來麻煩不少,必須要手動處理底層 IL 的各種細節,腦補一些 C# 編譯器的實現機理,同時還要瞭解一些基本的 IL(Intermediate
Time of Update: 2018-07-31
Go語言允許使用者定義型別。當使用者聲明一個類型時,這個聲明就給編譯器提供了一個架構,告知必要的記憶體大小和資訊。聲明結構類型type user struct { name string email string}上述代碼聲明的結構類型有2個欄位,每個欄位都基於一個內建類型。一旦聲明了類型,就可以使用這個類型建立值。使用結構型別宣告變數var zuckjet
Time of Update: 2018-08-06
golang中的fnv包實現了非加密hash函數What is the difference between a Hash Function and a Cryptographic Hash Function?Every cryptographic hash function is a hash function. But not every hash function is a cryptographic hash.A cryptographic hash function aims to
Time of Update: 2018-08-10
Go 語言誕生5周年!友情提示:本文使用Markdown編寫,黑色背景文字可能需要橫向拖動才能看清全文最近為了做Hyperledger Fabric國密改造,涉及到了golang源碼的改動。特將操作過程整理如下,以供參考:golang的源碼安裝其實比較簡單,只需運行源碼包中的指令碼src/all.bash,等到出現類似以下字樣就安裝好了:Installed Go for linux/amd64 in xxx(目錄位址)Installed commands in xxx(目錄位址)但是在源碼安裝1
Time of Update: 2018-08-06
環境搭建快速入門: http://hyperledger-fabric.rea...前提安裝git$ sudo apt update$ sudo apt install git安裝curl$ sudo apt install curl安裝vim$ sudo apt install vim安裝Docker$ sudo apt update$ docker --version$ sudo apt install docker.io查看Docker版本資訊version 1.12+$ docker
Time of Update: 2018-08-10
golang學習筆記17 爬蟲技術路線圖,python,java,nodejs,go語言,scrapy主流架構介紹go語言爬蟲架構:gocolly/colly,goquery,colly,chromedp,webloop,go_spider,Pholcus https://github.com/hu17889/go_spiderPholcus 幽靈蛛重量級爬蟲軟體(含3種操作介面) - Golang中國https://www.golangtc.com/p/557473c9b09ecc2aa700
Time of Update: 2018-08-10
func Search(n int, f func(int) bool)
Time of Update: 2018-08-09
錯誤處理前面的分享加了兩個功能,一個是編輯功能,一個儲存功能在我們的程式中有幾個地方其實是忽略了錯誤的處理。這是不好的做法,尤其是因為這樣的做法發生錯誤時,程式會出現意外行為。更好的解決方案是處理錯誤並向使用者返回錯誤訊息。這樣,如果出現問題,伺服器將完全按照我們想要的方式運行,並且可以通知使用者。首先,讓我們處理renderTemplate中的錯誤:func renderTemplate(w http.ResponseWriter, templateName string, p *Page)
Time of Update: 2018-08-09
基於記憶體的Redis應該是目前各種Web開發業務中最為常用的Key-Value資料庫了,我們經常在業務中用其儲存使用者登陸態(Session儲存),加速一些熱資料的查詢(相比較MySQL而言,速度有數量級的提升),做簡單的訊息佇列(LPUSH和BRPOP)、訂閱發布(PUB/SUB)系統等等。規模比較大的互連網公司,一般都會有專門的團隊,將Redis儲存以基礎服務的形式提供給各個業務調用。不過任何一個基礎服務的提供方,都會被呼叫者問起的一個問題是:你的服務是否具有高可用性?最好不要因為你的服務
Time of Update: 2018-08-04
### 介紹為簡化使用流程,減少開發時間,降低項目開發成本,搭建了一套基於 ```Gin``` 的web骨架。組件包括但不局限於路由、控制器、Orm、session、cookie、mysql串連、認證中介軟體等。項目地址:https://github.com/chenhg5/morningo### 使用指南提供了一個命令列工具,morningo-installer。可以直接下載:```wget
Time of Update: 2018-08-04
今天我們來講講自訂群組件和它的建構函式。在前面的文章裡我們已經接觸了好幾個自定組件,這次的樣本是一個自訂對話方塊,他有一個about按鈕,點擊按鈕可以顯示出Qt的資訊或者使用者輸入的資訊。這是:下面我們就來重點講解自訂群組件和它的建構函式吧。建構函式的聲明先上代碼:type MyDialog struct { widgets.QDialog _ func() `constructor:"init"` _ func(string) `signal:
Time of Update: 2018-08-03
go環境配置建立目錄~/.go_env/go~/.go_env/gopath下載go的10+版本到"~/.go_env/go"在.profile中添加如下代碼export GOROOT=$HOME/.go_env/goexport GOPATH=$HOME/.go_env/gopathexport PATH=$GOROOT/bin:$GOPATH/bin:$PATHvscode dev
Time of Update: 2018-08-08
4.7.1 首碼和尾碼HasPrefix 判斷字串 s 是否以 prefix 開頭:strings.HasPrefix(s, prefix string) boolHasSuffix 判斷字串 s 是否以 suffix 結尾:strings.HasSuffix(s, suffix string) boolpackage mainimport ("fmt""strings")func main() {var str string = "This is an
Time of Update: 2018-08-08
1. 下載protoc可以去https://github.com/google/protobuf/releases下載源碼自己編譯或者https://github.com/google/protobuf/releases去下載編譯好的二進位檔案2. 安裝protoc-gen-gogo get github.com/golang/protobuf/protoc-gen-go安裝好了之後, 在$GOPATH/bin下面會找到protoc-gen-go.exe3. 使用protoc.exe 和
Time of Update: 2018-08-02
螢幕快照 2018-08-02 下午5.50.18.png例如上面這個小表徵圖,github上的工程build後,會顯示編譯後的狀態,通過還是編譯失敗。我們來看看markdown的代碼:【!【Build
Time of Update: 2018-08-02
package mainimport("fmt")type Node struct {Key stringVal stringPre *NodeNext *Node}type DLinkedList struct {Head *NodeTail *Node}func (self *DLinkedList) IsEmpty() bool {if self.Head == nil && self.Tail == nil {return true} else