摘要:Go语言的值类型和引用类型一、值类型和引用类型区别说明1、值类型:int系列、float系列、bool、string、数组和结构体2、引用类型:指针、slice切片、map、管道chan、interface接口等 二、使用特点1、值类型:直接储存值,栈分配,拷贝直接拷贝所有的值,损伤性能2、引用类型
阅读全文
摘要:1 package main 2 3 import ( 4 "fmt" 5 "io/ioutil" 6 "log" 7 ) 8 9 func listFiles(dirname string, level int) { 10 // level用来记录当前递归的层次,生成带有层次感的空格 11 s :
阅读全文
摘要:1 package main 2 3 import ( 4 "fmt" 5 "io/ioutil" 6 "os" 7 ) 8 9 func main() { 10 /* 11 ioutil包: 12 ReadFile() 13 WriteFile() 14 ReadDir() 15 .. 16 */
阅读全文
摘要:1 package main 2 3 import ( 4 "bufio" 5 "fmt" 6 "os" 7 ) 8 9 func main() { 10 /* 11 bufio:高效io读写 12 buffer缓存 13 io:input/output 14 15 将io包下的Reader,Wri
阅读全文
摘要:1 package main 2 3 import ( 4 "bufio" 5 "fmt" 6 "os" 7 ) 8 9 func main() { 10 /* 11 bufio:高效io读写 12 buffer缓存 13 io:input/output 14 15 将io包下的Reader,Wri
阅读全文
摘要:1 package main 2 3 import ( 4 "fmt" 5 "io" 6 "log" 7 "os" 8 "strconv" 9 "strings" 10 ) 11 12 func HandleErr(err error) { 13 if err != nil { 14 log.Fat
阅读全文
摘要:1 package main 2 3 import ( 4 "fmt" 5 "io" 6 "log" 7 "os" 8 ) 9 10 func main() { 11 /* 12 Seek(offset int64, whence int) (int64, error),设置指针光标的位置 13 第
阅读全文
摘要:1 package main 2 3 import ( 4 "fmt" 5 "io" 6 "io/ioutil" 7 "os" 8 ) 9 10 // 该函数:用于通过io操作实现文件的拷贝,返回值是拷贝的总数量(字节),错误 11 func CopyFile1(srcFile, destFile
阅读全文
摘要:1 package main 2 3 import ( 4 "fmt" 5 "log" 6 "os" 7 ) 8 9 func HandleErr(err error) { 10 if err != nil { 11 log.Fatal(err) 12 } 13 } 14 15 func main(
阅读全文
摘要:1 package main 2 3 import ( 4 "fmt" 5 "io" 6 "os" 7 ) 8 9 func main() { 10 /* 11 读取数据: 12 Reader接口: 13 Read(p []byte)(n int, error) 14 */ 15 16 // ste
阅读全文
摘要:1 package main 2 3 import ( 4 "fmt" 5 "os" 6 "path/filepath" 7 ) 8 9 func main() { 10 /* 11 文件操作: 12 1.路径: 13 相对路径:relative 14 ab.txt 15 相对于当前工程 16 绝对
阅读全文
摘要:1 package main 2 3 import ( 4 "fmt" 5 "os" 6 ) 7 8 func main() { 9 /* 10 FileInfo:文件信息 11 interface 12 Name(),文件名 13 Size(),文件大小,字节为单位 14 IsDir(),是否是目
阅读全文
摘要:1 package main 2 3 import "fmt" 4 5 func myprint(s string) { 6 fmt.Println(s) 7 } 8 9 func funA() { 10 fmt.Println("我是一个函数funA()....") 11 } 12 13 func
阅读全文
摘要:1 package main 2 3 import "fmt" 4 5 type areaError struct { 6 msg string // 错误的描述 7 lenght float64 // 发生错误的时候,矩形的长度 8 width float64 // 发生错误的时候,矩形的宽度 9
阅读全文
摘要:1 package main 2 3 import ( 4 "fmt" 5 "math" 6 ) 7 8 //1.定义一个结构体,表示错误的类型 9 type areaError struct { 10 msg string 11 radius float64 12 } 13 14 // 2.实现e
阅读全文
摘要:1 package main 2 3 import ( 4 "fmt" 5 "net" 6 ) 7 8 func main() { 9 addr, err := net.LookupHost("www.baidu.com") 10 fmt.Println(err) 11 if ins, ok :=
阅读全文
摘要:1 package main 2 3 import ( 4 "errors" 5 "fmt" 6 ) 7 8 // 设计一个函数:验证年龄是否合法,如果为负数,就返回一个error 9 func checkAge(age int) error { 10 if age < 0 { 11 //返回err
阅读全文
摘要:1 package main 2 3 import ( 4 "fmt" 5 "os" 6 ) 7 8 func main() { 9 f, err := os.Open("test.txt") 10 if err != nil { 11 //log.Fatal(err) 12 fmt.Println
阅读全文
摘要:1 package main 2 3 import "fmt" 4 5 type Person struct { 6 name string 7 } 8 9 func (p Person) show() { 10 fmt.Println("Person >", p.name) 11 } 12 13
阅读全文
摘要:1 package main 2 3 import ( 4 "fmt" 5 "strconv" 6 ) 7 8 // 1.定义一个新的类型 9 type myint int 10 type mystr string 11 12 // 2.定义函数类型 13 type myfun func(int,
阅读全文