golang
tang05709
这个作者很懒,什么都没留下…
展开
-
gin 上传图片到阿里云oss
上传函数import ( "io" "Festival/app/common/cfg" "github.com/aliyun/aliyun-oss-go-sdk/oss")func OssUpload(key string, file io.Reader) (string, error) { ossCfg := cfg.Instance().Oss client, err := oss.New(ossCfg.Endpoint, ossCfg.AccessKeyId, ossCfg原创 2021-07-16 15:34:16 · 581 阅读 · 0 评论 -
go 读取yml
mysql: dsn: "root:123456@tcp(172.17.0.1:3306)/articles?charset=utf8mb4&parseTime=True&loc=Local" max_open: 100 max_idle: 10 life_time: "+3s" log: trueredis: addr: "172.18.0.1:2379"引入包_ "github.com/jinzhu/gorm/dialects/mysql" ".原创 2021-07-16 15:31:54 · 910 阅读 · 0 评论 -
sqlx 在把timestamp转为go的time.Time报错
sqlx 在把timestamp转为go的time.Time报错:sql: Scan error on column index 6: unsupported Scan, storing driver.Value type []uint8 into type *time.Time这个只需要在数据库链接字符串上加上parseTime=true就可以了,表示查询结果字段转为时间,如果不加上,sql查询出来的是0001-01-01 00:00:00 +0000 UTCroot:123456@tc原创 2021-07-08 11:11:53 · 747 阅读 · 0 评论 -
gorm记一次joins查询不出数据
在使用Joins查询时,使用了Scan自定义接口获取数据type UserRouteResult struct { Id uint `json:"id"` Cover string `json:"cover"` Name string `json:"name"` Step uint `json:"step"` CreatedAt time.Time UserId uint `json:"userId"`}但在结果中UserId是0,也没有报错,把sql打印出来使用m原创 2021-06-25 16:40:37 · 999 阅读 · 0 评论 -
go websocket
import ( "encoding/json" "fmt" "github.com/gorilla/websocket" "shopeecallback/service")type User struct { Conn *websocket.Conn UserId int64 Msg chan []byte}type Message struct { UserId int64 `json:"user_id, omitempty"` ShopId int64 `j.原创 2021-06-11 15:58:44 · 323 阅读 · 3 评论 -
gorm的sum查询
var amount1 float64 global.GVA_DB.Model(&product).Debug().Where("`type` = 0 AND `category_id` = ?", cat.ID).Pluck("COALESCE(SUM(price), 0) as amount1", &amount1).Error原创 2021-01-27 16:18:36 · 4980 阅读 · 0 评论 -
Gin重复绑定post数据问题
项目中,使用到了分页以及一些参数,分页单独写的绑定参数,type PageInfo struct { Page int `json:"page" form:"page"` PageSize int `json:"pageSize" form:"pageSize"`}但现在我需要传另外的参数,如type GetByParentId struct { ParentId uint `json:"parentId" form:"parentId"`}在使用ShouldBind原创 2021-01-19 17:19:19 · 1130 阅读 · 0 评论 -
golang随机字符串
func GetRoundName(size int) string { str := "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" bytes := []byte(str) result := []byte{} r := rand.New(rand.NewSource(time.Now().UnixNano())) for i := 0; i < size; i++ { result = append.原创 2020-11-09 12:01:53 · 361 阅读 · 0 评论 -
gloang判断文件夹是否操作
func GetSaveDir(savePath string) string { // os.stat返回err==nil,说明存在 _, err := os.Stat(savePath) if err != nil { // os.IsNotExist(err)为true,说明不存在;否则不确定是否存在 if os.IsNotExist(err){ os.Mkdir(savePath, 0777) } } return savePath}...原创 2020-11-09 11:57:51 · 130 阅读 · 0 评论 -
gin结合gorm实现mysql增删改查
https://gin-gonic.com/https://gorm.io/zh_CN/docs/index.htmlhttps://github.com/gin-gonic/gin/https://github.com/go-gorm/gorm集成go mod方式require ( github.com/gin-contrib/sessions v0.0.3 github.com/gin-gonic/gin v1.6.2 github.com/go-sql-driver/m原创 2020-11-09 11:54:52 · 1782 阅读 · 0 评论 -
golang的go mod
介绍最近在鼓捣golang,记得golang刚出来的时候,新建工程还需要新建到src目录下,自go mod问世后,就没这要求了。https://github.com/golang/go/wiki/Modules用这个需要把golang升级到1.11以上Go has included support for versioned modules as proposedheresince 1.11.配置需要设置环境变量,当然,bin目录还是要加入到环境变量的path中的,除了这个,还...原创 2020-11-09 11:43:07 · 422 阅读 · 0 评论 -
beego curd
首先建立模型package modelsimport "time"type Friendlink struct { Id int64 Name string `description:"网站名称"` Logo string `orm:"null" description:"网站logo"` Url string `description:"网站链接"` Sort int `...原创 2019-05-27 17:27:12 · 310 阅读 · 0 评论 -
beego 验证
使用structtype FriendlinkForm struct { Id int64 `form:"-"` Name string `form:"name"` Logo string `form:"logo"` Url string `form:"url"` Sort int `form:"sort"` // Url string `form:"url" valid:"Re...原创 2019-05-27 17:21:54 · 783 阅读 · 0 评论 -
beego 路由处理
func RestRoute(path string, action beego.ControllerInterface) { beego.Router(path, action,"get:Index") beego.Router(path + "/add", action,"get:Add") beego.Router(path + "/create", action,"post:Cre...原创 2019-05-27 17:17:26 · 330 阅读 · 0 评论