gobyexample-cn / gobyexample Goto Github PK
View Code? Open in Web Editor NEWGo by Example 通过例子学 Golang
Home Page: https://gobyexample-cn.github.io/
License: Other
Go by Example 通过例子学 Golang
Home Page: https://gobyexample-cn.github.io/
License: Other
This is not a issue!
I just want to say that we have an easier way to implement sorting-by-functions like this:
import (
"fmt"
"sort"
)
func main() {
fruits := []string{"peach", "banana", "kiwi"}
sort.Slice(fruits, func(i, j int) bool {
return len(fruits[i]) < len(fruits[j])
})
fmt.Println(fruits)
}
RT
使用这个 select 超时方式,需要使用通道传递结果。这对于一班情况是个好的方式,因为其他重要的 Go 特性是基于通道和select 的。接下来我们就要看到两个例子:timer 和 ticker。
这段在go文件里木有
Thank you for the translation, they are so great!
When I build it locally, I come to the following file missing error, while the file is actually at that certain place. I noticed the code to call this file is the same, which is tools/generate.go, with English version, and I could compile correctly in original English version, so I'm not so sure where this problem come from.
panic: exec: "./vendor/pygments/pygmentize": file does not exist
goroutine 1 [running]:
main.check(...)
C:/somepath/gobyexample/tools/generate.go:32
main.pipe(0x7c1fa5, 0x1c, 0xc000079c90, 0x4, 0x4, 0xc00023c07b, 0xc, 0x7b8c03, 0x1, 0xc00020a510)
C:/somepath/gobyexample/tools/generate.go:55 +0x300
main.cachedPygmentize(0x7b8d14, 0x2, 0xc00023c07b, 0xc, 0xc000248100, 0x7b)
C:/somepath/gobyexample/tools/generate.go:88 +0x2cb
main.parseAndRenderSegs(0xc00022e100, 0x19, 0x5, 0x0, 0x4, 0x0, 0x0)
C:/somepath/gobyexample/tools/generate.go:225 +0x13f
main.parseExamples(0x7c01cb, 0x17, 0xc0000106c0)
C:/somepath/gobyexample/tools/generate.go:271 +0x918
main.main()
C:/somepath/gobyexample/tools/generate.go:334 +0x303
exit status 2
System: Windows10 Pro
Bash: Git Bash
问题描述:
执行"临时文件和目录"代码时,会存在这样的error:The process cannot access the file because it is being used by another process.
首先代码如网站描述:
func check(e error) {
if e != nil {
panic(e)
}
}
func main() {
f, err := os.CreateTemp("", "sample")
check(err)
fmt.Println("Temp file name:", f.Name())
defer os.Remove(f.Name())
_, err = f.Write([]byte{1, 2, 3, 4})
check(err)
}
在这个过程中并不能删掉所创建的临时文件,因为此时*File
未关闭(造成存在一个process 正在访问file),导致os.Remove()
无法访问,进行删除。
故应该修改为:
func check(e error) {
if e != nil {
panic(e)
}
}
func main() {
f, err := os.CreateTemp("", "sample")
check(err)
fmt.Println("Temp file name:", f.Name())
defer os.Remove(f.Name())
defer f.Close()
_, err = f.Write([]byte{1, 2, 3, 4})
check(err)
}
When the transfer done, we need send a pull request to update Chinese translation descriptions in upstream and fix mmcgrana/gobyexample#173.
Commits on Apr 19, 2015 to Commits on Jan 6, 2016
我把代码直接贴上去运行 结果跟网页上的结果不一致
新人学习 求解析
Variable "opsFinal" is obsolete.
感谢提供中文版翻译!
服务器的访问时常有些问题,点击每个例子的页面有时并不会进入页面,而是弹出下载框,会不会是web服务器response没有设置好呢?
闭包那边可以引用Closures in Go来补充,使得更好的理解。
系统win10,使用 go get github.com/russross/blackfriday
构建项目,目录下没有 tools
文件夹。
建议修改readme,做相应说明。
https://books.studygolang.com/gobyexample/slices/
This slices up to (but excluding) s[5].
网页端错误翻译:这个 slice 从 s[0] 到(但是**### 包含**)s[5]。
正确翻译:这个 slice 从 s[0] 到(但是排除)s[5]。
感谢
Page https://gobyexample.com/mutexes is Updated on Fri, 09 Feb 2018.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.