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