随笔分类 -  Golang

摘要:最近日志打印的时候需要打印状态码,但是因为interface的原因直接获取失败,http.Request里面的response不知道怎么使用,所以就自己重写writeheader,write来截取status type doneWriter struct { http.ResponseWriter 阅读全文
posted @ 2018-12-14 11:17 赵客缦胡缨-Nicholas 阅读(2179) 评论(0) 推荐(0) 编辑
摘要:accounts := []users.Account{}Admin.DB.Preload("CurrencyObj").Where("member_id = ?", record.(*users.Member).ID).Find(&accounts)sort.Slice(accounts, fun 阅读全文
posted @ 2018-06-06 11:02 赵客缦胡缨-Nicholas 阅读(2590) 评论(2) 推荐(0) 编辑
摘要:背景: golang的interface是一种satisfied式的。A类只要实现了IA interface定义的方法,A就satisfied了接口IA。更抽象一层,如果某些设计上需要一些更抽象的共性,比如print各类型,这时需要使用reflect机制,reflect实质上就是将interface 阅读全文
posted @ 2017-12-15 09:47 赵客缦胡缨-Nicholas 阅读(297) 评论(0) 推荐(0) 编辑
摘要:package main import ( "encoding/json" "flag" "fmt" "log" "net/http" "time" "config" "framework/logger" "global" "models/function" "models/schema" "git 阅读全文
posted @ 2017-12-08 09:12 赵客缦胡缨-Nicholas 阅读(574) 评论(0) 推荐(0) 编辑
摘要:func AndLevel(resource []Resource, parentid int64, level int) []Trees { //递归调用当所有的循环没有完成的时候是没有进行child的存值操作 var len = 0 var x = 0 //这里是为了计算我存储数据的slice的长度 for _, v := range resource... 阅读全文
posted @ 2017-10-11 14:58 赵客缦胡缨-Nicholas 阅读(215) 评论(0) 推荐(0) 编辑
摘要://随机数生成要用到的 const letterBytes = "1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" const ( letterIdxBits = 6 letterIdxMask = 1= 0; { if remain == 0 { cache, remain ... 阅读全文
posted @ 2017-09-11 16:12 赵客缦胡缨-Nicholas 阅读(851) 评论(0) 推荐(0) 编辑
摘要:package mainimport ( "fmt")func main() { f := fibonacci() for i := 0; i < 10; i++ { fmt.Printf("%d:%d\n", i, f()) }}// func fibonaci(n int) (ret int) 阅读全文
posted @ 2017-06-21 17:22 赵客缦胡缨-Nicholas 阅读(501) 评论(0) 推荐(0) 编辑
摘要:在使用golang的模板语法的过程中遇见自动转义问题(或者以我的理解下发的富文本html代码不是template.html类型,而是string类型),需要强制转型 func unescaped(x string) interfacef{}{ t:=template.New("") t=t.Func 阅读全文
posted @ 2017-06-14 10:48 赵客缦胡缨-Nicholas 阅读(1421) 评论(0) 推荐(0) 编辑
摘要:package mainimport ( //"encoding/json" "fmt" //"os" //"io/ioutil" "github.com/nfnt/resize" "image/jpeg" "io" "log" "os" "path/filepath" "strconv" // " 阅读全文
posted @ 2017-05-31 17:32 赵客缦胡缨-Nicholas 阅读(1099) 评论(0) 推荐(0) 编辑
摘要:今天摸索了下 HTTPS 的证书生成,以及它在 Nginx 上的部署。由于博客托管在 github 上,没办法部署证书,先记录下,后续有需要方便快捷操作。本文的阐述不一定完善,但是可以让一个初学者了解大致的原理,同时跟着操作可以为自己的博客/网站部署一个 HTTPS 证书。 网站部署 HTTPS 的 阅读全文
posted @ 2017-05-14 15:23 赵客缦胡缨-Nicholas 阅读(639) 评论(0) 推荐(0) 编辑
摘要:最近要做后台主动推送:(iris框架,封装的有wesocket,刚开始以为直接拿过来用,结果不是现在贴一下代码,写一下遇到的坑) func main() { app := iris.New() app.Adapt(iris.DevLogger()) app.Adapt(httprouter.New( 阅读全文
posted @ 2017-05-13 20:47 赵客缦胡缨-Nicholas 阅读(5357) 评论(2) 推荐(0) 编辑

点击右上角即可分享
微信分享提示