1, go comment have /* */
2. go function input must declare type
good: func myFun(addr string) { ... }
bad: func myFun(addr ) { ... }
3. go functin return error type is error
good: func myFun(addr string) (string, error) {
if err != nil {
return "", err
}
return "success", nil
}
4. go string connact can use plus
5. Go cmd parameter use os package
func main() {
if len(os.Args) != 3 {
fmt.Println("Usage:", os.Args[0], "PATTERN", "FILE")
return
}
pattern := os.Args[1]
file := os.Args[2]
// ...
}
沒有留言:
張貼留言