认证授权主要流程实现
This commit is contained in:
@@ -36,7 +36,7 @@ func newAdmin(db *gorm.DB, opts ...gen.DOOption) admin {
|
||||
_admin.Email = field.NewString(tableName, "email")
|
||||
_admin.Status = field.NewInt32(tableName, "status")
|
||||
_admin.LastLogin = field.NewTime(tableName, "last_login")
|
||||
_admin.LastLoginAddr = field.NewString(tableName, "last_login_addr")
|
||||
_admin.LastLoginHost = field.NewString(tableName, "last_login_host")
|
||||
_admin.LastLoginAgent = field.NewString(tableName, "last_login_agent")
|
||||
_admin.CreatedAt = field.NewTime(tableName, "created_at")
|
||||
_admin.UpdatedAt = field.NewTime(tableName, "updated_at")
|
||||
@@ -60,7 +60,7 @@ type admin struct {
|
||||
Email field.String // 邮箱
|
||||
Status field.Int32 // 状态:1-正常,0-禁用
|
||||
LastLogin field.Time // 最后登录时间
|
||||
LastLoginAddr field.String // 最后登录地址
|
||||
LastLoginHost field.String // 最后登录地址
|
||||
LastLoginAgent field.String // 最后登录代理
|
||||
CreatedAt field.Time // 创建时间
|
||||
UpdatedAt field.Time // 更新时间
|
||||
@@ -90,7 +90,7 @@ func (a *admin) updateTableName(table string) *admin {
|
||||
a.Email = field.NewString(table, "email")
|
||||
a.Status = field.NewInt32(table, "status")
|
||||
a.LastLogin = field.NewTime(table, "last_login")
|
||||
a.LastLoginAddr = field.NewString(table, "last_login_addr")
|
||||
a.LastLoginHost = field.NewString(table, "last_login_host")
|
||||
a.LastLoginAgent = field.NewString(table, "last_login_agent")
|
||||
a.CreatedAt = field.NewTime(table, "created_at")
|
||||
a.UpdatedAt = field.NewTime(table, "updated_at")
|
||||
@@ -121,7 +121,7 @@ func (a *admin) fillFieldMap() {
|
||||
a.fieldMap["email"] = a.Email
|
||||
a.fieldMap["status"] = a.Status
|
||||
a.fieldMap["last_login"] = a.LastLogin
|
||||
a.fieldMap["last_login_addr"] = a.LastLoginAddr
|
||||
a.fieldMap["last_login_host"] = a.LastLoginHost
|
||||
a.fieldMap["last_login_agent"] = a.LastLoginAgent
|
||||
a.fieldMap["created_at"] = a.CreatedAt
|
||||
a.fieldMap["updated_at"] = a.UpdatedAt
|
||||
|
||||
@@ -30,7 +30,7 @@ func newChannel(db *gorm.DB, opts ...gen.DOOption) channel {
|
||||
_channel.ID = field.NewInt32(tableName, "id")
|
||||
_channel.UserID = field.NewInt32(tableName, "user_id")
|
||||
_channel.NodeID = field.NewInt32(tableName, "node_id")
|
||||
_channel.UserAddr = field.NewString(tableName, "user_addr")
|
||||
_channel.UserHost = field.NewString(tableName, "user_host")
|
||||
_channel.NodePort = field.NewInt32(tableName, "node_port")
|
||||
_channel.AuthIP = field.NewBool(tableName, "auth_ip")
|
||||
_channel.AuthPass = field.NewBool(tableName, "auth_pass")
|
||||
@@ -54,7 +54,7 @@ type channel struct {
|
||||
ID field.Int32 // 通道ID
|
||||
UserID field.Int32 // 用户ID
|
||||
NodeID field.Int32 // 节点ID
|
||||
UserAddr field.String // 用户地址
|
||||
UserHost field.String // 用户地址
|
||||
NodePort field.Int32 // 节点端口
|
||||
AuthIP field.Bool // IP认证
|
||||
AuthPass field.Bool // 密码认证
|
||||
@@ -84,7 +84,7 @@ func (c *channel) updateTableName(table string) *channel {
|
||||
c.ID = field.NewInt32(table, "id")
|
||||
c.UserID = field.NewInt32(table, "user_id")
|
||||
c.NodeID = field.NewInt32(table, "node_id")
|
||||
c.UserAddr = field.NewString(table, "user_addr")
|
||||
c.UserHost = field.NewString(table, "user_host")
|
||||
c.NodePort = field.NewInt32(table, "node_port")
|
||||
c.AuthIP = field.NewBool(table, "auth_ip")
|
||||
c.AuthPass = field.NewBool(table, "auth_pass")
|
||||
@@ -115,7 +115,7 @@ func (c *channel) fillFieldMap() {
|
||||
c.fieldMap["id"] = c.ID
|
||||
c.fieldMap["user_id"] = c.UserID
|
||||
c.fieldMap["node_id"] = c.NodeID
|
||||
c.fieldMap["user_addr"] = c.UserAddr
|
||||
c.fieldMap["user_host"] = c.UserHost
|
||||
c.fieldMap["node_port"] = c.NodePort
|
||||
c.fieldMap["auth_ip"] = c.AuthIP
|
||||
c.fieldMap["auth_pass"] = c.AuthPass
|
||||
|
||||
371
web/queries/client.gen.go
Normal file
371
web/queries/client.gen.go
Normal file
@@ -0,0 +1,371 @@
|
||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
||||
|
||||
package queries
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"gorm.io/gorm"
|
||||
"gorm.io/gorm/clause"
|
||||
"gorm.io/gorm/schema"
|
||||
|
||||
"gorm.io/gen"
|
||||
"gorm.io/gen/field"
|
||||
|
||||
"gorm.io/plugin/dbresolver"
|
||||
|
||||
"platform/web/models"
|
||||
)
|
||||
|
||||
func newClient(db *gorm.DB, opts ...gen.DOOption) client {
|
||||
_client := client{}
|
||||
|
||||
_client.clientDo.UseDB(db, opts...)
|
||||
_client.clientDo.UseModel(&models.Client{})
|
||||
|
||||
tableName := _client.clientDo.TableName()
|
||||
_client.ALL = field.NewAsterisk(tableName)
|
||||
_client.ID = field.NewInt32(tableName, "id")
|
||||
_client.ClientID = field.NewString(tableName, "client_id")
|
||||
_client.ClientSecret = field.NewString(tableName, "client_secret")
|
||||
_client.RedirectURI = field.NewString(tableName, "redirect_uri")
|
||||
_client.GrantCode = field.NewBool(tableName, "grant_code")
|
||||
_client.GrantClient = field.NewBool(tableName, "grant_client")
|
||||
_client.GrantRefresh = field.NewBool(tableName, "grant_refresh")
|
||||
_client.Spec = field.NewInt32(tableName, "spec")
|
||||
_client.Name = field.NewString(tableName, "name")
|
||||
_client.Version = field.NewInt32(tableName, "version")
|
||||
_client.Status = field.NewInt32(tableName, "status")
|
||||
_client.CreatedAt = field.NewTime(tableName, "created_at")
|
||||
_client.UpdatedAt = field.NewTime(tableName, "updated_at")
|
||||
_client.DeletedAt = field.NewField(tableName, "deleted_at")
|
||||
|
||||
_client.fillFieldMap()
|
||||
|
||||
return _client
|
||||
}
|
||||
|
||||
type client struct {
|
||||
clientDo
|
||||
|
||||
ALL field.Asterisk
|
||||
ID field.Int32 // 客户端ID
|
||||
ClientID field.String // OAuth2客户端标识符
|
||||
ClientSecret field.String // OAuth2客户端密钥
|
||||
RedirectURI field.String // OAuth2 重定向URI
|
||||
GrantCode field.Bool // 允许授权码授予
|
||||
GrantClient field.Bool // 允许客户端凭证授予
|
||||
GrantRefresh field.Bool // 允许刷新令牌授予
|
||||
Spec field.Int32 // 安全规范:0-web,1-native,2-browser
|
||||
Name field.String // 名称
|
||||
Version field.Int32 // 版本
|
||||
Status field.Int32 // 状态:1-正常,0-禁用
|
||||
CreatedAt field.Time // 创建时间
|
||||
UpdatedAt field.Time // 更新时间
|
||||
DeletedAt field.Field // 删除时间
|
||||
|
||||
fieldMap map[string]field.Expr
|
||||
}
|
||||
|
||||
func (c client) Table(newTableName string) *client {
|
||||
c.clientDo.UseTable(newTableName)
|
||||
return c.updateTableName(newTableName)
|
||||
}
|
||||
|
||||
func (c client) As(alias string) *client {
|
||||
c.clientDo.DO = *(c.clientDo.As(alias).(*gen.DO))
|
||||
return c.updateTableName(alias)
|
||||
}
|
||||
|
||||
func (c *client) updateTableName(table string) *client {
|
||||
c.ALL = field.NewAsterisk(table)
|
||||
c.ID = field.NewInt32(table, "id")
|
||||
c.ClientID = field.NewString(table, "client_id")
|
||||
c.ClientSecret = field.NewString(table, "client_secret")
|
||||
c.RedirectURI = field.NewString(table, "redirect_uri")
|
||||
c.GrantCode = field.NewBool(table, "grant_code")
|
||||
c.GrantClient = field.NewBool(table, "grant_client")
|
||||
c.GrantRefresh = field.NewBool(table, "grant_refresh")
|
||||
c.Spec = field.NewInt32(table, "spec")
|
||||
c.Name = field.NewString(table, "name")
|
||||
c.Version = field.NewInt32(table, "version")
|
||||
c.Status = field.NewInt32(table, "status")
|
||||
c.CreatedAt = field.NewTime(table, "created_at")
|
||||
c.UpdatedAt = field.NewTime(table, "updated_at")
|
||||
c.DeletedAt = field.NewField(table, "deleted_at")
|
||||
|
||||
c.fillFieldMap()
|
||||
|
||||
return c
|
||||
}
|
||||
|
||||
func (c *client) GetFieldByName(fieldName string) (field.OrderExpr, bool) {
|
||||
_f, ok := c.fieldMap[fieldName]
|
||||
if !ok || _f == nil {
|
||||
return nil, false
|
||||
}
|
||||
_oe, ok := _f.(field.OrderExpr)
|
||||
return _oe, ok
|
||||
}
|
||||
|
||||
func (c *client) fillFieldMap() {
|
||||
c.fieldMap = make(map[string]field.Expr, 14)
|
||||
c.fieldMap["id"] = c.ID
|
||||
c.fieldMap["client_id"] = c.ClientID
|
||||
c.fieldMap["client_secret"] = c.ClientSecret
|
||||
c.fieldMap["redirect_uri"] = c.RedirectURI
|
||||
c.fieldMap["grant_code"] = c.GrantCode
|
||||
c.fieldMap["grant_client"] = c.GrantClient
|
||||
c.fieldMap["grant_refresh"] = c.GrantRefresh
|
||||
c.fieldMap["spec"] = c.Spec
|
||||
c.fieldMap["name"] = c.Name
|
||||
c.fieldMap["version"] = c.Version
|
||||
c.fieldMap["status"] = c.Status
|
||||
c.fieldMap["created_at"] = c.CreatedAt
|
||||
c.fieldMap["updated_at"] = c.UpdatedAt
|
||||
c.fieldMap["deleted_at"] = c.DeletedAt
|
||||
}
|
||||
|
||||
func (c client) clone(db *gorm.DB) client {
|
||||
c.clientDo.ReplaceConnPool(db.Statement.ConnPool)
|
||||
return c
|
||||
}
|
||||
|
||||
func (c client) replaceDB(db *gorm.DB) client {
|
||||
c.clientDo.ReplaceDB(db)
|
||||
return c
|
||||
}
|
||||
|
||||
type clientDo struct{ gen.DO }
|
||||
|
||||
func (c clientDo) Debug() *clientDo {
|
||||
return c.withDO(c.DO.Debug())
|
||||
}
|
||||
|
||||
func (c clientDo) WithContext(ctx context.Context) *clientDo {
|
||||
return c.withDO(c.DO.WithContext(ctx))
|
||||
}
|
||||
|
||||
func (c clientDo) ReadDB() *clientDo {
|
||||
return c.Clauses(dbresolver.Read)
|
||||
}
|
||||
|
||||
func (c clientDo) WriteDB() *clientDo {
|
||||
return c.Clauses(dbresolver.Write)
|
||||
}
|
||||
|
||||
func (c clientDo) Session(config *gorm.Session) *clientDo {
|
||||
return c.withDO(c.DO.Session(config))
|
||||
}
|
||||
|
||||
func (c clientDo) Clauses(conds ...clause.Expression) *clientDo {
|
||||
return c.withDO(c.DO.Clauses(conds...))
|
||||
}
|
||||
|
||||
func (c clientDo) Returning(value interface{}, columns ...string) *clientDo {
|
||||
return c.withDO(c.DO.Returning(value, columns...))
|
||||
}
|
||||
|
||||
func (c clientDo) Not(conds ...gen.Condition) *clientDo {
|
||||
return c.withDO(c.DO.Not(conds...))
|
||||
}
|
||||
|
||||
func (c clientDo) Or(conds ...gen.Condition) *clientDo {
|
||||
return c.withDO(c.DO.Or(conds...))
|
||||
}
|
||||
|
||||
func (c clientDo) Select(conds ...field.Expr) *clientDo {
|
||||
return c.withDO(c.DO.Select(conds...))
|
||||
}
|
||||
|
||||
func (c clientDo) Where(conds ...gen.Condition) *clientDo {
|
||||
return c.withDO(c.DO.Where(conds...))
|
||||
}
|
||||
|
||||
func (c clientDo) Order(conds ...field.Expr) *clientDo {
|
||||
return c.withDO(c.DO.Order(conds...))
|
||||
}
|
||||
|
||||
func (c clientDo) Distinct(cols ...field.Expr) *clientDo {
|
||||
return c.withDO(c.DO.Distinct(cols...))
|
||||
}
|
||||
|
||||
func (c clientDo) Omit(cols ...field.Expr) *clientDo {
|
||||
return c.withDO(c.DO.Omit(cols...))
|
||||
}
|
||||
|
||||
func (c clientDo) Join(table schema.Tabler, on ...field.Expr) *clientDo {
|
||||
return c.withDO(c.DO.Join(table, on...))
|
||||
}
|
||||
|
||||
func (c clientDo) LeftJoin(table schema.Tabler, on ...field.Expr) *clientDo {
|
||||
return c.withDO(c.DO.LeftJoin(table, on...))
|
||||
}
|
||||
|
||||
func (c clientDo) RightJoin(table schema.Tabler, on ...field.Expr) *clientDo {
|
||||
return c.withDO(c.DO.RightJoin(table, on...))
|
||||
}
|
||||
|
||||
func (c clientDo) Group(cols ...field.Expr) *clientDo {
|
||||
return c.withDO(c.DO.Group(cols...))
|
||||
}
|
||||
|
||||
func (c clientDo) Having(conds ...gen.Condition) *clientDo {
|
||||
return c.withDO(c.DO.Having(conds...))
|
||||
}
|
||||
|
||||
func (c clientDo) Limit(limit int) *clientDo {
|
||||
return c.withDO(c.DO.Limit(limit))
|
||||
}
|
||||
|
||||
func (c clientDo) Offset(offset int) *clientDo {
|
||||
return c.withDO(c.DO.Offset(offset))
|
||||
}
|
||||
|
||||
func (c clientDo) Scopes(funcs ...func(gen.Dao) gen.Dao) *clientDo {
|
||||
return c.withDO(c.DO.Scopes(funcs...))
|
||||
}
|
||||
|
||||
func (c clientDo) Unscoped() *clientDo {
|
||||
return c.withDO(c.DO.Unscoped())
|
||||
}
|
||||
|
||||
func (c clientDo) Create(values ...*models.Client) error {
|
||||
if len(values) == 0 {
|
||||
return nil
|
||||
}
|
||||
return c.DO.Create(values)
|
||||
}
|
||||
|
||||
func (c clientDo) CreateInBatches(values []*models.Client, batchSize int) error {
|
||||
return c.DO.CreateInBatches(values, batchSize)
|
||||
}
|
||||
|
||||
// Save : !!! underlying implementation is different with GORM
|
||||
// The method is equivalent to executing the statement: db.Clauses(clause.OnConflict{UpdateAll: true}).Create(values)
|
||||
func (c clientDo) Save(values ...*models.Client) error {
|
||||
if len(values) == 0 {
|
||||
return nil
|
||||
}
|
||||
return c.DO.Save(values)
|
||||
}
|
||||
|
||||
func (c clientDo) First() (*models.Client, error) {
|
||||
if result, err := c.DO.First(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*models.Client), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (c clientDo) Take() (*models.Client, error) {
|
||||
if result, err := c.DO.Take(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*models.Client), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (c clientDo) Last() (*models.Client, error) {
|
||||
if result, err := c.DO.Last(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*models.Client), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (c clientDo) Find() ([]*models.Client, error) {
|
||||
result, err := c.DO.Find()
|
||||
return result.([]*models.Client), err
|
||||
}
|
||||
|
||||
func (c clientDo) FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*models.Client, err error) {
|
||||
buf := make([]*models.Client, 0, batchSize)
|
||||
err = c.DO.FindInBatches(&buf, batchSize, func(tx gen.Dao, batch int) error {
|
||||
defer func() { results = append(results, buf...) }()
|
||||
return fc(tx, batch)
|
||||
})
|
||||
return results, err
|
||||
}
|
||||
|
||||
func (c clientDo) FindInBatches(result *[]*models.Client, batchSize int, fc func(tx gen.Dao, batch int) error) error {
|
||||
return c.DO.FindInBatches(result, batchSize, fc)
|
||||
}
|
||||
|
||||
func (c clientDo) Attrs(attrs ...field.AssignExpr) *clientDo {
|
||||
return c.withDO(c.DO.Attrs(attrs...))
|
||||
}
|
||||
|
||||
func (c clientDo) Assign(attrs ...field.AssignExpr) *clientDo {
|
||||
return c.withDO(c.DO.Assign(attrs...))
|
||||
}
|
||||
|
||||
func (c clientDo) Joins(fields ...field.RelationField) *clientDo {
|
||||
for _, _f := range fields {
|
||||
c = *c.withDO(c.DO.Joins(_f))
|
||||
}
|
||||
return &c
|
||||
}
|
||||
|
||||
func (c clientDo) Preload(fields ...field.RelationField) *clientDo {
|
||||
for _, _f := range fields {
|
||||
c = *c.withDO(c.DO.Preload(_f))
|
||||
}
|
||||
return &c
|
||||
}
|
||||
|
||||
func (c clientDo) FirstOrInit() (*models.Client, error) {
|
||||
if result, err := c.DO.FirstOrInit(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*models.Client), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (c clientDo) FirstOrCreate() (*models.Client, error) {
|
||||
if result, err := c.DO.FirstOrCreate(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*models.Client), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (c clientDo) FindByPage(offset int, limit int) (result []*models.Client, count int64, err error) {
|
||||
result, err = c.Offset(offset).Limit(limit).Find()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
if size := len(result); 0 < limit && 0 < size && size < limit {
|
||||
count = int64(size + offset)
|
||||
return
|
||||
}
|
||||
|
||||
count, err = c.Offset(-1).Limit(-1).Count()
|
||||
return
|
||||
}
|
||||
|
||||
func (c clientDo) ScanByPage(result interface{}, offset int, limit int) (count int64, err error) {
|
||||
count, err = c.Count()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
err = c.Offset(offset).Limit(limit).Scan(result)
|
||||
return
|
||||
}
|
||||
|
||||
func (c clientDo) Scan(result interface{}) (err error) {
|
||||
return c.DO.Scan(result)
|
||||
}
|
||||
|
||||
func (c clientDo) Delete(models ...*models.Client) (result gen.ResultInfo, err error) {
|
||||
return c.DO.Delete(models)
|
||||
}
|
||||
|
||||
func (c *clientDo) withDO(do gen.Dao) *clientDo {
|
||||
c.DO = *do.(*gen.DO)
|
||||
return c
|
||||
}
|
||||
339
web/queries/client_permission_link.gen.go
Normal file
339
web/queries/client_permission_link.gen.go
Normal file
@@ -0,0 +1,339 @@
|
||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
||||
|
||||
package queries
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"gorm.io/gorm"
|
||||
"gorm.io/gorm/clause"
|
||||
"gorm.io/gorm/schema"
|
||||
|
||||
"gorm.io/gen"
|
||||
"gorm.io/gen/field"
|
||||
|
||||
"gorm.io/plugin/dbresolver"
|
||||
|
||||
"platform/web/models"
|
||||
)
|
||||
|
||||
func newClientPermissionLink(db *gorm.DB, opts ...gen.DOOption) clientPermissionLink {
|
||||
_clientPermissionLink := clientPermissionLink{}
|
||||
|
||||
_clientPermissionLink.clientPermissionLinkDo.UseDB(db, opts...)
|
||||
_clientPermissionLink.clientPermissionLinkDo.UseModel(&models.ClientPermissionLink{})
|
||||
|
||||
tableName := _clientPermissionLink.clientPermissionLinkDo.TableName()
|
||||
_clientPermissionLink.ALL = field.NewAsterisk(tableName)
|
||||
_clientPermissionLink.ID = field.NewInt32(tableName, "id")
|
||||
_clientPermissionLink.ClientID = field.NewInt32(tableName, "client_id")
|
||||
_clientPermissionLink.PermissionID = field.NewInt32(tableName, "permission_id")
|
||||
_clientPermissionLink.CreatedAt = field.NewTime(tableName, "created_at")
|
||||
_clientPermissionLink.UpdatedAt = field.NewTime(tableName, "updated_at")
|
||||
_clientPermissionLink.DeletedAt = field.NewField(tableName, "deleted_at")
|
||||
|
||||
_clientPermissionLink.fillFieldMap()
|
||||
|
||||
return _clientPermissionLink
|
||||
}
|
||||
|
||||
type clientPermissionLink struct {
|
||||
clientPermissionLinkDo
|
||||
|
||||
ALL field.Asterisk
|
||||
ID field.Int32 // 关联ID
|
||||
ClientID field.Int32 // 客户端ID
|
||||
PermissionID field.Int32 // 权限ID
|
||||
CreatedAt field.Time // 创建时间
|
||||
UpdatedAt field.Time // 更新时间
|
||||
DeletedAt field.Field // 删除时间
|
||||
|
||||
fieldMap map[string]field.Expr
|
||||
}
|
||||
|
||||
func (c clientPermissionLink) Table(newTableName string) *clientPermissionLink {
|
||||
c.clientPermissionLinkDo.UseTable(newTableName)
|
||||
return c.updateTableName(newTableName)
|
||||
}
|
||||
|
||||
func (c clientPermissionLink) As(alias string) *clientPermissionLink {
|
||||
c.clientPermissionLinkDo.DO = *(c.clientPermissionLinkDo.As(alias).(*gen.DO))
|
||||
return c.updateTableName(alias)
|
||||
}
|
||||
|
||||
func (c *clientPermissionLink) updateTableName(table string) *clientPermissionLink {
|
||||
c.ALL = field.NewAsterisk(table)
|
||||
c.ID = field.NewInt32(table, "id")
|
||||
c.ClientID = field.NewInt32(table, "client_id")
|
||||
c.PermissionID = field.NewInt32(table, "permission_id")
|
||||
c.CreatedAt = field.NewTime(table, "created_at")
|
||||
c.UpdatedAt = field.NewTime(table, "updated_at")
|
||||
c.DeletedAt = field.NewField(table, "deleted_at")
|
||||
|
||||
c.fillFieldMap()
|
||||
|
||||
return c
|
||||
}
|
||||
|
||||
func (c *clientPermissionLink) GetFieldByName(fieldName string) (field.OrderExpr, bool) {
|
||||
_f, ok := c.fieldMap[fieldName]
|
||||
if !ok || _f == nil {
|
||||
return nil, false
|
||||
}
|
||||
_oe, ok := _f.(field.OrderExpr)
|
||||
return _oe, ok
|
||||
}
|
||||
|
||||
func (c *clientPermissionLink) fillFieldMap() {
|
||||
c.fieldMap = make(map[string]field.Expr, 6)
|
||||
c.fieldMap["id"] = c.ID
|
||||
c.fieldMap["client_id"] = c.ClientID
|
||||
c.fieldMap["permission_id"] = c.PermissionID
|
||||
c.fieldMap["created_at"] = c.CreatedAt
|
||||
c.fieldMap["updated_at"] = c.UpdatedAt
|
||||
c.fieldMap["deleted_at"] = c.DeletedAt
|
||||
}
|
||||
|
||||
func (c clientPermissionLink) clone(db *gorm.DB) clientPermissionLink {
|
||||
c.clientPermissionLinkDo.ReplaceConnPool(db.Statement.ConnPool)
|
||||
return c
|
||||
}
|
||||
|
||||
func (c clientPermissionLink) replaceDB(db *gorm.DB) clientPermissionLink {
|
||||
c.clientPermissionLinkDo.ReplaceDB(db)
|
||||
return c
|
||||
}
|
||||
|
||||
type clientPermissionLinkDo struct{ gen.DO }
|
||||
|
||||
func (c clientPermissionLinkDo) Debug() *clientPermissionLinkDo {
|
||||
return c.withDO(c.DO.Debug())
|
||||
}
|
||||
|
||||
func (c clientPermissionLinkDo) WithContext(ctx context.Context) *clientPermissionLinkDo {
|
||||
return c.withDO(c.DO.WithContext(ctx))
|
||||
}
|
||||
|
||||
func (c clientPermissionLinkDo) ReadDB() *clientPermissionLinkDo {
|
||||
return c.Clauses(dbresolver.Read)
|
||||
}
|
||||
|
||||
func (c clientPermissionLinkDo) WriteDB() *clientPermissionLinkDo {
|
||||
return c.Clauses(dbresolver.Write)
|
||||
}
|
||||
|
||||
func (c clientPermissionLinkDo) Session(config *gorm.Session) *clientPermissionLinkDo {
|
||||
return c.withDO(c.DO.Session(config))
|
||||
}
|
||||
|
||||
func (c clientPermissionLinkDo) Clauses(conds ...clause.Expression) *clientPermissionLinkDo {
|
||||
return c.withDO(c.DO.Clauses(conds...))
|
||||
}
|
||||
|
||||
func (c clientPermissionLinkDo) Returning(value interface{}, columns ...string) *clientPermissionLinkDo {
|
||||
return c.withDO(c.DO.Returning(value, columns...))
|
||||
}
|
||||
|
||||
func (c clientPermissionLinkDo) Not(conds ...gen.Condition) *clientPermissionLinkDo {
|
||||
return c.withDO(c.DO.Not(conds...))
|
||||
}
|
||||
|
||||
func (c clientPermissionLinkDo) Or(conds ...gen.Condition) *clientPermissionLinkDo {
|
||||
return c.withDO(c.DO.Or(conds...))
|
||||
}
|
||||
|
||||
func (c clientPermissionLinkDo) Select(conds ...field.Expr) *clientPermissionLinkDo {
|
||||
return c.withDO(c.DO.Select(conds...))
|
||||
}
|
||||
|
||||
func (c clientPermissionLinkDo) Where(conds ...gen.Condition) *clientPermissionLinkDo {
|
||||
return c.withDO(c.DO.Where(conds...))
|
||||
}
|
||||
|
||||
func (c clientPermissionLinkDo) Order(conds ...field.Expr) *clientPermissionLinkDo {
|
||||
return c.withDO(c.DO.Order(conds...))
|
||||
}
|
||||
|
||||
func (c clientPermissionLinkDo) Distinct(cols ...field.Expr) *clientPermissionLinkDo {
|
||||
return c.withDO(c.DO.Distinct(cols...))
|
||||
}
|
||||
|
||||
func (c clientPermissionLinkDo) Omit(cols ...field.Expr) *clientPermissionLinkDo {
|
||||
return c.withDO(c.DO.Omit(cols...))
|
||||
}
|
||||
|
||||
func (c clientPermissionLinkDo) Join(table schema.Tabler, on ...field.Expr) *clientPermissionLinkDo {
|
||||
return c.withDO(c.DO.Join(table, on...))
|
||||
}
|
||||
|
||||
func (c clientPermissionLinkDo) LeftJoin(table schema.Tabler, on ...field.Expr) *clientPermissionLinkDo {
|
||||
return c.withDO(c.DO.LeftJoin(table, on...))
|
||||
}
|
||||
|
||||
func (c clientPermissionLinkDo) RightJoin(table schema.Tabler, on ...field.Expr) *clientPermissionLinkDo {
|
||||
return c.withDO(c.DO.RightJoin(table, on...))
|
||||
}
|
||||
|
||||
func (c clientPermissionLinkDo) Group(cols ...field.Expr) *clientPermissionLinkDo {
|
||||
return c.withDO(c.DO.Group(cols...))
|
||||
}
|
||||
|
||||
func (c clientPermissionLinkDo) Having(conds ...gen.Condition) *clientPermissionLinkDo {
|
||||
return c.withDO(c.DO.Having(conds...))
|
||||
}
|
||||
|
||||
func (c clientPermissionLinkDo) Limit(limit int) *clientPermissionLinkDo {
|
||||
return c.withDO(c.DO.Limit(limit))
|
||||
}
|
||||
|
||||
func (c clientPermissionLinkDo) Offset(offset int) *clientPermissionLinkDo {
|
||||
return c.withDO(c.DO.Offset(offset))
|
||||
}
|
||||
|
||||
func (c clientPermissionLinkDo) Scopes(funcs ...func(gen.Dao) gen.Dao) *clientPermissionLinkDo {
|
||||
return c.withDO(c.DO.Scopes(funcs...))
|
||||
}
|
||||
|
||||
func (c clientPermissionLinkDo) Unscoped() *clientPermissionLinkDo {
|
||||
return c.withDO(c.DO.Unscoped())
|
||||
}
|
||||
|
||||
func (c clientPermissionLinkDo) Create(values ...*models.ClientPermissionLink) error {
|
||||
if len(values) == 0 {
|
||||
return nil
|
||||
}
|
||||
return c.DO.Create(values)
|
||||
}
|
||||
|
||||
func (c clientPermissionLinkDo) CreateInBatches(values []*models.ClientPermissionLink, batchSize int) error {
|
||||
return c.DO.CreateInBatches(values, batchSize)
|
||||
}
|
||||
|
||||
// Save : !!! underlying implementation is different with GORM
|
||||
// The method is equivalent to executing the statement: db.Clauses(clause.OnConflict{UpdateAll: true}).Create(values)
|
||||
func (c clientPermissionLinkDo) Save(values ...*models.ClientPermissionLink) error {
|
||||
if len(values) == 0 {
|
||||
return nil
|
||||
}
|
||||
return c.DO.Save(values)
|
||||
}
|
||||
|
||||
func (c clientPermissionLinkDo) First() (*models.ClientPermissionLink, error) {
|
||||
if result, err := c.DO.First(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*models.ClientPermissionLink), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (c clientPermissionLinkDo) Take() (*models.ClientPermissionLink, error) {
|
||||
if result, err := c.DO.Take(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*models.ClientPermissionLink), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (c clientPermissionLinkDo) Last() (*models.ClientPermissionLink, error) {
|
||||
if result, err := c.DO.Last(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*models.ClientPermissionLink), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (c clientPermissionLinkDo) Find() ([]*models.ClientPermissionLink, error) {
|
||||
result, err := c.DO.Find()
|
||||
return result.([]*models.ClientPermissionLink), err
|
||||
}
|
||||
|
||||
func (c clientPermissionLinkDo) FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*models.ClientPermissionLink, err error) {
|
||||
buf := make([]*models.ClientPermissionLink, 0, batchSize)
|
||||
err = c.DO.FindInBatches(&buf, batchSize, func(tx gen.Dao, batch int) error {
|
||||
defer func() { results = append(results, buf...) }()
|
||||
return fc(tx, batch)
|
||||
})
|
||||
return results, err
|
||||
}
|
||||
|
||||
func (c clientPermissionLinkDo) FindInBatches(result *[]*models.ClientPermissionLink, batchSize int, fc func(tx gen.Dao, batch int) error) error {
|
||||
return c.DO.FindInBatches(result, batchSize, fc)
|
||||
}
|
||||
|
||||
func (c clientPermissionLinkDo) Attrs(attrs ...field.AssignExpr) *clientPermissionLinkDo {
|
||||
return c.withDO(c.DO.Attrs(attrs...))
|
||||
}
|
||||
|
||||
func (c clientPermissionLinkDo) Assign(attrs ...field.AssignExpr) *clientPermissionLinkDo {
|
||||
return c.withDO(c.DO.Assign(attrs...))
|
||||
}
|
||||
|
||||
func (c clientPermissionLinkDo) Joins(fields ...field.RelationField) *clientPermissionLinkDo {
|
||||
for _, _f := range fields {
|
||||
c = *c.withDO(c.DO.Joins(_f))
|
||||
}
|
||||
return &c
|
||||
}
|
||||
|
||||
func (c clientPermissionLinkDo) Preload(fields ...field.RelationField) *clientPermissionLinkDo {
|
||||
for _, _f := range fields {
|
||||
c = *c.withDO(c.DO.Preload(_f))
|
||||
}
|
||||
return &c
|
||||
}
|
||||
|
||||
func (c clientPermissionLinkDo) FirstOrInit() (*models.ClientPermissionLink, error) {
|
||||
if result, err := c.DO.FirstOrInit(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*models.ClientPermissionLink), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (c clientPermissionLinkDo) FirstOrCreate() (*models.ClientPermissionLink, error) {
|
||||
if result, err := c.DO.FirstOrCreate(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*models.ClientPermissionLink), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (c clientPermissionLinkDo) FindByPage(offset int, limit int) (result []*models.ClientPermissionLink, count int64, err error) {
|
||||
result, err = c.Offset(offset).Limit(limit).Find()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
if size := len(result); 0 < limit && 0 < size && size < limit {
|
||||
count = int64(size + offset)
|
||||
return
|
||||
}
|
||||
|
||||
count, err = c.Offset(-1).Limit(-1).Count()
|
||||
return
|
||||
}
|
||||
|
||||
func (c clientPermissionLinkDo) ScanByPage(result interface{}, offset int, limit int) (count int64, err error) {
|
||||
count, err = c.Count()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
err = c.Offset(offset).Limit(limit).Scan(result)
|
||||
return
|
||||
}
|
||||
|
||||
func (c clientPermissionLinkDo) Scan(result interface{}) (err error) {
|
||||
return c.DO.Scan(result)
|
||||
}
|
||||
|
||||
func (c clientPermissionLinkDo) Delete(models ...*models.ClientPermissionLink) (result gen.ResultInfo, err error) {
|
||||
return c.DO.Delete(models)
|
||||
}
|
||||
|
||||
func (c *clientPermissionLinkDo) withDO(do gen.Dao) *clientPermissionLinkDo {
|
||||
c.DO = *do.(*gen.DO)
|
||||
return c
|
||||
}
|
||||
@@ -23,6 +23,8 @@ var (
|
||||
AdminRolePermissionLink *adminRolePermissionLink
|
||||
Bill *bill
|
||||
Channel *channel
|
||||
Client *client
|
||||
ClientPermissionLink *clientPermissionLink
|
||||
Node *node
|
||||
Permission *permission
|
||||
Product *product
|
||||
@@ -47,6 +49,8 @@ func SetDefault(db *gorm.DB, opts ...gen.DOOption) {
|
||||
AdminRolePermissionLink = &Q.AdminRolePermissionLink
|
||||
Bill = &Q.Bill
|
||||
Channel = &Q.Channel
|
||||
Client = &Q.Client
|
||||
ClientPermissionLink = &Q.ClientPermissionLink
|
||||
Node = &Q.Node
|
||||
Permission = &Q.Permission
|
||||
Product = &Q.Product
|
||||
@@ -72,6 +76,8 @@ func Use(db *gorm.DB, opts ...gen.DOOption) *Query {
|
||||
AdminRolePermissionLink: newAdminRolePermissionLink(db, opts...),
|
||||
Bill: newBill(db, opts...),
|
||||
Channel: newChannel(db, opts...),
|
||||
Client: newClient(db, opts...),
|
||||
ClientPermissionLink: newClientPermissionLink(db, opts...),
|
||||
Node: newNode(db, opts...),
|
||||
Permission: newPermission(db, opts...),
|
||||
Product: newProduct(db, opts...),
|
||||
@@ -98,6 +104,8 @@ type Query struct {
|
||||
AdminRolePermissionLink adminRolePermissionLink
|
||||
Bill bill
|
||||
Channel channel
|
||||
Client client
|
||||
ClientPermissionLink clientPermissionLink
|
||||
Node node
|
||||
Permission permission
|
||||
Product product
|
||||
@@ -125,6 +133,8 @@ func (q *Query) clone(db *gorm.DB) *Query {
|
||||
AdminRolePermissionLink: q.AdminRolePermissionLink.clone(db),
|
||||
Bill: q.Bill.clone(db),
|
||||
Channel: q.Channel.clone(db),
|
||||
Client: q.Client.clone(db),
|
||||
ClientPermissionLink: q.ClientPermissionLink.clone(db),
|
||||
Node: q.Node.clone(db),
|
||||
Permission: q.Permission.clone(db),
|
||||
Product: q.Product.clone(db),
|
||||
@@ -159,6 +169,8 @@ func (q *Query) ReplaceDB(db *gorm.DB) *Query {
|
||||
AdminRolePermissionLink: q.AdminRolePermissionLink.replaceDB(db),
|
||||
Bill: q.Bill.replaceDB(db),
|
||||
Channel: q.Channel.replaceDB(db),
|
||||
Client: q.Client.replaceDB(db),
|
||||
ClientPermissionLink: q.ClientPermissionLink.replaceDB(db),
|
||||
Node: q.Node.replaceDB(db),
|
||||
Permission: q.Permission.replaceDB(db),
|
||||
Product: q.Product.replaceDB(db),
|
||||
@@ -183,6 +195,8 @@ type queryCtx struct {
|
||||
AdminRolePermissionLink *adminRolePermissionLinkDo
|
||||
Bill *billDo
|
||||
Channel *channelDo
|
||||
Client *clientDo
|
||||
ClientPermissionLink *clientPermissionLinkDo
|
||||
Node *nodeDo
|
||||
Permission *permissionDo
|
||||
Product *productDo
|
||||
@@ -207,6 +221,8 @@ func (q *Query) WithContext(ctx context.Context) *queryCtx {
|
||||
AdminRolePermissionLink: q.AdminRolePermissionLink.WithContext(ctx),
|
||||
Bill: q.Bill.WithContext(ctx),
|
||||
Channel: q.Channel.WithContext(ctx),
|
||||
Client: q.Client.WithContext(ctx),
|
||||
ClientPermissionLink: q.ClientPermissionLink.WithContext(ctx),
|
||||
Node: q.Node.WithContext(ctx),
|
||||
Permission: q.Permission.WithContext(ctx),
|
||||
Product: q.Product.WithContext(ctx),
|
||||
|
||||
@@ -43,7 +43,7 @@ func newUser(db *gorm.DB, opts ...gen.DOOption) user {
|
||||
_user.ContactQq = field.NewString(tableName, "contact_qq")
|
||||
_user.ContactWechat = field.NewString(tableName, "contact_wechat")
|
||||
_user.LastLogin = field.NewTime(tableName, "last_login")
|
||||
_user.LastLoginAddr = field.NewString(tableName, "last_login_addr")
|
||||
_user.LastLoginHost = field.NewString(tableName, "last_login_host")
|
||||
_user.LastLoginAgent = field.NewString(tableName, "last_login_agent")
|
||||
_user.CreatedAt = field.NewTime(tableName, "created_at")
|
||||
_user.UpdatedAt = field.NewTime(tableName, "updated_at")
|
||||
@@ -58,27 +58,27 @@ type user struct {
|
||||
userDo
|
||||
|
||||
ALL field.Asterisk
|
||||
ID field.Int32
|
||||
AdminID field.Int32
|
||||
Phone field.String
|
||||
Username field.String
|
||||
ID field.Int32 // 用户ID
|
||||
AdminID field.Int32 // 管理员ID
|
||||
Phone field.String // 手机号码
|
||||
Username field.String // 用户名
|
||||
Email field.String
|
||||
Password field.String
|
||||
Name field.String
|
||||
Avatar field.String
|
||||
Status field.Int32
|
||||
Balance field.Float64
|
||||
IDType field.Int32
|
||||
IDNo field.String
|
||||
IDToken field.String
|
||||
ContactQq field.String
|
||||
ContactWechat field.String
|
||||
LastLogin field.Time
|
||||
LastLoginAddr field.String
|
||||
LastLoginAgent field.String
|
||||
CreatedAt field.Time
|
||||
UpdatedAt field.Time
|
||||
DeletedAt field.Field
|
||||
Password field.String // 用户密码
|
||||
Name field.String // 真实姓名
|
||||
Avatar field.String // 头像URL
|
||||
Status field.Int32 // 用户状态:1-正常,0-禁用
|
||||
Balance field.Float64 // 账户余额
|
||||
IDType field.Int32 // 认证类型:0-未认证,1-个人认证,2-企业认证
|
||||
IDNo field.String // 身份证号或营业执照号
|
||||
IDToken field.String // 身份验证标识
|
||||
ContactQq field.String // QQ联系方式
|
||||
ContactWechat field.String // 微信联系方式
|
||||
LastLogin field.Time // 最后登录时间
|
||||
LastLoginHost field.String // 最后登录地址
|
||||
LastLoginAgent field.String // 最后登录代理
|
||||
CreatedAt field.Time // 创建时间
|
||||
UpdatedAt field.Time // 更新时间
|
||||
DeletedAt field.Field // 删除时间
|
||||
|
||||
fieldMap map[string]field.Expr
|
||||
}
|
||||
@@ -111,7 +111,7 @@ func (u *user) updateTableName(table string) *user {
|
||||
u.ContactQq = field.NewString(table, "contact_qq")
|
||||
u.ContactWechat = field.NewString(table, "contact_wechat")
|
||||
u.LastLogin = field.NewTime(table, "last_login")
|
||||
u.LastLoginAddr = field.NewString(table, "last_login_addr")
|
||||
u.LastLoginHost = field.NewString(table, "last_login_host")
|
||||
u.LastLoginAgent = field.NewString(table, "last_login_agent")
|
||||
u.CreatedAt = field.NewTime(table, "created_at")
|
||||
u.UpdatedAt = field.NewTime(table, "updated_at")
|
||||
@@ -149,7 +149,7 @@ func (u *user) fillFieldMap() {
|
||||
u.fieldMap["contact_qq"] = u.ContactQq
|
||||
u.fieldMap["contact_wechat"] = u.ContactWechat
|
||||
u.fieldMap["last_login"] = u.LastLogin
|
||||
u.fieldMap["last_login_addr"] = u.LastLoginAddr
|
||||
u.fieldMap["last_login_host"] = u.LastLoginHost
|
||||
u.fieldMap["last_login_agent"] = u.LastLoginAgent
|
||||
u.fieldMap["created_at"] = u.CreatedAt
|
||||
u.fieldMap["updated_at"] = u.UpdatedAt
|
||||
|
||||
@@ -29,7 +29,7 @@ func newWhitelist(db *gorm.DB, opts ...gen.DOOption) whitelist {
|
||||
_whitelist.ALL = field.NewAsterisk(tableName)
|
||||
_whitelist.ID = field.NewInt32(tableName, "id")
|
||||
_whitelist.UserID = field.NewInt32(tableName, "user_id")
|
||||
_whitelist.Address = field.NewString(tableName, "address")
|
||||
_whitelist.Host = field.NewString(tableName, "host")
|
||||
_whitelist.CreatedAt = field.NewTime(tableName, "created_at")
|
||||
_whitelist.UpdatedAt = field.NewTime(tableName, "updated_at")
|
||||
_whitelist.DeletedAt = field.NewField(tableName, "deleted_at")
|
||||
@@ -45,7 +45,7 @@ type whitelist struct {
|
||||
ALL field.Asterisk
|
||||
ID field.Int32 // 白名单ID
|
||||
UserID field.Int32 // 用户ID
|
||||
Address field.String // IP地址
|
||||
Host field.String // IP地址
|
||||
CreatedAt field.Time // 创建时间
|
||||
UpdatedAt field.Time // 更新时间
|
||||
DeletedAt field.Field // 删除时间
|
||||
@@ -67,7 +67,7 @@ func (w *whitelist) updateTableName(table string) *whitelist {
|
||||
w.ALL = field.NewAsterisk(table)
|
||||
w.ID = field.NewInt32(table, "id")
|
||||
w.UserID = field.NewInt32(table, "user_id")
|
||||
w.Address = field.NewString(table, "address")
|
||||
w.Host = field.NewString(table, "host")
|
||||
w.CreatedAt = field.NewTime(table, "created_at")
|
||||
w.UpdatedAt = field.NewTime(table, "updated_at")
|
||||
w.DeletedAt = field.NewField(table, "deleted_at")
|
||||
@@ -90,7 +90,7 @@ func (w *whitelist) fillFieldMap() {
|
||||
w.fieldMap = make(map[string]field.Expr, 6)
|
||||
w.fieldMap["id"] = w.ID
|
||||
w.fieldMap["user_id"] = w.UserID
|
||||
w.fieldMap["address"] = w.Address
|
||||
w.fieldMap["host"] = w.Host
|
||||
w.fieldMap["created_at"] = w.CreatedAt
|
||||
w.fieldMap["updated_at"] = w.UpdatedAt
|
||||
w.fieldMap["deleted_at"] = w.DeletedAt
|
||||
|
||||
Reference in New Issue
Block a user