随笔分类 - Golang
摘要:服务端实现 package main import ( "encoding/json" "fmt" "log" "net/http" "golang.org/x/net/websocket" ) func add(ws *websocket.Conn) { msg := make([]byte, 5
阅读全文
摘要:Sprintf 四舍六入: value, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", 9.824), 64) fmt.Println(value) //9.82 value, _ = strconv.ParseFloat(fmt.Sprintf("%.2f
阅读全文
摘要:1.服务启动: Windows: 1.在window的环境变量中path加入: E:\nsq-1.0.0-compat.windows-amd64.go1.8\bin 2.打开命令窗口,运行: nsqlookupd 3.打开新的命令窗口,运行: nsqd --broadcast-address=12
阅读全文
摘要:** 1.Type(expression): ** int(time.Now().Weekday()) //星期转int int(time.Now().Month()) //月份转int var a float64 a = 3.1 b := int(a) //float64转int var a in
阅读全文
摘要:下载cron包: go get github.com/robfig/cron 开启一个定时: 根据cron表达式进行时间调度,cron可以精确到秒,大部分表达式格式也是从秒开始。 c := cron.New()默认从分开始,所以加上cron.WithSeconds(),保证定时按照表达式字面意思执行
阅读全文
摘要:Gorm连接MySQL: import ( _ "github.com/go-sql-driver/mysql" "github.com/jinzhu/gorm" ) type User struct { Id int `json:"id"` Name string `json:"name"` Ag
阅读全文
摘要:冒泡排序: 时间复杂度:O(n^2) 稳定性:稳定 //冒泡排序 //相邻两位交换,12交换,23交换,34交换,把最大的数放到最右边 //利用flag标记可以避免无效循环 func BubbleSort(arr []int) { length := len(arr) //length是最后一位,i
阅读全文
摘要:使用gopath的时候,一般引用是从src下一层开始,比如src/github.com/…,引用github.com…,我的工程src/xxx.com/go-qb/…,引用xxx.com/go-qb/… 使用mod的时候,github自动下载到gopath的pkg里,全名引用github.com…,
阅读全文
摘要:设置https访问: 原始代码为http监听: func main() { server := &http.Server{ Addr: ":8080", ... } go func() { if err := server.ListenAndServe(); err != nil && err !=
阅读全文
摘要:所列题目与牛客网《剑指offer》专题相对应。 数组: 和为S的两个数字 和为S的连续正数序列 连续子数组的最大和 数字在排序数组中出现的次数 数组中只出现一次的数字 旋转数组的最小数字 数组中的逆序对 最小的K个数 数组中出现次数超过一半的数字 把数组排成最小的数 数组中重复的数字 滑动窗口的最大
阅读全文

浙公网安备 33010602011771号