摘要:
Array(数组) 数组是同一种数据类型元素的集合。 在Go语言中,数组从声明时就确定,使用时可以修改数组成员,但是数组大小不可变化。 基本语法: // 定义一个长度为3元素类型为int的数组a var a [3]int 数组定义: var 数组变量名 [元素数量]T 比如:var a [5]int 阅读全文
posted @ 2021-01-22 17:27
pebblecome
阅读(71)
评论(0)
推荐(0)
摘要:
变量 var 变量名 类型 = 表达式 var name string = "Q1mi" var age int = 18 #匿名变量 func foo() (int, string) { return 10, "Q1mi" } func main() { x, _ := foo() _, y := 阅读全文
posted @ 2021-01-22 17:24
pebblecome
阅读(71)
评论(0)
推荐(0)
摘要:
目录列表 安装gin框架 go get github.com/gin-gonic/gin 路由包 package routers import ( "github.com/gin-gonic/gin" "lesson26/bubble/controller" ) func SetupRouter() 阅读全文
posted @ 2021-01-22 17:02
pebblecome
阅读(95)
评论(0)
推荐(0)
摘要:
客户端client package main import ( "bufio" "fmt" "net" "os" "strings" ) //客户端 func main() { conn,err := net.Dial("tcp","127.0.0.1:20000") if err !=nil{ f 阅读全文
posted @ 2021-01-22 16:52
pebblecome
阅读(74)
评论(0)
推荐(0)
摘要:
安装 go get github.com/go-sql-driver/mysql 代码示例 package main import ( "context" "database/sql" "fmt" _ "github.com/go-sql-driver/mysql" "log" "strconv" 阅读全文
posted @ 2021-01-22 13:05
pebblecome
阅读(176)
评论(0)
推荐(0)
摘要:
代码示例 package main import ( "fmt" "log" "net/http" "time" ) func setCookie(w http.ResponseWriter,r *http.Request) { expiration := time.Now().Add(time.H 阅读全文
posted @ 2021-01-22 12:58
pebblecome
阅读(130)
评论(0)
推荐(0)
摘要:
代码示例 package main import ( "bufio" "fmt" "os" "strings" "sync" ) //使用锁实现一个队列 type SliceQueue struct { data []interface{} mu sync.Mutex } func NewSlice 阅读全文
posted @ 2021-01-22 12:57
pebblecome
阅读(247)
评论(0)
推荐(0)
摘要:
编号1,2,3,4 的goroutine 每秒顺序打印 1,2,3,4 的编号 package main import ( "fmt" "time" ) //编号1,2,3,4 的goroutine 每秒顺序打印 1,2,3,4 的编号 type Token struct { } func work 阅读全文
posted @ 2021-01-22 12:55
pebblecome
阅读(118)
评论(0)
推荐(0)
摘要:
代码示例 package main import ( "bufio" "fmt" "math/rand" "os" "strings" "time" ) //使用channel简单实现消息队列 //1 func main() { ch := make(chan string,1) rand.Seed 阅读全文
posted @ 2021-01-22 12:53
pebblecome
阅读(800)
评论(0)
推荐(0)
摘要:
互斥锁 package main import ( "fmt" "sync" "time" ) //使用互斥锁计算时间 var( mu sync.Mutex x int64 wg sync.WaitGroup ) func write() { defer wg.Done() mu.Lock() x 阅读全文
posted @ 2021-01-22 12:51
pebblecome
阅读(108)
评论(0)
推荐(0)

浙公网安备 33010602011771号