摘要:
在默认情况下,当发生错误后(panic),程序就会退出(崩溃)。 如果希望发生错误后程序还能继续运行就要做错误处理 使用defer+recover来捕捉和处理异常 go语言追求简洁优雅,所有go不支持传统的try、catch、finally这种处理 go中引入的方式是:defer、panic、rec 阅读全文
摘要:
package main import ( "fmt" "strconv" "time" ) func main() { // 获取当前时间 now := time.Now() fmt.Println(time.Now()) // 通过now获取年月日,分时秒 fmt.Printf("年:%v\n" 阅读全文
摘要:
package main import ( "fmt" "strconv" "strings" ) func main() { // 字符串长度 str := "hello北" fmt.Println("str len():", len(str)) // 带中文的字符串变量 str2 := "hel 阅读全文