mirror of
https://github.com/unknwon/the-way-to-go_ZH_CN.git
synced 2025-11-13 09:16:10 +08:00
12.9md (#349)
* Update 11.9.md 修正166行一个错误,ix 改为i * Update 11.14.md 34-43行代码错误,会造成无法运行 * 修改一处权限bug,否则会造成linux下生成的文件为空
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -6,6 +6,7 @@
|
|||||||
# Folders
|
# Folders
|
||||||
_obj
|
_obj
|
||||||
_test
|
_test
|
||||||
|
.idea
|
||||||
|
|
||||||
# Architecture specific extensions/prefixes
|
# Architecture specific extensions/prefixes
|
||||||
*.[568vq]
|
*.[568vq]
|
||||||
|
|||||||
@@ -36,9 +36,9 @@ func (cs Cars) FindAll(f func(car *Car) bool) Cars {
|
|||||||
cars := make([]*Car, 0)
|
cars := make([]*Car, 0)
|
||||||
cs.Process(func(c *Car) {
|
cs.Process(func(c *Car) {
|
||||||
if f(c) {
|
if f(c) {
|
||||||
append(cars,c)
|
cars = append(cars, c)
|
||||||
}
|
}
|
||||||
)
|
})
|
||||||
return cars
|
return cars
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|||||||
@@ -163,8 +163,8 @@ var interfaceSlice []interface{} = dataSlice
|
|||||||
```go
|
```go
|
||||||
var dataSlice []myType = FuncReturnSlice()
|
var dataSlice []myType = FuncReturnSlice()
|
||||||
var interfaceSlice []interface{} = make([]interface{}, len(dataSlice))
|
var interfaceSlice []interface{} = make([]interface{}, len(dataSlice))
|
||||||
for ix, d := range dataSlice {
|
for i, d := range dataSlice {
|
||||||
interfaceSlice[ix] = d
|
interfaceSlice[i] = d
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|||||||
@@ -69,7 +69,7 @@ func main() {
|
|||||||
js, _ := json.Marshal(vc)
|
js, _ := json.Marshal(vc)
|
||||||
fmt.Printf("JSON format: %s", js)
|
fmt.Printf("JSON format: %s", js)
|
||||||
// using an encoder:
|
// using an encoder:
|
||||||
file, _ := os.OpenFile("vcard.json", os.O_CREATE|os.O_WRONLY, 0)
|
file, _ := os.OpenFile("vcard.json", os.O_CREATE|os.O_WRONLY, 0666)
|
||||||
defer file.Close()
|
defer file.Close()
|
||||||
enc := json.NewEncoder(file)
|
enc := json.NewEncoder(file)
|
||||||
err := enc.Encode(vc)
|
err := enc.Encode(vc)
|
||||||
|
|||||||
Reference in New Issue
Block a user