Go语言中文网 为您找到相关结果 9

用go语言遍历文件夹

用python遍历文件夹很方便,在go的世界里,我也需要这样的功能。找了找文档,里面有这个功能(具体参考这里:http://golang.org/pkg/path/filepath/ )…… 好,不废话了,我也想早点睡,直接上代码。 代码如下: /* File : getFilelist.go Author : Mike E-Mail : Mike_Zhang@live.com */ package main import ( "path/filepath" "os" "fmt" "flag" ) func getFilelist(path string) { err := filepath.Walk(path, func(path string, f os.FileInfo, err er...阅读全文

博文 2014-10-04 19:26:20 MikeZhang

Go里面的唯一ID

Unique IDs in Golang: [part1](http://antoniomo.com/blog/2017/05/21/unique-ids-in-golang-part-1/) [part2](http://antoniomo.com/blog/2017/05/28/unique-ids-in-golang-part-2/) [part3](http://antoniomo.com/blog/2017/06/03/unique-ids-in-golang-part-3/...阅读全文

资源 2017-06-04 04:45:32 polaris

golang consistent hash 菜鸟分析

一直找集群的算法,刚好golang上面有一个适合。下面作为菜鸟来分析一下 // Copyright (C) 2012 Numerotron Inc. // Use of this source code is governed by an MIT-style license // that can be found in the LICENSE file. // Package consistent provides a consistent hashing function. // // Consistent hashing is often used to distribute requests to a changing set of servers. For example, // ...阅读全文

博文 2014-10-04 19:26:07 laohan_

golang中的defer panic recover

大家都知道golang里的panic相当于其他语言里的throw,而recover相当于其他语言里的cacth,可是由于golang的recover机制要求必须在defer的函数里才能执行catch panic 大概意思如下 func protect(g func()) { defer func() { log.Println("done") // Println executes normally even if there is a panic if x := recover(); x != nil { log.Printf("run time panic: %v", x) } }() log.Println("start") g() } 这似乎跟try catch没啥区别,但是如果我们...阅读全文

博文 2014-10-04 19:26:12 HopingWhite

安装Go时出现错误 File: client_test.go 的解决方案

gopack grc _test/http.a _gotest_.6--- FAIL: http.TestClientGet http://www.google.com/robots.txt: read tcp:192.168.1.2:49664->64.233.189.103:80: connection reset by peerFAILmake[1]: *** [test] Error 1make: *** [http.test] Error 2 这个问题我个人认为可能和中国网络环境有关, 由于Go在编译了每一个包后都要做一个测试, 而选择的服务器都是美国的服务器. 解决这个问题的方法很解决, 将测试条件改成国内的就可以了. 文件位置在$GOROOT/src/pkg/http. 也就这...阅读全文

博文 2014-10-04 19:26:26 屈能荣

Ubuntu下安装go语言

Go语言是Google开发的一个开源项目,目的之一是为了提高开发人员的编程效率。Go语言语法灵活,简洁,清晰,高效。它的并发特性可以方便的用于多核处理器和网络开发,同时灵活新颖的类型系统可以方便的编写模块化的系统。go可以快速编译,同时具有垃圾内存自动回收功能,并且还支持运行时反射。go十一个高效、静态类型,但是邮局有解释语言的动态类型特征的系统级语法。 由于只介绍Ubuntu下386的go语言安装方法,其他平台的可以到http://code.google.com/p/golang-china/上查看 1、安装Go语言工具 sudo apt-get install bison ed gawk gcc libc6-dev make 如果上面有那个安装不上的可能会导致后面的也无法安装,用户也可以...阅读全文

博文 2014-10-04 19:26:26 loulijun

go interface理解

如果一只鸟长得像鸭子,走起路来像鸭子,叫起来也像鸭子,那么就把这只鸟叫做鸭子; golang中的interface就是上面这个意思,如果你定义了一个struct,它里面的方法和属性都和interface中的一样,那么可以说,这个struct实现这个interface,上代码 package main import ( "fmt" ) type s struct { //定义一个s类型,有一个属性i是int的 i int } func (this *s) Get() int { //Get方法获得i属性 return this.i } func (this *s) Put(v int) { //Put方法设置i属性 this.i = v } type I interface { //定义一个接...阅读全文

博文 2014-10-04 19:26:35 别人说我名字很长