![](https://img-blog.csdnimg.cn/20201014180756922.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
golang
robin912
赶路的时候,多停下来看看周围的风景;编码的时候,多停下来想想相关问题。
展开
-
golang http
golang httpgolang 解析 POST 中的数据POST 的数据放在 http.Request.Body 字段,可以用 json.Decoder 解析func test(rw http.ResponseWriter, req *http.Request) { decoder := json.NewDecoder(req.Body) var t tes...原创 2018-06-20 22:33:28 · 147 阅读 · 0 评论 -
golang在http消息交互时的 "[object undefined]"
golang在http消息交互时的 “[object undefined]”在使用golang作为微信开发的服务端时,遇到解析消息时字段为空的情况.这种情况下使用encoding/json解析会出现[object Undefined]字符串,而不是期望的空字符串. 自己写了一个工具函数解析此类情况:func GetHeadString(r *http.Request, key strin...原创 2018-07-10 10:26:17 · 1571 阅读 · 0 评论 -
golang jwt验证
安装 go get “github.com/dgrijalva/jwt-go”登陆// Create a new token object, specifying signing method and the claims// you would like it to contain.token := jwt.NewWithClaims(jwt.SigningMethodHS256...原创 2018-06-27 14:32:15 · 1767 阅读 · 0 评论 -
golang 中多个 defer 的执行顺序
golang 中多个 defer 的执行顺序引用 Ture Go 中的一个示例:package mainimport "fmt"func main() { fmt.Println("counting") for i := 0; i < 10; i++ { defer fmt.Println(i) } fmt.Printl...原创 2018-06-19 22:13:56 · 19794 阅读 · 0 评论 -
golang sql 的使用
golang sql 的使用使用 statement 增加数据使用db.Prepare获取一个 sql 执行模板,其中的?为需要输入的参数,之后通过stmt.Exec()添加参数。 Exec返回的Result可以获取 LastInsertId(),但是并不是所有数据库都支持;RowsAffected()能够获取修改数据的条数。stmt, err := db.Prepare("...原创 2018-06-19 21:50:41 · 1902 阅读 · 0 评论 -
golang 的 UUID 使用
golang 的 UUID 使用安装go get github.com/satori/go.uuid使用几种 UUID 的产生方式:Version 1, based on timestamp and MAC address (RFC 4122) Version 2, based on timestamp, MAC address and POSIX UID/GID (...原创 2018-06-19 21:39:12 · 12592 阅读 · 0 评论 -
golang excel 读取操作
golang excel 读取操作excel读取的几个步骤 - xlsx.OpenFile(filename) - for idx, sheet := range xlsFile.Sheets - for idxrow, row := range sheet.Rows - for idxcell, cell := range row.Cellspackage mainimpor...原创 2018-06-26 09:27:05 · 8372 阅读 · 1 评论 -
golang json处理
golang json处理在http json中使用其中json:"username"等字符,表示json字符串中对应的参数名称.type User struct { Username string `json:"username"` Password string `json:"password"` Nickname strin...原创 2018-06-26 09:25:37 · 426 阅读 · 0 评论 -
golang 结构体初始化时赋值格式
golang 结构体初始化时赋值格式:golang在给结构体赋值初始值时,用:分割k,v值 x := ItemLog{ Id: GetUuid(), ItemId: u.Id, UsrId: "123", Name: u.Name, Price: u.Price, ...原创 2018-06-21 20:15:15 · 10927 阅读 · 0 评论 -
golang 获取当前时间
golang time nowgolang 获取当前时间具体操作如下package mainimport ( "fmt" "time")func main() { t := time.Now() fmt.Println(t.Format("20060102150405")) fmt.Println(time.Now().Format(t...原创 2018-06-21 20:13:22 · 5336 阅读 · 0 评论 -
抛出 error 异常的方式
抛出 error 异常的方式一种方式是通过 error.New 产生异常。func Sqrt(f float64) (float64, error) { if f < 0 { return 0, errors.New("math: square root of negative number") } // implementation}...原创 2018-06-20 22:40:46 · 1023 阅读 · 0 评论 -
golang计算字符串长度
golang计算字符串长度计算字符串长度有两种情况,一种是 ascii 字符,另一种为本地编码 (如:utf8) 的字符。package mainimport "fmt"import "unicode/utf8"func main() { fmt.Println("Hello, 世界", len("世界"), utf8.RuneCountInString("世界"))}...原创 2018-06-20 22:37:41 · 9033 阅读 · 0 评论 -
golang 之反向代理
golang 之反向代理使用golang实现一个类似nginx的反向代理程序,处理react编译后的单页面部署.func middleware1(next http.Handler, proxy http.Handler) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Req...原创 2018-07-05 09:21:24 · 1200 阅读 · 0 评论