mirror of
https://github.com/go-admin-team/go-admin.git
synced 2026-09-24 19:17:43 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3873342f6c | ||
|
|
717903a2b6 | ||
|
|
88030e301a | ||
|
|
cd0792e3d2 | ||
|
|
6ed2fcbf6c | ||
|
|
bf93b86bd0 | ||
|
|
c41672c21a | ||
|
|
8716b073df | ||
|
|
638bab3c9d | ||
|
|
c5d7a8c740 | ||
|
|
b030be8f80 | ||
|
|
1fe19d1c3b | ||
|
|
1508e850fe | ||
|
|
81bc15d77c | ||
|
|
24adca55e4 | ||
|
|
9c8974a26e | ||
|
|
01e8984b79 | ||
|
|
7f1aa89539 | ||
|
|
4876fc0aa1 | ||
|
|
f998d20a86 | ||
|
|
cdb5faf043 | ||
|
|
dfaa2ff51e | ||
|
|
8754ff8147 | ||
|
|
cca84c3c21 | ||
|
|
b52da434bb | ||
|
|
3cfa7a2767 | ||
|
|
054199d1e4 | ||
|
|
abdc80b756 |
+1
-1
@@ -1,6 +1,6 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2020 wenjianzhang
|
||||
Copyright (c) 2020 go-admin-team
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
|
||||
+10
-3
@@ -1,6 +1,6 @@
|
||||
# go-admin
|
||||
|
||||
<img align="right" width="320" src="https://gitee.com/mydearzwj/image/raw/master/img/go-admin.svg">
|
||||
<img align="right" width="320" src="https://raw.githubusercontent.com/wenjianzhang/image/a44d60756c9fdedbd70f6bff076a31cbf314936a/img/go-admin.svg">
|
||||
|
||||
|
||||
[](https://github.com/go-admin-team/go-admin)
|
||||
@@ -74,9 +74,9 @@
|
||||
|
||||
### 轻松实现go-admin写出第一个应用 - 文档教程
|
||||
|
||||
[步骤一 - 基础内容介绍](http://doc.zhangwj.com/go-admin-site/guide/intro/tutorial01.html)
|
||||
[步骤一 - 基础内容介绍](https://doc.zhangwj.com/guide/intro/tutorial01.html)
|
||||
|
||||
[步骤二 - 实际应用 - 编写增删改查](http://doc.zhangwj.com/go-admin-site/guide/intro/tutorial02.html)
|
||||
[步骤二 - 实际应用 - 编写增删改查](https://doc.zhangwj.com/guide/intro/tutorial02.html)
|
||||
|
||||
### 手把手教你从入门到放弃 - 视频教程
|
||||
|
||||
@@ -182,6 +182,13 @@ $ ./go-admin server -c config/settings.yml
|
||||
$ go-admin.exe server -c config/settings.yml
|
||||
```
|
||||
|
||||
#### sys_api 表的数据如何添加
|
||||
|
||||
在项目启动时,使用`-a true` 系统会自动添加缺少的接口数据
|
||||
```bash
|
||||
./go-admin server -c config/settings.yml -a true
|
||||
```
|
||||
|
||||
#### 使用docker 编译启动
|
||||
|
||||
```shell
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
|
||||
# go-admin
|
||||
|
||||
<img align="right" width="320" src="https://gitee.com/mydearzwj/image/raw/master/img/go-admin.svg">
|
||||
<img align="right" width="320" src="https://raw.githubusercontent.com/wenjianzhang/image/a44d60756c9fdedbd70f6bff076a31cbf314936a/img/go-admin.svg">
|
||||
|
||||
|
||||
[](https://github.com/go-admin-team/go-admin)
|
||||
@@ -68,9 +68,9 @@ At the same time, a series of tutorials including videos and documents are provi
|
||||
|
||||
### Easily implement go-admin to write the first application-documentation tutorial
|
||||
|
||||
[Step 1 - basic content introduction](http://doc.zhangwj.com/go-admin-site/guide/intro/tutorial01.html)
|
||||
[Step 1 - basic content introduction](https://doc.zhangwj.com/guide/intro/tutorial01.html)
|
||||
|
||||
[Step 2 - Practical application - writing database operations](http://doc.zhangwj.com/go-admin-site/guide/intro/tutorial02.html)
|
||||
[Step 2 - Practical application - writing database operations](https://doc.zhangwj.com/guide/intro/tutorial02.html)
|
||||
|
||||
### Teach you from getting started to giving up-video tutorial
|
||||
|
||||
|
||||
@@ -125,7 +125,7 @@ func (e SysRole) Insert(c *gin.Context) {
|
||||
err = s.Insert(&req, cb)
|
||||
if err != nil {
|
||||
e.Logger.Error(err)
|
||||
e.Error(500, err, "创建失败")
|
||||
e.Error(500, err, "创建失败,"+err.Error())
|
||||
return
|
||||
}
|
||||
_, err = global.LoadPolicy(c)
|
||||
|
||||
+30
-16
@@ -2,6 +2,7 @@ package apis
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin/binding"
|
||||
"github.com/go-admin-team/go-admin-core/sdk/config"
|
||||
"go-admin/app/admin/models"
|
||||
"net/http"
|
||||
|
||||
@@ -30,7 +31,7 @@ type SysUser struct {
|
||||
// @Security Bearer
|
||||
func (e SysUser) GetPage(c *gin.Context) {
|
||||
s := service.SysUser{}
|
||||
req :=dto.SysUserGetPageReq{}
|
||||
req := dto.SysUserGetPageReq{}
|
||||
err := e.MakeContext(c).
|
||||
MakeOrm().
|
||||
Bind(&req).
|
||||
@@ -67,7 +68,7 @@ func (e SysUser) GetPage(c *gin.Context) {
|
||||
// @Security Bearer
|
||||
func (e SysUser) Get(c *gin.Context) {
|
||||
s := service.SysUser{}
|
||||
req :=dto.SysUserById{}
|
||||
req := dto.SysUserById{}
|
||||
err := e.MakeContext(c).
|
||||
MakeOrm().
|
||||
Bind(&req, nil).
|
||||
@@ -101,7 +102,7 @@ func (e SysUser) Get(c *gin.Context) {
|
||||
// @Security Bearer
|
||||
func (e SysUser) Insert(c *gin.Context) {
|
||||
s := service.SysUser{}
|
||||
req :=dto.SysUserInsertReq{}
|
||||
req := dto.SysUserInsertReq{}
|
||||
err := e.MakeContext(c).
|
||||
MakeOrm().
|
||||
Bind(&req, binding.JSON).
|
||||
@@ -136,7 +137,7 @@ func (e SysUser) Insert(c *gin.Context) {
|
||||
// @Security Bearer
|
||||
func (e SysUser) Update(c *gin.Context) {
|
||||
s := service.SysUser{}
|
||||
req :=dto.SysUserUpdateReq{}
|
||||
req := dto.SysUserUpdateReq{}
|
||||
err := e.MakeContext(c).
|
||||
MakeOrm().
|
||||
Bind(&req).
|
||||
@@ -171,7 +172,7 @@ func (e SysUser) Update(c *gin.Context) {
|
||||
// @Security Bearer
|
||||
func (e SysUser) Delete(c *gin.Context) {
|
||||
s := service.SysUser{}
|
||||
req :=dto.SysUserById{}
|
||||
req := dto.SysUserById{}
|
||||
err := e.MakeContext(c).
|
||||
MakeOrm().
|
||||
Bind(&req, binding.JSON).
|
||||
@@ -208,7 +209,7 @@ func (e SysUser) Delete(c *gin.Context) {
|
||||
// @Security Bearer
|
||||
func (e SysUser) InsetAvatar(c *gin.Context) {
|
||||
s := service.SysUser{}
|
||||
req :=dto.UpdateSysUserAvatarReq{}
|
||||
req := dto.UpdateSysUserAvatarReq{}
|
||||
err := e.MakeContext(c).
|
||||
MakeOrm().
|
||||
MakeService(&s.Service).
|
||||
@@ -257,7 +258,7 @@ func (e SysUser) InsetAvatar(c *gin.Context) {
|
||||
// @Security Bearer
|
||||
func (e SysUser) UpdateStatus(c *gin.Context) {
|
||||
s := service.SysUser{}
|
||||
req :=dto.UpdateSysUserStatusReq{}
|
||||
req := dto.UpdateSysUserStatusReq{}
|
||||
err := e.MakeContext(c).
|
||||
MakeOrm().
|
||||
Bind(&req, binding.JSON, nil).
|
||||
@@ -294,7 +295,7 @@ func (e SysUser) UpdateStatus(c *gin.Context) {
|
||||
// @Security Bearer
|
||||
func (e SysUser) ResetPwd(c *gin.Context) {
|
||||
s := service.SysUser{}
|
||||
req :=dto.ResetSysUserPwdReq{}
|
||||
req := dto.ResetSysUserPwdReq{}
|
||||
err := e.MakeContext(c).
|
||||
MakeOrm().
|
||||
Bind(&req, binding.JSON).
|
||||
@@ -311,16 +312,23 @@ func (e SysUser) ResetPwd(c *gin.Context) {
|
||||
//数据权限检查
|
||||
p := actions.GetPermissionFromContext(c)
|
||||
|
||||
if req.UserId == 1 && config.ApplicationConfig.Mode == "demo" {
|
||||
req.Password = "123456"
|
||||
}
|
||||
err = s.ResetPwd(&req, p)
|
||||
if err != nil {
|
||||
e.Logger.Error(err)
|
||||
return
|
||||
}
|
||||
e.OK(req.GetId(), "更新成功")
|
||||
if req.UserId == 1 && config.ApplicationConfig.Mode == "demo" {
|
||||
e.OK(req.GetId(), "admin:现在使用的预览环境,休想改掉我!否则会影响其他朋友体验的哦!可以创建其他用户体验该功能!")
|
||||
} else {
|
||||
e.OK(req.GetId(), "更新成功")
|
||||
}
|
||||
}
|
||||
|
||||
// UpdatePwd
|
||||
// @Summary 重置密码
|
||||
// @Summary 修改密码
|
||||
// @Description 获取JSON
|
||||
// @Tags 用户
|
||||
// @Accept application/json
|
||||
@@ -331,7 +339,7 @@ func (e SysUser) ResetPwd(c *gin.Context) {
|
||||
// @Security Bearer
|
||||
func (e SysUser) UpdatePwd(c *gin.Context) {
|
||||
s := service.SysUser{}
|
||||
req :=dto.PassWord{}
|
||||
req := dto.PassWord{}
|
||||
err := e.MakeContext(c).
|
||||
MakeOrm().
|
||||
Bind(&req).
|
||||
@@ -345,14 +353,20 @@ func (e SysUser) UpdatePwd(c *gin.Context) {
|
||||
|
||||
// 数据权限检查
|
||||
p := actions.GetPermissionFromContext(c)
|
||||
|
||||
if user.GetUserId(c) == 1 && config.ApplicationConfig.Mode == "demo" {
|
||||
req.NewPassword = "123456"
|
||||
}
|
||||
err = s.UpdatePwd(user.GetUserId(c), req.OldPassword, req.NewPassword, p)
|
||||
if err != nil {
|
||||
e.Logger.Error(err)
|
||||
e.Error(http.StatusForbidden, err, "密码修改失败")
|
||||
return
|
||||
}
|
||||
e.OK(nil, "密码修改成功")
|
||||
if user.GetUserId(c) == 1 && config.ApplicationConfig.Mode == "demo" {
|
||||
e.OK(nil, "admin:现在使用的预览环境,休想改掉我!否则会影响其他朋友体验的哦!可以创建其他用户体验该功能!")
|
||||
} else {
|
||||
e.OK(nil, "密码修改成功")
|
||||
}
|
||||
}
|
||||
|
||||
// GetProfile
|
||||
@@ -364,7 +378,7 @@ func (e SysUser) UpdatePwd(c *gin.Context) {
|
||||
// @Security Bearer
|
||||
func (e SysUser) GetProfile(c *gin.Context) {
|
||||
s := service.SysUser{}
|
||||
req :=dto.SysUserById{}
|
||||
req := dto.SysUserById{}
|
||||
err := e.MakeContext(c).
|
||||
MakeOrm().
|
||||
MakeService(&s.Service).
|
||||
@@ -401,7 +415,7 @@ func (e SysUser) GetProfile(c *gin.Context) {
|
||||
// @Router /api/v1/getinfo [get]
|
||||
// @Security Bearer
|
||||
func (e SysUser) GetInfo(c *gin.Context) {
|
||||
req :=dto.SysUserById{}
|
||||
req := dto.SysUserById{}
|
||||
s := service.SysUser{}
|
||||
r := service.SysRole{}
|
||||
err := e.MakeContext(c).
|
||||
@@ -450,4 +464,4 @@ func (e SysUser) GetInfo(c *gin.Context) {
|
||||
mp["name"] = sysUser.NickName
|
||||
mp["code"] = 200
|
||||
e.OK(mp, "")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -83,6 +83,18 @@ func (e *SysRole) Insert(c *dto.SysRoleInsertReq, cb *casbin.SyncedEnforcer) err
|
||||
}
|
||||
}()
|
||||
}
|
||||
var count int64
|
||||
err = tx.Model(&data).Where("role_key = ?", c.RoleKey).Count(&count).Error
|
||||
if err != nil {
|
||||
e.Log.Errorf("db error:%s", err)
|
||||
return err
|
||||
}
|
||||
|
||||
if count > 0 {
|
||||
err = errors.New("roleKey已存在,需更换在提交!")
|
||||
e.Log.Errorf("db error:%s", err)
|
||||
return err
|
||||
}
|
||||
|
||||
err = tx.Create(&data).Error
|
||||
if err != nil {
|
||||
@@ -227,7 +239,7 @@ func (e *SysRole) UpdateDataScope(c *dto.RoleDataScopeReq) *SysRole {
|
||||
var dlist = make([]models.SysDept, 0)
|
||||
var model = models.SysRole{}
|
||||
tx.Preload("SysDept").First(&model, c.RoleId)
|
||||
tx.Where("id in ?", c.DeptIds).Find(&dlist)
|
||||
tx.Where("dept_id in ?", c.DeptIds).Find(&dlist)
|
||||
err = tx.Model(&model).Association("SysDept").Delete(model.SysDept)
|
||||
if err != nil {
|
||||
e.Log.Errorf("delete SysDept error:%s", err)
|
||||
|
||||
@@ -127,8 +127,7 @@ func (e *SysUser) UpdateAvatar(c *dto.UpdateSysUserAvatarReq, p *actions.DataPer
|
||||
return errors.New("无权更新该数据")
|
||||
|
||||
}
|
||||
c.Generate(&model)
|
||||
err = e.Orm.Save(&model).Error
|
||||
err = e.Orm.Table(model.TableName()).Where("user_id =? ", c.UserId).Updates(c).Error
|
||||
if err != nil {
|
||||
e.Log.Errorf("Service UpdateSysUser error: %s", err)
|
||||
return err
|
||||
@@ -151,8 +150,7 @@ func (e *SysUser) UpdateStatus(c *dto.UpdateSysUserStatusReq, p *actions.DataPer
|
||||
return errors.New("无权更新该数据")
|
||||
|
||||
}
|
||||
c.Generate(&model)
|
||||
err = e.Orm.Save(&model).Error
|
||||
err = e.Orm.Table(model.TableName()).Where("user_id =? ", c.UserId).Updates(c).Error
|
||||
if err != nil {
|
||||
e.Log.Errorf("Service UpdateSysUser error: %s", err)
|
||||
return err
|
||||
@@ -175,7 +173,7 @@ func (e *SysUser) ResetPwd(c *dto.ResetSysUserPwdReq, p *actions.DataPermission)
|
||||
return errors.New("无权更新该数据")
|
||||
}
|
||||
c.Generate(&model)
|
||||
err = e.Orm.Save(&model).Error
|
||||
err = e.Orm.Omit("username", "nick_name", "phone", "role_id", "avatar", "sex").Save(&model).Error
|
||||
if err != nil {
|
||||
e.Log.Errorf("At Service ResetSysUserPwd error: %s", err)
|
||||
return err
|
||||
|
||||
@@ -62,7 +62,7 @@ func (e SysJob) StartJobForService(c *gin.Context) {
|
||||
err = s.StartJob(&v)
|
||||
if err != nil {
|
||||
log.Errorf("GetCrontabKey error, %s", err.Error())
|
||||
e.Error(500, err, "")
|
||||
e.Error(500, err, err.Error())
|
||||
return
|
||||
}
|
||||
e.OK(nil, s.Msg)
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"github.com/pkg/errors"
|
||||
"time"
|
||||
|
||||
"github.com/go-admin-team/go-admin-core/sdk/service"
|
||||
@@ -52,6 +53,12 @@ func (e *SysJob) StartJob(c *dto.GeneralGetDto) error {
|
||||
e.Log.Errorf("db error: %s", err)
|
||||
return err
|
||||
}
|
||||
|
||||
if data.Status == 1 {
|
||||
err = errors.New("当前Job是关闭状态不能被启动,请先启用。")
|
||||
return err
|
||||
}
|
||||
|
||||
if data.JobType == 1 {
|
||||
var j = &jobs.HttpJob{}
|
||||
j.InvokeTarget = data.InvokeTarget
|
||||
|
||||
@@ -1,13 +1,45 @@
|
||||
package file_store
|
||||
|
||||
type FileStore struct {
|
||||
import "fmt"
|
||||
|
||||
type OXS struct {
|
||||
// Endpoint 访问域名
|
||||
Endpoint string
|
||||
// AccessKeyID AK
|
||||
AccessKeyID string
|
||||
// AccessKeySecret AKS
|
||||
AccessKeySecret string
|
||||
// BucketName 桶名称
|
||||
BucketName string
|
||||
}
|
||||
|
||||
// Setup 配置数据库
|
||||
func (e *FileStore) Setup(driver string) {
|
||||
//fileStoreType := driver
|
||||
//if fileStoreType == "ALiYunOSS" {
|
||||
// var store = new(ALiYunOSS)
|
||||
// store.Setup()
|
||||
//}
|
||||
// Setup 配置文件存储driver
|
||||
func (e *OXS) Setup(driver DriverType, options ...ClientOption) FileStoreType {
|
||||
fileStoreType := driver
|
||||
var fileStore FileStoreType
|
||||
switch fileStoreType {
|
||||
case AliYunOSS:
|
||||
fileStore = new(ALiYunOSS)
|
||||
err := fileStore.Setup(e.Endpoint, e.AccessKeyID, e.AccessKeySecret, e.BucketName)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
return fileStore
|
||||
case HuaweiOBS:
|
||||
fileStore = new(HuaWeiOBS)
|
||||
err := fileStore.Setup(e.Endpoint, e.AccessKeyID, e.AccessKeySecret, e.BucketName)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
return fileStore
|
||||
case QiNiuKodo:
|
||||
fileStore = new(QiNiuKODO)
|
||||
err := fileStore.Setup(e.Endpoint, e.AccessKeyID, e.AccessKeySecret, e.BucketName)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
return fileStore
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -1,6 +1,27 @@
|
||||
package file_store
|
||||
|
||||
// DriverType 驱动类型
|
||||
type DriverType string
|
||||
|
||||
const (
|
||||
// HuaweiOBS 华为云OBS
|
||||
HuaweiOBS DriverType = "HuaweiOBS"
|
||||
// AliYunOSS 阿里云OSS
|
||||
AliYunOSS DriverType = "AliYunOSS"
|
||||
// QiNiuKodo 七牛云kodo
|
||||
QiNiuKodo DriverType = "QiNiuKodo"
|
||||
)
|
||||
|
||||
type ClientOption map[string]interface{}
|
||||
|
||||
// TODO: FileStoreType名称待定
|
||||
|
||||
// FileStoreType OXS
|
||||
type FileStoreType interface {
|
||||
Setup() error
|
||||
UpLoad(yourObjectName string, localFile string) error
|
||||
// Setup 装载 endpoint sss
|
||||
Setup(endpoint, accessKeyID, accessKeySecret, BucketName string, options ...ClientOption) error
|
||||
// UpLoad 上传
|
||||
UpLoad(yourObjectName string, localFile interface{}) error
|
||||
// GetTempToken 获取临时Token
|
||||
GetTempToken() (string, error)
|
||||
}
|
||||
|
||||
@@ -0,0 +1,111 @@
|
||||
package file_store
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/qiniu/go-sdk/v7/auth/qbox"
|
||||
"github.com/qiniu/go-sdk/v7/storage"
|
||||
)
|
||||
|
||||
type Zone string
|
||||
|
||||
const (
|
||||
// HuaDong 华东
|
||||
HuaDong Zone = "HuaDong"
|
||||
// HuaBei 华北
|
||||
HuaBei Zone = "HuaBei"
|
||||
// HuaNan 华南
|
||||
HuaNan Zone = "HuaNan"
|
||||
// BeiMei 北美
|
||||
BeiMei Zone = "BeiMei"
|
||||
// XinJiaPo 新加坡
|
||||
XinJiaPo Zone = "XinJiaPo"
|
||||
)
|
||||
|
||||
type QiNiuKODO struct {
|
||||
Client interface{}
|
||||
BucketName string
|
||||
cfg storage.Config
|
||||
options []ClientOption
|
||||
}
|
||||
|
||||
func (e *QiNiuKODO) getToken() string {
|
||||
putPolicy := storage.PutPolicy{
|
||||
Scope: e.BucketName,
|
||||
}
|
||||
if len(e.options) > 0 && e.options[0]["Expires"] != nil {
|
||||
putPolicy.Expires = e.options[0]["Expires"].(uint64)
|
||||
}
|
||||
upToken := putPolicy.UploadToken(e.Client.(*qbox.Mac))
|
||||
return upToken
|
||||
}
|
||||
|
||||
//Setup 装载
|
||||
//endpoint sss
|
||||
func (e *QiNiuKODO) Setup(endpoint, accessKeyID, accessKeySecret, BucketName string, options ...ClientOption) error {
|
||||
|
||||
mac := qbox.NewMac(accessKeyID, accessKeySecret)
|
||||
// 获取存储空间。
|
||||
cfg := storage.Config{}
|
||||
// 空间对应的机房
|
||||
e.setZoneORDefault(cfg, options...)
|
||||
// 是否使用https域名
|
||||
cfg.UseHTTPS = true
|
||||
// 上传是否使用CDN上传加速
|
||||
cfg.UseCdnDomains = false
|
||||
|
||||
e.Client = mac
|
||||
e.BucketName = BucketName
|
||||
e.cfg = cfg
|
||||
e.options = options
|
||||
return nil
|
||||
}
|
||||
|
||||
// setZoneORDefault 设置Zone或者默认华东
|
||||
func (e *QiNiuKODO) setZoneORDefault(cfg storage.Config, options ...ClientOption) {
|
||||
if len(options) > 0 && options[0]["Zone"] != nil {
|
||||
if _, ok := options[0]["Zone"].(Zone); !ok {
|
||||
cfg.Zone = &storage.ZoneHuadong
|
||||
}
|
||||
switch options[0]["Zone"].(Zone) {
|
||||
case HuaDong:
|
||||
cfg.Zone = &storage.ZoneHuadong
|
||||
case HuaBei:
|
||||
cfg.Zone = &storage.ZoneHuabei
|
||||
case HuaNan:
|
||||
cfg.Zone = &storage.ZoneHuanan
|
||||
case BeiMei:
|
||||
cfg.Zone = &storage.ZoneBeimei
|
||||
case XinJiaPo:
|
||||
cfg.Zone = &storage.ZoneXinjiapo
|
||||
default:
|
||||
cfg.Zone = &storage.ZoneHuadong
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// UpLoad 文件上传
|
||||
func (e *QiNiuKODO) UpLoad(yourObjectName string, localFile interface{}) error {
|
||||
|
||||
// 构建表单上传的对象
|
||||
formUploader := storage.NewFormUploader(&e.cfg)
|
||||
ret := storage.PutRet{}
|
||||
// 可选配置
|
||||
putExtra := storage.PutExtra{
|
||||
Params: map[string]string{
|
||||
"x:name": "github logo",
|
||||
},
|
||||
}
|
||||
err := formUploader.PutFile(context.Background(), &ret, e.getToken(), yourObjectName, localFile.(string), &putExtra)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return err
|
||||
}
|
||||
fmt.Println(ret.Key, ret.Hash)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (e *QiNiuKODO) GetTempToken() (string, error) {
|
||||
token := e.getToken()
|
||||
return token, nil
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package file_store
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestKODOUpload(t *testing.T) {
|
||||
e := OXS{"", "", "", ""}
|
||||
var oxs = e.Setup(QiNiuKodo, map[string]interface{}{"Zone": "华东"})
|
||||
err := oxs.UpLoad("test.png", "./test.png")
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
t.Log("ok")
|
||||
}
|
||||
|
||||
func TestKODOGetTempToken(t *testing.T) {
|
||||
e := OXS{"", "", "", ""}
|
||||
var oxs = e.Setup(QiNiuKodo, map[string]interface{}{"Zone": "华东"})
|
||||
token, _ := oxs.GetTempToken()
|
||||
t.Log(token)
|
||||
t.Log("ok")
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
package file_store
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/huaweicloud/huaweicloud-sdk-go-obs/obs"
|
||||
"log"
|
||||
)
|
||||
|
||||
type HuaWeiOBS struct {
|
||||
Client interface{}
|
||||
BucketName string
|
||||
}
|
||||
|
||||
func (e *HuaWeiOBS) Setup(endpoint, accessKeyID, accessKeySecret, BucketName string, options ...ClientOption) error {
|
||||
// 创建ObsClient结构体
|
||||
client, err := obs.New(accessKeyID, accessKeySecret, endpoint)
|
||||
if err != nil {
|
||||
log.Println("Error:", err)
|
||||
return err
|
||||
}
|
||||
e.Client = client
|
||||
e.BucketName = BucketName
|
||||
return nil
|
||||
}
|
||||
|
||||
// UpLoad 文件上传
|
||||
// yourObjectName 文件路径名称,与objectKey是同一概念,表示断点续传上传文件到OSS时需要指定包含文件后缀在内的完整路径,例如abc/efg/123.jpg
|
||||
func (e *HuaWeiOBS) UpLoad(yourObjectName string, localFile interface{}) error {
|
||||
// 获取存储空间。
|
||||
input := &obs.PutFileInput{}
|
||||
input.Bucket = e.BucketName
|
||||
input.Key = yourObjectName
|
||||
input.SourceFile = localFile.(string)
|
||||
output, err := e.Client.(*obs.ObsClient).PutFile(input)
|
||||
|
||||
if err == nil {
|
||||
fmt.Printf("RequestId:%s\n", output.RequestId)
|
||||
fmt.Printf("ETag:%s, StorageClass:%s\n", output.ETag, output.StorageClass)
|
||||
} else {
|
||||
if obsError, ok := err.(obs.ObsError); ok {
|
||||
fmt.Println(obsError.Code)
|
||||
fmt.Println(obsError.Message)
|
||||
} else {
|
||||
fmt.Println(err)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (e *HuaWeiOBS) GetTempToken() (string, error) {
|
||||
return "", nil
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package file_store
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestOBSUpload(t *testing.T) {
|
||||
e := OXS{"", "", "", ""}
|
||||
var oxs = e.Setup(HuaweiOBS)
|
||||
err := oxs.UpLoad("test.png", "./test.png")
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
t.Log("ok")
|
||||
}
|
||||
+14
-21
@@ -6,50 +6,43 @@ import (
|
||||
)
|
||||
|
||||
type ALiYunOSS struct {
|
||||
Client interface{}
|
||||
Endpoint string
|
||||
AccessKeyId string
|
||||
AccessKeySecret string
|
||||
BucketName string
|
||||
Client interface{}
|
||||
BucketName string
|
||||
}
|
||||
|
||||
func (e *ALiYunOSS) Setup() error {
|
||||
// TODO: 如果需要使用阿里云OSS请在此处填写对应信息
|
||||
e.AccessKeyId = ""
|
||||
e.AccessKeySecret = ""
|
||||
e.Endpoint = ""
|
||||
e.BucketName = ""
|
||||
|
||||
client, err := oss.New(e.Endpoint, e.AccessKeyId, e.AccessKeySecret)
|
||||
//Setup 装载
|
||||
//endpoint sss
|
||||
func (e *ALiYunOSS) Setup(endpoint, accessKeyID, accessKeySecret, BucketName string, options ...ClientOption) error {
|
||||
client, err := oss.New(endpoint, accessKeyID, accessKeySecret)
|
||||
if err != nil {
|
||||
log.Println("Error:", err)
|
||||
return err
|
||||
}
|
||||
e.Client = client
|
||||
e.BucketName = BucketName
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// UpLoad 文件上传
|
||||
func (e *ALiYunOSS) UpLoad(yourObjectName string, localFile string) error {
|
||||
err := e.Setup()
|
||||
if err != nil {
|
||||
log.Println("Error:", err)
|
||||
return err
|
||||
}
|
||||
func (e *ALiYunOSS) UpLoad(yourObjectName string, localFile interface{}) error {
|
||||
// 获取存储空间。
|
||||
bucket, err := e.Client.(*oss.Client).Bucket(e.BucketName)
|
||||
if err != nil {
|
||||
log.Println("Error:", err)
|
||||
return err
|
||||
}
|
||||
|
||||
// 设置分片大小为100 KB,指定分片上传并发数为3,并开启断点续传上传。
|
||||
// 其中<yourObjectName>与objectKey是同一概念,表示断点续传上传文件到OSS时需要指定包含文件后缀在内的完整路径,例如abc/efg/123.jpg。
|
||||
// "LocalFile"为filePath,100*1024为partSize。
|
||||
err = bucket.UploadFile(yourObjectName, localFile, 100*1024, oss.Routines(3), oss.Checkpoint(true, ""))
|
||||
err = bucket.UploadFile(yourObjectName, localFile.(string), 100*1024, oss.Routines(3), oss.Checkpoint(true, ""))
|
||||
if err != nil {
|
||||
log.Println("Error:", err)
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (e *ALiYunOSS) GetTempToken() (string, error) {
|
||||
return "", nil
|
||||
}
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
package file_store
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestOSSUpload(t *testing.T) {
|
||||
// 打括号内填写自己的测试信息即可
|
||||
e := OXS{}
|
||||
var oxs = e.Setup(AliYunOSS)
|
||||
err := oxs.UpLoad("test.png", "./test.png")
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
t.Log("ok")
|
||||
}
|
||||
@@ -2,7 +2,7 @@ package global
|
||||
|
||||
const (
|
||||
// Version go-admin version info
|
||||
Version = "2.0.9"
|
||||
Version = "2.0.11"
|
||||
)
|
||||
|
||||
var (
|
||||
|
||||
@@ -13,9 +13,11 @@ require (
|
||||
github.com/go-admin-team/go-admin-core v1.3.8
|
||||
github.com/go-admin-team/go-admin-core/sdk v1.3.9
|
||||
github.com/google/uuid v1.2.0
|
||||
github.com/huaweicloud/huaweicloud-sdk-go-obs v3.21.12+incompatible
|
||||
github.com/mssola/user_agent v0.5.2
|
||||
github.com/opentracing/opentracing-go v1.1.0
|
||||
github.com/prometheus/client_golang v1.11.0
|
||||
github.com/qiniu/go-sdk/v7 v7.11.1
|
||||
github.com/robfig/cron/v3 v3.0.1
|
||||
github.com/shirou/gopsutil/v3 v3.22.1
|
||||
github.com/spf13/cast v1.3.1
|
||||
@@ -23,7 +25,7 @@ require (
|
||||
github.com/swaggo/gin-swagger v1.2.0
|
||||
github.com/swaggo/swag v1.6.7
|
||||
github.com/unrolled/secure v1.0.8
|
||||
golang.org/x/crypto v0.0.0-20210220033148-5ea612d1eb83
|
||||
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519
|
||||
golang.org/x/lint v0.0.0-20200302205851-738671d3881b // indirect
|
||||
gorm.io/driver/mysql v1.0.4-0.20201206014609-ae5fd10184f6
|
||||
gorm.io/driver/postgres v1.0.6-0.20201208020313-1ed927cfab53
|
||||
|
||||
@@ -1,9 +1,6 @@
|
||||
package dto
|
||||
|
||||
import (
|
||||
"go-admin/app/{{.PackageName}}/models"
|
||||
"go-admin/common/dto"
|
||||
common "go-admin/common/models"
|
||||
|
||||
{{- $bb := false -}}
|
||||
{{- range .Columns -}}
|
||||
@@ -18,6 +15,10 @@ import (
|
||||
{{- if eq $bb true -}}
|
||||
"time"
|
||||
{{- end }}
|
||||
|
||||
"go-admin/app/{{.PackageName}}/models"
|
||||
"go-admin/common/dto"
|
||||
common "go-admin/common/models"
|
||||
)
|
||||
|
||||
type {{.ClassName}}GetPageReq struct {
|
||||
@@ -70,7 +71,8 @@ func (s *{{.ClassName}}InsertReq) Generate(model *models.{{.ClassName}}) {
|
||||
{{- else if eq .GoField "CreatedAt" -}}
|
||||
{{- else if eq .GoField "UpdatedAt" -}}
|
||||
{{- else if eq .GoField "DeletedAt" -}}
|
||||
{{- else if eq .GoField "CreateBy" -}}
|
||||
{{- else if eq .GoField "CreateBy"}}
|
||||
model.{{.GoField}} = s.{{.GoField}} // 添加这而,需要记录是被谁创建的
|
||||
{{- else if eq .GoField "UpdateBy" -}}
|
||||
{{- else }}
|
||||
model.{{.GoField}} = s.{{.GoField}}
|
||||
@@ -110,7 +112,8 @@ func (s *{{.ClassName}}UpdateReq) Generate(model *models.{{.ClassName}}) {
|
||||
{{- else if eq .GoField "UpdatedAt" -}}
|
||||
{{- else if eq .GoField "DeletedAt" -}}
|
||||
{{- else if eq .GoField "CreateBy" -}}
|
||||
{{- else if eq .GoField "UpdateBy" -}}
|
||||
{{- else if eq .GoField "UpdateBy"}}
|
||||
model.{{.GoField}} = s.{{.GoField}} // 添加这而,需要记录是被谁更新的
|
||||
{{- else }}
|
||||
model.{{.GoField}} = s.{{.GoField}}
|
||||
{{- end -}}
|
||||
|
||||
@@ -1,9 +1,23 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
// "gorm.io/gorm"
|
||||
|
||||
{{- $bb := false -}}
|
||||
{{- range .Columns -}}
|
||||
{{$z := .IsQuery}}
|
||||
{{- if ($z) }}
|
||||
{{if eq .GoType "time.Time"}}{{- $bb = true -}}{{- end -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
{{- range .Columns -}}
|
||||
{{if eq .GoType "time.Time"}}{{- $bb = true -}}{{- end -}}
|
||||
{{- end -}}
|
||||
{{- if eq $bb true -}}
|
||||
"time"
|
||||
{{- end }}
|
||||
|
||||
"go-admin/common/models"
|
||||
|
||||
)
|
||||
|
||||
type {{.ClassName}} struct {
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
|
||||
"go-admin/app/{{.PackageName}}/apis"
|
||||
"go-admin/common/middleware"
|
||||
"go-admin/common/actions"
|
||||
)
|
||||
|
||||
func init() {
|
||||
@@ -17,10 +18,10 @@ func register{{.ClassName}}Router(v1 *gin.RouterGroup, authMiddleware *jwt.GinJW
|
||||
api := apis.{{.ClassName}}{}
|
||||
r := v1.Group("/{{.ModuleName}}").Use(authMiddleware.MiddlewareFunc()).Use(middleware.AuthCheckRole())
|
||||
{
|
||||
r.GET("", api.GetPage)
|
||||
r.GET("/:id", api.Get)
|
||||
r.GET("", actions.PermissionAction(), api.GetPage)
|
||||
r.GET("/:id", actions.PermissionAction(), api.Get)
|
||||
r.POST("", api.Insert)
|
||||
r.PUT("/:id", api.Update)
|
||||
r.PUT("/:id", actions.PermissionAction(), api.Update)
|
||||
r.DELETE("", api.Delete)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user