作者 tangxvhui

新增

module gitlab.fjmaimaimai.com/mmm-go/partner
go 1.13
go 1.14
require (
github.com/ajg/form v1.5.1 // indirect
github.com/astaxie/beego v1.12.1
github.com/fasthttp-contrib/websocket v0.0.0-20160511215533-1f3b11f56072 // indirect
github.com/fatih/structs v1.1.0 // indirect
github.com/gavv/httpexpect v2.0.0+incompatible
github.com/go-pg/pg/v10 v10.0.0-beta.2
github.com/google/go-querystring v1.0.0 // indirect
github.com/gorilla/websocket v1.4.2 // indirect
github.com/imkira/go-interpol v1.1.0 // indirect
github.com/k0kubun/colorstring v0.0.0-20150214042306-9440f1994b88 // indirect
github.com/linmadan/egglib-go v0.0.0-20191217144343-ca4539f95bf9
github.com/mattn/go-colorable v0.1.6 // indirect
github.com/moul/http2curl v1.0.0 // indirect
github.com/onsi/ginkgo v1.10.3
github.com/onsi/gomega v1.7.1
github.com/sergi/go-diff v1.1.0 // indirect
github.com/shiena/ansicolor v0.0.0-20151119151921-a422bbe96644 // indirect
github.com/smartystreets/goconvey v1.6.4 // indirect
github.com/valyala/fasthttp v1.14.0 // indirect
github.com/xeipuuv/gojsonschema v1.2.0 // indirect
github.com/yalp/jsonpath v0.0.0-20180802001716-5cc68e5049a0 // indirect
github.com/yudai/gojsondiff v1.0.0 // indirect
github.com/yudai/golcs v0.0.0-20170316035057-ecda9a501e82 // indirect
github.com/yudai/pp v2.0.1+incompatible // indirect
)
replace gitlab.fjmaimaimai.com/mmm-go/partner => ../partner
... ...
package domain
//权限代码
const (
PERMINSSION_ADMIN_USER string = "ADMIN_USER"
PERMINSSION_PARTNER string = "PARTNER"
)
//权限数据
var ConstAdminPermissions = map[string]AdminPermission{
PERMINSSION_ADMIN_USER: AdminPermission{
Code: PERMINSSION_ADMIN_USER,
Name: "管理员管理",
},
PERMINSSION_PARTNER: AdminPermission{
Code: PERMINSSION_PARTNER,
Name: "合伙人管理",
},
}
// 权限结构
type AdminPermission struct {
Code string `json:"code"`
Name string `json:"name"`
}
func (permission AdminPermission) GetPermissions(codes []string) []AdminPermission {
newPermissions := []AdminPermission{}
if len(codes) == 0 {
return newPermissions
}
for i := range codes {
code := codes[i]
if _, ok := ConstAdminPermissions[code]; ok {
newPermissions = append(newPermissions, ConstAdminPermissions[code])
}
}
return newPermissions
}
... ...
package domain
//AdminUser 管理员
type AdminUser struct {
//id
Id int64 `json:"id"`
//账号
Account string `json:"account"`
//密码
Password string `json:"password"`
//管理员名称
AdminName string `json:"admin_name"`
//是否是默认系统账号
IsDefault bool `json:"is_default"`
//创建时间
CreateAt string `json:"create_at"`
//用户权限
Permission []string `json:"permission"`
}
type AdminUserFindQuery struct {
AccountLike string
Offset int
Limit int
}
type AdminUserFindOneQuery struct {
AdminUserId int64
AccountEqual string
}
type AdminUserRepository interface {
Save(*AdminUser) (*AdminUser, error)
Remove(user *AdminUser) (*AdminUser, error)
FindOne(qureyOptions AdminUserFindOneQuery) (*AdminUser, error)
Find(queryOptions AdminUserFindQuery) (int, []AdminUser, error)
}
... ...
package models
import (
"context"
"time"
"github.com/go-pg/pg/v10"
)
type AdminUser struct {
tableName struct{} `pg:"admin_user"`
//id
Id int64 `pg:",pk"`
//用户账号
AdminAccount string `pg:",unique"`
//用户名称
AdminName string
//账号密码
Password string
//是否是默认账号
IsDefault bool `pg:",use_zero"`
//删除时间
DeleteAt int64
CreateAt time.Time
UpdateAt time.Time
}
var _ pg.BeforeUpdateHook = (*AdminUser)(nil)
func (user *AdminUser) BeforeUpdate(ctx context.Context) (context.Context, error) {
user.UpdateAt = time.Now()
return ctx, nil
}
var _ pg.BeforeInsertHook = (*AdminUser)(nil)
func (user *AdminUser) BeforeInsert(ctx context.Context) (context.Context, error) {
user.CreateAt = time.Now()
user.UpdateAt = time.Now()
user.DeleteAt = 0
return ctx, nil
}
... ...
package models
import (
"gitlab.fjmaimaimai.com/mmm-go/partner/pkg/domain"
"time"
"gitlab.fjmaimaimai.com/mmm-go/partner/pkg/domain"
)
type PartnerInfo struct {
... ...
package middleware
import (
"github.com/astaxie/beego/context"
)
func PermissionCheck(permissionCode string, excludeUrl ...string) func(ctx *context.Context) {
return func(ctx *context.Context) {
//根据code检查权限数据,并排除excludeUrl指定的url
}
}
... ...
package routers
import (
"github.com/astaxie/beego"
"gitlab.fjmaimaimai.com/mmm-go/partner/pkg/domain"
"gitlab.fjmaimaimai.com/mmm-go/partner/pkg/port/beego/middleware"
)
func init() {
adminRouter := beego.NewNamespace("/admin_user",
//验证权限
beego.NSBefore(middleware.PermissionCheck(domain.PERMINSSION_ADMIN_USER)),
//其余的路由
//...
)
beego.AddNamespace(adminRouter)
}
... ...