摘要:
生成json格式字符 使用结构体生成 package main import ( "encoding/json" "fmt" ) //用于json的结构体类型成员首字母必须大写 // type Jon struct { // Name string // Subject []string // Sc 阅读全文
posted @ 2021-02-28 19:35
GPHPER
阅读(163)
评论(0)
推荐(0)
摘要:
字符串操作 package main import ( "fmt" "strings" ) func main() { str := "hello world" //contains 是否包含指定字符串 fmt.Println(strings.Contains(str, "hello")) //Ji 阅读全文
posted @ 2021-02-28 16:34
GPHPER
阅读(157)
评论(0)
推荐(0)
摘要:
自定义异常的两种方式 package main import ( "errors" "fmt" ) func main() { //使用fmt.Errorf err1 := fmt.Errorf("%s", "this is normal error") fmt.Println(err1) //使用 阅读全文
posted @ 2021-02-28 16:14
GPHPER
阅读(103)
评论(0)
推荐(0)
摘要:
接口 定义及使用 package main import ( "fmt" ) //定义一个接口 type Human interface { sayHello() } type Student struct { name string age int } type Teacher struct { 阅读全文
posted @ 2021-02-28 15:33
GPHPER
阅读(144)
评论(0)
推荐(0)
摘要:
继承 匿名字段(可以是任意类型) package main import ( "fmt" ) type Person struct { id int username string sex byte } type Student struct { Person //匿名字段继承了Person的成员 阅读全文
posted @ 2021-02-28 11:49
GPHPER
阅读(121)
评论(0)
推荐(0)
摘要:
定义 type 变量名 struct{ 元素1名称 元素1类型 元素2名称 元素2类型 } package main import ( "fmt" ) type student struct { id int name string age int addr string } func main() 阅读全文
posted @ 2021-02-28 10:54
GPHPER
阅读(164)
评论(0)
推荐(0)
摘要:
map数据类型 形式如 map[keyType]valueType 类型的数据 定义 //直接定义 m2 := map[int]string{1: "hello", 2: "world"} fmt.Println("m2 = ", m2) //使用make函数定义 m1 := make(map[in 阅读全文
posted @ 2021-02-28 10:17
GPHPER
阅读(286)
评论(0)
推荐(0)