Browse Source

第一版个人中心

master
zhipeng.hu 3 years ago
parent
commit
58dc48e234
  1. 10
      go.mod
  2. 11
      initialize/gorm.go
  3. 52
      initialize/gorm_mysql.go
  4. 6
      log/server_info.log
  5. 14
      model/autocode/ercode.go
  6. 45
      utils/net.go

10
go.mod

@ -12,7 +12,6 @@ require (
github.com/go-redis/redis v6.15.9+incompatible github.com/go-redis/redis v6.15.9+incompatible
github.com/gookit/color v1.3.6 github.com/gookit/color v1.3.6
github.com/huaweicloud/huaweicloud-sdk-go-obs v3.21.12+incompatible github.com/huaweicloud/huaweicloud-sdk-go-obs v3.21.12+incompatible
github.com/mojocn/base64Captcha v1.3.5
github.com/natefinch/lumberjack v2.0.0+incompatible github.com/natefinch/lumberjack v2.0.0+incompatible
github.com/pkg/errors v0.9.1 github.com/pkg/errors v0.9.1
github.com/qiniu/api.v7/v7 v7.8.2 github.com/qiniu/api.v7/v7 v7.8.2
@ -24,8 +23,9 @@ require (
github.com/stretchr/testify v1.7.0 github.com/stretchr/testify v1.7.0
github.com/swaggo/gin-swagger v1.3.3 github.com/swaggo/gin-swagger v1.3.3
github.com/tencentyun/cos-go-sdk-v5 v0.7.33 github.com/tencentyun/cos-go-sdk-v5 v0.7.33
github.com/valyala/fasthttp v1.32.0
github.com/xlstudio/wxbizdatacrypt v1.0.2
go.uber.org/zap v1.20.0 go.uber.org/zap v1.20.0
gorm.io/driver/mysql v1.2.3
gorm.io/driver/postgres v1.2.3 gorm.io/driver/postgres v1.2.3
gorm.io/gorm v1.22.5 gorm.io/gorm v1.22.5
) )
@ -34,6 +34,7 @@ require (
github.com/KyleBanks/depth v1.2.1 // indirect github.com/KyleBanks/depth v1.2.1 // indirect
github.com/PuerkitoBio/purell v1.1.1 // indirect github.com/PuerkitoBio/purell v1.1.1 // indirect
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 // indirect github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 // indirect
github.com/andybalholm/brotli v1.0.2 // indirect
github.com/baiyubin/aliyun-sts-go-sdk v0.0.0-20180326062324-cfa1a18b161f // indirect github.com/baiyubin/aliyun-sts-go-sdk v0.0.0-20180326062324-cfa1a18b161f // indirect
github.com/davecgh/go-spew v1.1.1 // indirect github.com/davecgh/go-spew v1.1.1 // indirect
github.com/gin-contrib/sse v0.1.0 // indirect github.com/gin-contrib/sse v0.1.0 // indirect
@ -45,8 +46,6 @@ require (
github.com/go-playground/locales v0.14.0 // indirect github.com/go-playground/locales v0.14.0 // indirect
github.com/go-playground/universal-translator v0.18.0 // indirect github.com/go-playground/universal-translator v0.18.0 // indirect
github.com/go-playground/validator/v10 v10.9.0 // indirect github.com/go-playground/validator/v10 v10.9.0 // indirect
github.com/go-sql-driver/mysql v1.6.0 // indirect
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 // indirect
github.com/golang/protobuf v1.5.2 // indirect github.com/golang/protobuf v1.5.2 // indirect
github.com/google/go-querystring v1.0.0 // indirect github.com/google/go-querystring v1.0.0 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect github.com/hashicorp/hcl v1.0.0 // indirect
@ -63,6 +62,7 @@ require (
github.com/jmespath/go-jmespath v0.4.0 // indirect github.com/jmespath/go-jmespath v0.4.0 // indirect
github.com/josharian/intern v1.0.0 // indirect github.com/josharian/intern v1.0.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect github.com/json-iterator/go v1.1.12 // indirect
github.com/klauspost/compress v1.13.4 // indirect
github.com/leodido/go-urn v1.2.1 // indirect github.com/leodido/go-urn v1.2.1 // indirect
github.com/magiconair/properties v1.8.5 // indirect github.com/magiconair/properties v1.8.5 // indirect
github.com/mailru/easyjson v0.7.7 // indirect github.com/mailru/easyjson v0.7.7 // indirect
@ -84,11 +84,11 @@ require (
github.com/tklauser/go-sysconf v0.3.9 // indirect github.com/tklauser/go-sysconf v0.3.9 // indirect
github.com/tklauser/numcpus v0.3.0 // indirect github.com/tklauser/numcpus v0.3.0 // indirect
github.com/ugorji/go/codec v1.2.6 // indirect github.com/ugorji/go/codec v1.2.6 // indirect
github.com/valyala/bytebufferpool v1.0.0 // indirect
github.com/yusufpapurcu/wmi v1.2.2 // indirect github.com/yusufpapurcu/wmi v1.2.2 // indirect
go.uber.org/atomic v1.7.0 // indirect go.uber.org/atomic v1.7.0 // indirect
go.uber.org/multierr v1.6.0 // indirect go.uber.org/multierr v1.6.0 // indirect
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519 // indirect golang.org/x/crypto v0.0.0-20210921155107-089bfa567519 // indirect
golang.org/x/image v0.0.0-20210220032944-ac19c3e999fb // indirect
golang.org/x/net v0.0.0-20211216030914-fe4d6282115f // indirect golang.org/x/net v0.0.0-20211216030914-fe4d6282115f // indirect
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c // indirect golang.org/x/sync v0.0.0-20210220032951-036812b2e83c // indirect
golang.org/x/sys v0.0.0-20211210111614-af8b64212486 // indirect golang.org/x/sys v0.0.0-20211210111614-af8b64212486 // indirect

11
initialize/gorm.go

@ -12,14 +12,7 @@ import (
// Gorm 初始化数据库并产生数据库全局变量 // Gorm 初始化数据库并产生数据库全局变量
// Author SliverHorn // Author SliverHorn
func Gorm() *gorm.DB { func Gorm() *gorm.DB {
switch global.GVA_CONFIG.System.DbType {
case "mysql":
return GormMysql()
case "pgsql":
return GormPgSql()
default:
return GormMysql()
}
return GormInit()
} }
// RegisterTables 注册数据库表专用 // RegisterTables 注册数据库表专用
@ -30,6 +23,8 @@ func RegisterTables(db *gorm.DB) {
// 自动化模块表 // 自动化模块表
// Code generated by github.com/flipped-aurora/yibu/server Begin; DO NOT EDIT. // Code generated by github.com/flipped-aurora/yibu/server Begin; DO NOT EDIT.
autocode.AutoCodeExample{}, autocode.AutoCodeExample{},
autocode.UserInfo{},
autocode.Ercode{},
// Code generated by github.com/flipped-aurora/yibu/server End; DO NOT EDIT. // Code generated by github.com/flipped-aurora/yibu/server End; DO NOT EDIT.
) )
if err != nil { if err != nil {

52
initialize/gorm_mysql.go

@ -1,52 +0,0 @@
package initialize
import (
"autocode/config"
"autocode/global"
"autocode/initialize/internal"
"gorm.io/driver/mysql"
"gorm.io/gorm"
)
// GormMysql 初始化Mysql数据库
// Author [piexlmax](https://github.com/piexlmax)
// Author [SliverHorn](https://github.com/SliverHorn)
func GormMysql() *gorm.DB {
m := global.GVA_CONFIG.Mysql
if m.Dbname == "" {
return nil
}
mysqlConfig := mysql.Config{
DSN: m.Dsn(), // DSN data source name
DefaultStringSize: 191, // string 类型字段的默认长度
SkipInitializeWithVersion: false, // 根据版本自动配置
}
if db, err := gorm.Open(mysql.New(mysqlConfig), internal.Gorm.Config()); err != nil {
return nil
} else {
sqlDB, _ := db.DB()
sqlDB.SetMaxIdleConns(m.MaxIdleConns)
sqlDB.SetMaxOpenConns(m.MaxOpenConns)
return db
}
}
// GormMysqlByConfig 初始化Mysql数据库用过传入配置
func GormMysqlByConfig(m config.DB) *gorm.DB {
if m.Dbname == "" {
return nil
}
mysqlConfig := mysql.Config{
DSN: m.Dsn(), // DSN data source name
DefaultStringSize: 191, // string 类型字段的默认长度
SkipInitializeWithVersion: false, // 根据版本自动配置
}
if db, err := gorm.Open(mysql.New(mysqlConfig), internal.Gorm.Config()); err != nil {
panic(err)
} else {
sqlDB, _ := db.DB()
sqlDB.SetMaxIdleConns(m.MaxIdleConns)
sqlDB.SetMaxOpenConns(m.MaxOpenConns)
return db
}
}

6
log/server_info.log

@ -492,3 +492,9 @@
[github.com/flipped-aurora/yibu/server]2022/01/16 - 14:56:34.358 info C:/Users/Administrator/go/src/awesomeProject5/autocode/initialize/router.go:35 register swagger handler [github.com/flipped-aurora/yibu/server]2022/01/16 - 14:56:34.358 info C:/Users/Administrator/go/src/awesomeProject5/autocode/initialize/router.go:35 register swagger handler
[github.com/flipped-aurora/yibu/server]2022/01/16 - 14:56:34.359 info C:/Users/Administrator/go/src/awesomeProject5/autocode/initialize/router.go:59 router register success [github.com/flipped-aurora/yibu/server]2022/01/16 - 14:56:34.359 info C:/Users/Administrator/go/src/awesomeProject5/autocode/initialize/router.go:59 router register success
[github.com/flipped-aurora/yibu/server]2022/01/16 - 14:56:34.365 info C:/Users/Administrator/go/src/awesomeProject5/autocode/core/server.go:31 server run success on {"address": ":8888"} [github.com/flipped-aurora/yibu/server]2022/01/16 - 14:56:34.365 info C:/Users/Administrator/go/src/awesomeProject5/autocode/core/server.go:31 server run success on {"address": ":8888"}
[github.com/flipped-aurora/yibu/server]2022/01/16 - 16:00:22.394 info C:/Users/Administrator/go/src/awesomeProject5/autocode/initialize/gorm.go:34 register table success
[github.com/flipped-aurora/yibu/server]2022/01/16 - 16:00:22.396 info C:/Users/Administrator/go/src/awesomeProject5/autocode/initialize/router.go:29 use middleware logger
[github.com/flipped-aurora/yibu/server]2022/01/16 - 16:00:22.396 info C:/Users/Administrator/go/src/awesomeProject5/autocode/initialize/router.go:33 use middleware cors
[github.com/flipped-aurora/yibu/server]2022/01/16 - 16:00:22.396 info C:/Users/Administrator/go/src/awesomeProject5/autocode/initialize/router.go:35 register swagger handler
[github.com/flipped-aurora/yibu/server]2022/01/16 - 16:00:22.397 info C:/Users/Administrator/go/src/awesomeProject5/autocode/initialize/router.go:59 router register success
[github.com/flipped-aurora/yibu/server]2022/01/16 - 16:00:22.409 info C:/Users/Administrator/go/src/awesomeProject5/autocode/core/server.go:31 server run success on {"address": ":8888"}

14
model/autocode/ercode.go

@ -0,0 +1,14 @@
// 自动生成模板UserInfo
package autocode
// UserInfo 结构体
// 如果含有time.Time 请自行import time包
type Ercode struct {
WechatId string `json:"wechatId" form:"wechatId" gorm:"column:wechat_id;comment:;"`
QrcodeId string `json:"qrcodeId" form:"qrcodeId" gorm:"column:qrcode_id;comment:;"`
}
// TableName 表名
func (Ercode) TableName() string {
return "ercode"
}

45
utils/net.go

@ -0,0 +1,45 @@
package utils
import (
"errors"
"fmt"
"github.com/valyala/fasthttp"
)
func Get(url string) ([]byte, error) {
status, resp, err := fasthttp.Get(nil, url)
if err != nil {
return []byte{}, err
}
if status != fasthttp.StatusOK {
return []byte{}, errors.New(fmt.Sprintf("请求失败:%d", status))
}
return resp, nil
}
func PostJson(url string, JsonString string) ([]byte, error) {
req := fasthttp.AcquireRequest()
resp := fasthttp.AcquireResponse()
defer func() {
// 用完需要释放资源
fasthttp.ReleaseResponse(resp)
fasthttp.ReleaseRequest(req)
}()
// 默认是application/x-www-form-urlencoded
req.Header.SetContentType("application/json")
req.Header.SetMethod("POST")
req.SetRequestURI(url)
requestBody := []byte(JsonString)
req.SetBody(requestBody)
if err := fasthttp.Do(req, resp); err != nil {
return []byte{}, err
}
b := resp.Body()
fmt.Println(string(b))
return b, nil
}
Loading…
Cancel
Save