This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if err != nil { | |
fmt.Printf("Program stopping with error %v", err) | |
os.Exit(1) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if err := file.Chmod(0664); err != nil { | |
fmt.Println(err) | |
return err | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if value, ok := readData(); ok { | |
… | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
switch var1 { | |
case val1: | |
... | |
case val2: | |
... | |
default: | |
... | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
switch { | |
case condition1: | |
... | |
case condition2: | |
... | |
default: | |
... | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
switch initialization { | |
case val1: | |
... | |
case val2: | |
... | |
default: | |
... | |
} | |
switch result := calculate(); { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
switch i { | |
case 0: // 空分支,只有当 i == 0 时才会进入分支 | |
case 1: | |
f() // 当 i == 0 时函数不会被调用 | |
} | |
switch i { | |
case 0: fallthrough | |
case 1: | |
f() // 当 i == 0 时函数也会被调用 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// for 初始化语句; 条件语句; 修饰语句 {} | |
for i := 0; i < 5; i++ { | |
fmt.Printf("This is the %d iteration\n", i) | |
} | |
/* | |
初始化语句 | |
for 条件语句 { | |
修饰语句 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
for ix, val := range coll { } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//6.3 传递变长参数 | |
func typecheck(..,..,values … interface{}) { | |
for _, value := range values { | |
switch v := value.(type) { | |
case int: … | |
case float: … | |
case string: … | |
case bool: … | |
default: … | |
} |
OlderNewer