
Golang
文章平均质量分 74
熊先生的博客
这个作者很懒,什么都没留下…
展开
-
golang时间解析问题
time.Parse() 不会使用系统本地时区解析指定时区解析时间字符串为Time,需要使用: time.ParseInLocation() timeZone, _ := time.LoadLocation("Asia/Shanghai") timeObj_1, _ := time.Parse("2006-01-02 15:04:05", "2020-12-01 00:00:00") fmt.Println("timeObj_1" , timeObj_1.Unix()) timeObj_2 ,原创 2020-12-23 15:51:19 · 1011 阅读 · 0 评论 -
Golang 获取时间年月日
获取数值的格式的年月日package mainimport ( "fmt" "time")func main() { month := time.Unix(1557042972, 0).Format("1") fmt.Println(month) year := time.Now().Format("2006") month = time.Now().Format("01") day := time.Now().Format("02") fmt.Println(year).原创 2020-10-28 16:33:44 · 5003 阅读 · 0 评论 -
Golang使用flag包获取传入的参数
package mainimport ( "flag" "fmt" )func main() { var name string var age int64 flag.StringVar(&name,"name","default","log in user") flag.Int64Var(&age, "age", 16, "help message for flagname") // 必须有这一行 flag.Parse() fmt.Println( ref原创 2020-09-27 18:29:06 · 2249 阅读 · 0 评论 -
一个说明golang map传引用的例子
array打印结果可知item传的是引用func main() { item := make( map[string]interface{} ) var array [3]interface{} item["key"] = 2 var i int item["key"] = 1 array[i] = item for i=0; i<3; i++ { item["key"] = i+10 fmt.Println(item) array[i] = item } fmt.P原创 2020-09-24 20:28:57 · 726 阅读 · 0 评论 -
Golang Mongo BulkWrite upsert 用法示例
文档地址: https://godoc.org/go.mongodb.org/mongo-driver/mongo#example-Collection-BulkWritepackage mainimport ( "fmt" "go.mongodb.org/mongo-driver/bson" "go.mongodb.org/mongo-driver/mongo/options" "context" "time")import mog "go.mongodb.org/mongo-dr原创 2020-09-24 18:33:03 · 2836 阅读 · 0 评论 -
Golang 实现sha256 加密
先贴出PHP代码:$string = "1234";$key = "abcd";$signature = hash_hmac('sha256', $string, $key);然后是Golang:package mainimport ( "crypto/hmac" "crypto/sha256" "encoding/hex" "fmt")func main() { ...原创 2019-08-18 16:50:18 · 4382 阅读 · 0 评论