加载中
GO 类型断言

package main import( "fmt" ) type Usb interface { Start() Stop() } type Phone struct{ } func (p Phone) Start() { fmt.Println("手机开始工作") } func (p Phone) Stop() { fmt.Printl...

07/31 18:13
7
闭包小案列

//闭包 保护了n 变量不会每次初始化; func testClosure() func(int) int { var n int = 10 return func(x int) int { n = x + n return n } } func makeSuffix(suffix string) func (name s...

F2
07/28 17:06
2
go包 相关说明

目录结构 src ----db -------db.go ----utils ------p1.go ----main.go main.go package main import(   "fmt"   "packageDemo/db" //从环境变量 GOPAHT src目录底下起(不包括src目录)   ut "pa...

07/28 10:39
0
GO redis 相关操作

在gopath 目录下安装 go get github.com/garyburd/redigo/redis package main import ( "fmt" "github.com/garyburd/redigo/redis" ) //定义一个全局链接池变量 var pool *redis.Pool //在m...

2018/12/18 20:15
24
GO 文件相关操作

package main import( "fmt" "os" "bufio" "io" "io/ioutil" ) type ChartCount struct{ Chct int Spacect int Numberct int Otherct int } func main() { file,err := os.Open("./test.txt"...

Go
2018/11/15 11:01
7
GO接口

package main import ( "fmt" "sort" "math/rand" ) //接口不能包含变量,不能有方法的实现 type Usb interface{ Start() Stop() } //Phone实现Usb接口 type Phone struct{ } func (p Phone) ...

2018/10/30 20:49
10
GO结构体

package main import ( "fmt" "encoding/json" ) type Point struct { x,y int } type Rect struct { leftUp,righDown Point } type A struct { Name string } type B struct { Name string ...

2018/10/08 14:41
9
GO map相关操作

package main import ( "fmt" "sort" ) type Stu struct{ Name string Age int Address string } func main() { var m map[string]string m = make(map[string]string, 10) m["a"] = "wangwu...

Go
2018/09/25 17:48
8
GO冒泡,二分查找

package main import( "fmt" ) func main() { var arr [5]int = [5]int{11,13,9,2,25} maopao(&arr) fmt.Println("arr = ", arr) //[2 9 11 13 25] findIndex := binaryFind(&arr, 0, len(ar...

Go
2018/09/20 22:04
8
GO 切片(slice)相关语法

package main import( "fmt" ) func main() { var intArr [5]int = [...]int{1,2,3,4,5} //定义一个数组 slice := intArr[2:4] //第二个(包含)下标到第四个下标(不包含) fmt.Println("slice ...

Go
2018/09/19 22:35
36
GO 数组相关操作

package main import( "fmt" "math/rand" "time" ) func main() { //数组的几种定义方式 var arr1 [3]int = [3]int{1,2,3} var arr2 = [3]int{4,5,6} arr3 := [3]string{"h", "w", "z"} var ...

Go
2018/09/18 22:49
183
GO错误的一些处理(defer,recover,panic)

package main import( "fmt" "errors" ) func main() { num := 10 fmt.Printf("num的类型%T, num的值%v, num的地址%v\n", num, num, &num) num2 := new(int) //返回一个指针 //num2的类型*in...

Go
2018/09/18 20:49
22
GO 时间相关函数

package main import( "fmt" "time" ) func main () { now := time.Now(); fmt.Printf("now=%v, now type %T\n", now, now) fmt.Println("年=",now.Year()); fmt.Println("月=",now.Month())...

2018/09/18 18:54
4
GO字符串相关函数

package main import ( "fmt" "strings" "strconv" ) func main () { str := "hello老美" //中文占三个字节 fmt.Println("str的长度为len=", len(str)) //长度为11 for i := 0; i < len(s...

Go
2018/09/18 17:50
2
go基本语法

package main import( "fmt" "strings" "project04/utils" //这个引入包,从环境变量GOPATH或者GOROOT起需要一个src目录; ) type myfunc func(int, int) int //自定义类型myfunc //全局匿名函...

Go
2018/09/18 10:53
13

没有更多内容

加载失败,请刷新页面

没有更多内容

返回顶部
顶部