This commit is contained in:
haha 2021-03-08 10:33:18 +08:00
commit 17104f9c66
32 changed files with 1770 additions and 0 deletions

3
.gitattributes vendored Normal file
View File

@ -0,0 +1,3 @@
*.js linguist-language=GO
*.css linguist-language=GO
*.html linguist-language=GO

23
.gitignore vendored Normal file
View File

@ -0,0 +1,23 @@
.DS_Store
.buildpath
.hgignore.swp
.project
.orig
.swp
.idea/
.settings/
.vscode/
vender/
log/
composer.lock
gitpush.sh
pkg/
bin/
tmp/
cbuild
*/.DS_Store
config/config.toml
main
.vscode
go.sum
*.exe

21
LICENSE Normal file
View File

@ -0,0 +1,21 @@
MIT License
Copyright (c) 2018 john@goframe.org https://goframe.org
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

50
app/api/curd/curd.go Normal file
View File

@ -0,0 +1,50 @@
package curd
import (
"Gf-Vben/app/service/curd"
"Gf-Vben/app/service/user"
"Gf-Vben/library/response"
"github.com/gogf/gf/net/ghttp"
)
type Controller struct {
}
func (c *Controller) Curd(r *ghttp.Request) {
var cu curd.Curd
switch r.GetString("interface") {
case "user":
req := new(user.Req)
cu = req
default:
response.JsonExit(r, 1, "接口参数错误")
}
if err := r.Parse(cu); err != nil {
response.JsonExit(r, 2, err.Error())
}
switch r.GetString("action") {
case "list":
result, err := cu.List()
if err != nil {
response.JsonExit(r, 3, err.Error())
}
response.JsonExit(r, 2, "", result)
case "add":
if err := cu.Add(); err != nil {
response.JsonExit(r, 3, err.Error())
}
response.JsonExit(r, 2, "新增成功")
case "edit":
if err := cu.Edit(); err != nil {
response.JsonExit(r, 3, err.Error())
}
response.JsonExit(r, 2, "修改成功")
case "del":
if err := cu.Del(); err != nil {
response.JsonExit(r, 3, err.Error())
}
response.JsonExit(r, 2, "删除成功")
default:
response.JsonExit(r, 3, "接口参数错误")
}
}

22
app/api/user/user.go Normal file
View File

@ -0,0 +1,22 @@
package user
import (
"Gf-Vben/app/service/user"
"Gf-Vben/library/response"
"github.com/gogf/gf/net/ghttp"
)
type Controller struct {
}
func Register(r *ghttp.Request) {
var req *user.RegisterReq
if err := r.Parse(&req); err != nil {
response.JsonExit(r, 1, err.Error())
}
if err := req.Register(); err != nil {
response.JsonExit(r, 2, err.Error())
}
response.JsonExit(r, 0, "注册成功")
}

25
app/dao/app_role.go Normal file
View File

@ -0,0 +1,25 @@
// ============================================================================
// This is auto-generated by gf cli tool only once. Fill this file as you wish.
// ============================================================================
package dao
import (
"Gf-Vben/app/dao/internal"
)
// appRoleDao is the manager for logic model data accessing
// and custom defined data operations functions management. You can define
// methods on it to extend its functionality as you wish.
type appRoleDao struct {
internal.AppRoleDao
}
var (
// AppRole is globally public accessible object for table app_role operations.
AppRole = appRoleDao{
internal.AppRole,
}
)
// Fill with you ideas below.

25
app/dao/app_user.go Normal file
View File

@ -0,0 +1,25 @@
// ============================================================================
// This is auto-generated by gf cli tool only once. Fill this file as you wish.
// ============================================================================
package dao
import (
"Gf-Vben/app/dao/internal"
)
// appUserDao is the manager for logic model data accessing
// and custom defined data operations functions management. You can define
// methods on it to extend its functionality as you wish.
type appUserDao struct {
internal.AppUserDao
}
var (
// AppUser is globally public accessible object for table app_user operations.
AppUser = appUserDao{
internal.AppUser,
}
)
// Fill with you ideas below.

25
app/dao/app_user_role.go Normal file
View File

@ -0,0 +1,25 @@
// ============================================================================
// This is auto-generated by gf cli tool only once. Fill this file as you wish.
// ============================================================================
package dao
import (
"Gf-Vben/app/dao/internal"
)
// appUserRoleDao is the manager for logic model data accessing
// and custom defined data operations functions management. You can define
// methods on it to extend its functionality as you wish.
type appUserRoleDao struct {
internal.AppUserRoleDao
}
var (
// AppUserRole is globally public accessible object for table app_user_role operations.
AppUserRole = appUserRoleDao{
internal.AppUserRole,
}
)
// Fill with you ideas below.

View File

@ -0,0 +1,387 @@
// ==========================================================================
// This is auto-generated by gf cli tool. DO NOT EDIT THIS FILE MANUALLY.
// ==========================================================================
package internal
import (
"context"
"database/sql"
"github.com/gogf/gf/database/gdb"
"github.com/gogf/gf/frame/g"
"github.com/gogf/gf/frame/gmvc"
"time"
"Gf-Vben/app/model"
)
// AppRoleDao is the manager for logic model data accessing
// and custom defined data operations functions management.
type AppRoleDao struct {
gmvc.M
DB gdb.DB
Table string
Columns appRoleColumns
}
// AppRoleColumns defines and stores column names for table app_role.
type appRoleColumns struct {
Id string //
RoleName string //
RoleValue string //
}
var (
// AppRole is globally public accessible object for table app_role operations.
AppRole = AppRoleDao{
M: g.DB("default").Model("app_role").Safe(),
DB: g.DB("default"),
Table: "app_role",
Columns: appRoleColumns{
Id: "id",
RoleName: "role_name",
RoleValue: "role_value",
},
}
)
// Ctx is a chaining function, which creates and returns a new DB that is a shallow copy
// of current DB object and with given context in it.
// Note that this returned DB object can be used only once, so do not assign it to
// a global or package variable for long using.
func (d *AppRoleDao) Ctx(ctx context.Context) *AppRoleDao {
return &AppRoleDao{M: d.M.Ctx(ctx)}
}
// As sets an alias name for current table.
func (d *AppRoleDao) As(as string) *AppRoleDao {
return &AppRoleDao{M: d.M.As(as)}
}
// TX sets the transaction for current operation.
func (d *AppRoleDao) TX(tx *gdb.TX) *AppRoleDao {
return &AppRoleDao{M: d.M.TX(tx)}
}
// Master marks the following operation on master node.
func (d *AppRoleDao) Master() *AppRoleDao {
return &AppRoleDao{M: d.M.Master()}
}
// Slave marks the following operation on slave node.
// Note that it makes sense only if there's any slave node configured.
func (d *AppRoleDao) Slave() *AppRoleDao {
return &AppRoleDao{M: d.M.Slave()}
}
// Args sets custom arguments for model operation.
func (d *AppRoleDao) Args(args ...interface{}) *AppRoleDao {
return &AppRoleDao{M: d.M.Args(args...)}
}
// LeftJoin does "LEFT JOIN ... ON ..." statement on the model.
// The parameter <table> can be joined table and its joined condition,
// and also with its alias name, like:
// Table("user").LeftJoin("user_detail", "user_detail.uid=user.uid")
// Table("user", "u").LeftJoin("user_detail", "ud", "ud.uid=u.uid")
func (d *AppRoleDao) LeftJoin(table ...string) *AppRoleDao {
return &AppRoleDao{M: d.M.LeftJoin(table...)}
}
// RightJoin does "RIGHT JOIN ... ON ..." statement on the model.
// The parameter <table> can be joined table and its joined condition,
// and also with its alias name, like:
// Table("user").RightJoin("user_detail", "user_detail.uid=user.uid")
// Table("user", "u").RightJoin("user_detail", "ud", "ud.uid=u.uid")
func (d *AppRoleDao) RightJoin(table ...string) *AppRoleDao {
return &AppRoleDao{M: d.M.RightJoin(table...)}
}
// InnerJoin does "INNER JOIN ... ON ..." statement on the model.
// The parameter <table> can be joined table and its joined condition,
// and also with its alias name, like:
// Table("user").InnerJoin("user_detail", "user_detail.uid=user.uid")
// Table("user", "u").InnerJoin("user_detail", "ud", "ud.uid=u.uid")
func (d *AppRoleDao) InnerJoin(table ...string) *AppRoleDao {
return &AppRoleDao{M: d.M.InnerJoin(table...)}
}
// Fields sets the operation fields of the model, multiple fields joined using char ','.
// The parameter <fieldNamesOrMapStruct> can be type of string/map/*map/struct/*struct.
func (d *AppRoleDao) Fields(fieldNamesOrMapStruct ...interface{}) *AppRoleDao {
return &AppRoleDao{M: d.M.Fields(fieldNamesOrMapStruct...)}
}
// FieldsEx sets the excluded operation fields of the model, multiple fields joined using char ','.
// The parameter <fieldNamesOrMapStruct> can be type of string/map/*map/struct/*struct.
func (d *AppRoleDao) FieldsEx(fieldNamesOrMapStruct ...interface{}) *AppRoleDao {
return &AppRoleDao{M: d.M.FieldsEx(fieldNamesOrMapStruct...)}
}
// Option sets the extra operation option for the model.
func (d *AppRoleDao) Option(option int) *AppRoleDao {
return &AppRoleDao{M: d.M.Option(option)}
}
// OmitEmpty sets OPTION_OMITEMPTY option for the model, which automatically filers
// the data and where attributes for empty values.
func (d *AppRoleDao) OmitEmpty() *AppRoleDao {
return &AppRoleDao{M: d.M.OmitEmpty()}
}
// Filter marks filtering the fields which does not exist in the fields of the operated table.
func (d *AppRoleDao) Filter() *AppRoleDao {
return &AppRoleDao{M: d.M.Filter()}
}
// Where sets the condition statement for the model. The parameter <where> can be type of
// string/map/gmap/slice/struct/*struct, etc. Note that, if it's called more than one times,
// multiple conditions will be joined into where statement using "AND".
// Eg:
// Where("uid=10000")
// Where("uid", 10000)
// Where("money>? AND name like ?", 99999, "vip_%")
// Where("uid", 1).Where("name", "john")
// Where("status IN (?)", g.Slice{1,2,3})
// Where("age IN(?,?)", 18, 50)
// Where(User{ Id : 1, UserName : "john"})
func (d *AppRoleDao) Where(where interface{}, args ...interface{}) *AppRoleDao {
return &AppRoleDao{M: d.M.Where(where, args...)}
}
// WherePri does the same logic as M.Where except that if the parameter <where>
// is a single condition like int/string/float/slice, it treats the condition as the primary
// key value. That is, if primary key is "id" and given <where> parameter as "123", the
// WherePri function treats the condition as "id=123", but M.Where treats the condition
// as string "123".
func (d *AppRoleDao) WherePri(where interface{}, args ...interface{}) *AppRoleDao {
return &AppRoleDao{M: d.M.WherePri(where, args...)}
}
// And adds "AND" condition to the where statement.
func (d *AppRoleDao) And(where interface{}, args ...interface{}) *AppRoleDao {
return &AppRoleDao{M: d.M.And(where, args...)}
}
// Or adds "OR" condition to the where statement.
func (d *AppRoleDao) Or(where interface{}, args ...interface{}) *AppRoleDao {
return &AppRoleDao{M: d.M.Or(where, args...)}
}
// Group sets the "GROUP BY" statement for the model.
func (d *AppRoleDao) Group(groupBy string) *AppRoleDao {
return &AppRoleDao{M: d.M.Group(groupBy)}
}
// Order sets the "ORDER BY" statement for the model.
func (d *AppRoleDao) Order(orderBy ...string) *AppRoleDao {
return &AppRoleDao{M: d.M.Order(orderBy...)}
}
// Limit sets the "LIMIT" statement for the model.
// The parameter <limit> can be either one or two number, if passed two number is passed,
// it then sets "LIMIT limit[0],limit[1]" statement for the model, or else it sets "LIMIT limit[0]"
// statement.
func (d *AppRoleDao) Limit(limit ...int) *AppRoleDao {
return &AppRoleDao{M: d.M.Limit(limit...)}
}
// Offset sets the "OFFSET" statement for the model.
// It only makes sense for some databases like SQLServer, PostgreSQL, etc.
func (d *AppRoleDao) Offset(offset int) *AppRoleDao {
return &AppRoleDao{M: d.M.Offset(offset)}
}
// Page sets the paging number for the model.
// The parameter <page> is started from 1 for paging.
// Note that, it differs that the Limit function start from 0 for "LIMIT" statement.
func (d *AppRoleDao) Page(page, limit int) *AppRoleDao {
return &AppRoleDao{M: d.M.Page(page, limit)}
}
// Batch sets the batch operation number for the model.
func (d *AppRoleDao) Batch(batch int) *AppRoleDao {
return &AppRoleDao{M: d.M.Batch(batch)}
}
// Cache sets the cache feature for the model. It caches the result of the sql, which means
// if there's another same sql request, it just reads and returns the result from cache, it
// but not committed and executed into the database.
//
// If the parameter <duration> < 0, which means it clear the cache with given <name>.
// If the parameter <duration> = 0, which means it never expires.
// If the parameter <duration> > 0, which means it expires after <duration>.
//
// The optional parameter <name> is used to bind a name to the cache, which means you can later
// control the cache like changing the <duration> or clearing the cache with specified <name>.
//
// Note that, the cache feature is disabled if the model is operating on a transaction.
func (d *AppRoleDao) Cache(duration time.Duration, name ...string) *AppRoleDao {
return &AppRoleDao{M: d.M.Cache(duration, name...)}
}
// Data sets the operation data for the model.
// The parameter <data> can be type of string/map/gmap/slice/struct/*struct, etc.
// Eg:
// Data("uid=10000")
// Data("uid", 10000)
// Data(g.Map{"uid": 10000, "name":"john"})
// Data(g.Slice{g.Map{"uid": 10000, "name":"john"}, g.Map{"uid": 20000, "name":"smith"})
func (d *AppRoleDao) Data(data ...interface{}) *AppRoleDao {
return &AppRoleDao{M: d.M.Data(data...)}
}
// All does "SELECT FROM ..." statement for the model.
// It retrieves the records from table and returns the result as []*model.AppRole.
// It returns nil if there's no record retrieved with the given conditions from table.
//
// The optional parameter <where> is the same as the parameter of M.Where function,
// see M.Where.
func (d *AppRoleDao) All(where ...interface{}) ([]*model.AppRole, error) {
all, err := d.M.All(where...)
if err != nil {
return nil, err
}
var entities []*model.AppRole
if err = all.Structs(&entities); err != nil && err != sql.ErrNoRows {
return nil, err
}
return entities, nil
}
// One retrieves one record from table and returns the result as *model.AppRole.
// It returns nil if there's no record retrieved with the given conditions from table.
//
// The optional parameter <where> is the same as the parameter of M.Where function,
// see M.Where.
func (d *AppRoleDao) One(where ...interface{}) (*model.AppRole, error) {
one, err := d.M.One(where...)
if err != nil {
return nil, err
}
var entity *model.AppRole
if err = one.Struct(&entity); err != nil && err != sql.ErrNoRows {
return nil, err
}
return entity, nil
}
// FindOne retrieves and returns a single Record by M.WherePri and M.One.
// Also see M.WherePri and M.One.
func (d *AppRoleDao) FindOne(where ...interface{}) (*model.AppRole, error) {
one, err := d.M.FindOne(where...)
if err != nil {
return nil, err
}
var entity *model.AppRole
if err = one.Struct(&entity); err != nil && err != sql.ErrNoRows {
return nil, err
}
return entity, nil
}
// FindAll retrieves and returns Result by by M.WherePri and M.All.
// Also see M.WherePri and M.All.
func (d *AppRoleDao) FindAll(where ...interface{}) ([]*model.AppRole, error) {
all, err := d.M.FindAll(where...)
if err != nil {
return nil, err
}
var entities []*model.AppRole
if err = all.Structs(&entities); err != nil && err != sql.ErrNoRows {
return nil, err
}
return entities, nil
}
// Struct retrieves one record from table and converts it into given struct.
// The parameter <pointer> should be type of *struct/**struct. If type **struct is given,
// it can create the struct internally during converting.
//
// The optional parameter <where> is the same as the parameter of Model.Where function,
// see Model.Where.
//
// Note that it returns sql.ErrNoRows if there's no record retrieved with the given conditions
// from table and <pointer> is not nil.
//
// Eg:
// user := new(User)
// err := dao.User.Where("id", 1).Struct(user)
//
// user := (*User)(nil)
// err := dao.User.Where("id", 1).Struct(&user)
func (d *AppRoleDao) Struct(pointer interface{}, where ...interface{}) error {
return d.M.Struct(pointer, where...)
}
// Structs retrieves records from table and converts them into given struct slice.
// The parameter <pointer> should be type of *[]struct/*[]*struct. It can create and fill the struct
// slice internally during converting.
//
// The optional parameter <where> is the same as the parameter of Model.Where function,
// see Model.Where.
//
// Note that it returns sql.ErrNoRows if there's no record retrieved with the given conditions
// from table and <pointer> is not empty.
//
// Eg:
// users := ([]User)(nil)
// err := dao.User.Structs(&users)
//
// users := ([]*User)(nil)
// err := dao.User.Structs(&users)
func (d *AppRoleDao) Structs(pointer interface{}, where ...interface{}) error {
return d.M.Structs(pointer, where...)
}
// Scan automatically calls Struct or Structs function according to the type of parameter <pointer>.
// It calls function Struct if <pointer> is type of *struct/**struct.
// It calls function Structs if <pointer> is type of *[]struct/*[]*struct.
//
// The optional parameter <where> is the same as the parameter of Model.Where function,
// see Model.Where.
//
// Note that it returns sql.ErrNoRows if there's no record retrieved and given pointer is not empty or nil.
//
// Eg:
// user := new(User)
// err := dao.User.Where("id", 1).Scan(user)
//
// user := (*User)(nil)
// err := dao.User.Where("id", 1).Scan(&user)
//
// users := ([]User)(nil)
// err := dao.User.Scan(&users)
//
// users := ([]*User)(nil)
// err := dao.User.Scan(&users)
func (d *AppRoleDao) Scan(pointer interface{}, where ...interface{}) error {
return d.M.Scan(pointer, where...)
}
// Chunk iterates the table with given size and callback function.
func (d *AppRoleDao) Chunk(limit int, callback func(entities []*model.AppRole, err error) bool) {
d.M.Chunk(limit, func(result gdb.Result, err error) bool {
var entities []*model.AppRole
err = result.Structs(&entities)
if err == sql.ErrNoRows {
return false
}
return callback(entities, err)
})
}
// LockUpdate sets the lock for update for current operation.
func (d *AppRoleDao) LockUpdate() *AppRoleDao {
return &AppRoleDao{M: d.M.LockUpdate()}
}
// LockShared sets the lock in share mode for current operation.
func (d *AppRoleDao) LockShared() *AppRoleDao {
return &AppRoleDao{M: d.M.LockShared()}
}
// Unscoped enables/disables the soft deleting feature.
func (d *AppRoleDao) Unscoped() *AppRoleDao {
return &AppRoleDao{M: d.M.Unscoped()}
}

View File

@ -0,0 +1,399 @@
// ==========================================================================
// This is auto-generated by gf cli tool. DO NOT EDIT THIS FILE MANUALLY.
// ==========================================================================
package internal
import (
"context"
"database/sql"
"github.com/gogf/gf/database/gdb"
"github.com/gogf/gf/frame/g"
"github.com/gogf/gf/frame/gmvc"
"time"
"Gf-Vben/app/model"
)
// AppUserDao is the manager for logic model data accessing
// and custom defined data operations functions management.
type AppUserDao struct {
gmvc.M
DB gdb.DB
Table string
Columns appUserColumns
}
// AppUserColumns defines and stores column names for table app_user.
type appUserColumns struct {
Id string // primary id
Username string // username
Password string // password
Note string //
NickName string // nickName
Status string // 1:enable 2:disable
CreateAt string //
UpdateAt string //
DeleteAt string //
}
var (
// AppUser is globally public accessible object for table app_user operations.
AppUser = AppUserDao{
M: g.DB("default").Model("app_user").Safe(),
DB: g.DB("default"),
Table: "app_user",
Columns: appUserColumns{
Id: "id",
Username: "username",
Password: "password",
Note: "note",
NickName: "nick_name",
Status: "status",
CreateAt: "create_at",
UpdateAt: "update_at",
DeleteAt: "delete_at",
},
}
)
// Ctx is a chaining function, which creates and returns a new DB that is a shallow copy
// of current DB object and with given context in it.
// Note that this returned DB object can be used only once, so do not assign it to
// a global or package variable for long using.
func (d *AppUserDao) Ctx(ctx context.Context) *AppUserDao {
return &AppUserDao{M: d.M.Ctx(ctx)}
}
// As sets an alias name for current table.
func (d *AppUserDao) As(as string) *AppUserDao {
return &AppUserDao{M: d.M.As(as)}
}
// TX sets the transaction for current operation.
func (d *AppUserDao) TX(tx *gdb.TX) *AppUserDao {
return &AppUserDao{M: d.M.TX(tx)}
}
// Master marks the following operation on master node.
func (d *AppUserDao) Master() *AppUserDao {
return &AppUserDao{M: d.M.Master()}
}
// Slave marks the following operation on slave node.
// Note that it makes sense only if there's any slave node configured.
func (d *AppUserDao) Slave() *AppUserDao {
return &AppUserDao{M: d.M.Slave()}
}
// Args sets custom arguments for model operation.
func (d *AppUserDao) Args(args ...interface{}) *AppUserDao {
return &AppUserDao{M: d.M.Args(args...)}
}
// LeftJoin does "LEFT JOIN ... ON ..." statement on the model.
// The parameter <table> can be joined table and its joined condition,
// and also with its alias name, like:
// Table("user").LeftJoin("user_detail", "user_detail.uid=user.uid")
// Table("user", "u").LeftJoin("user_detail", "ud", "ud.uid=u.uid")
func (d *AppUserDao) LeftJoin(table ...string) *AppUserDao {
return &AppUserDao{M: d.M.LeftJoin(table...)}
}
// RightJoin does "RIGHT JOIN ... ON ..." statement on the model.
// The parameter <table> can be joined table and its joined condition,
// and also with its alias name, like:
// Table("user").RightJoin("user_detail", "user_detail.uid=user.uid")
// Table("user", "u").RightJoin("user_detail", "ud", "ud.uid=u.uid")
func (d *AppUserDao) RightJoin(table ...string) *AppUserDao {
return &AppUserDao{M: d.M.RightJoin(table...)}
}
// InnerJoin does "INNER JOIN ... ON ..." statement on the model.
// The parameter <table> can be joined table and its joined condition,
// and also with its alias name, like:
// Table("user").InnerJoin("user_detail", "user_detail.uid=user.uid")
// Table("user", "u").InnerJoin("user_detail", "ud", "ud.uid=u.uid")
func (d *AppUserDao) InnerJoin(table ...string) *AppUserDao {
return &AppUserDao{M: d.M.InnerJoin(table...)}
}
// Fields sets the operation fields of the model, multiple fields joined using char ','.
// The parameter <fieldNamesOrMapStruct> can be type of string/map/*map/struct/*struct.
func (d *AppUserDao) Fields(fieldNamesOrMapStruct ...interface{}) *AppUserDao {
return &AppUserDao{M: d.M.Fields(fieldNamesOrMapStruct...)}
}
// FieldsEx sets the excluded operation fields of the model, multiple fields joined using char ','.
// The parameter <fieldNamesOrMapStruct> can be type of string/map/*map/struct/*struct.
func (d *AppUserDao) FieldsEx(fieldNamesOrMapStruct ...interface{}) *AppUserDao {
return &AppUserDao{M: d.M.FieldsEx(fieldNamesOrMapStruct...)}
}
// Option sets the extra operation option for the model.
func (d *AppUserDao) Option(option int) *AppUserDao {
return &AppUserDao{M: d.M.Option(option)}
}
// OmitEmpty sets OPTION_OMITEMPTY option for the model, which automatically filers
// the data and where attributes for empty values.
func (d *AppUserDao) OmitEmpty() *AppUserDao {
return &AppUserDao{M: d.M.OmitEmpty()}
}
// Filter marks filtering the fields which does not exist in the fields of the operated table.
func (d *AppUserDao) Filter() *AppUserDao {
return &AppUserDao{M: d.M.Filter()}
}
// Where sets the condition statement for the model. The parameter <where> can be type of
// string/map/gmap/slice/struct/*struct, etc. Note that, if it's called more than one times,
// multiple conditions will be joined into where statement using "AND".
// Eg:
// Where("uid=10000")
// Where("uid", 10000)
// Where("money>? AND name like ?", 99999, "vip_%")
// Where("uid", 1).Where("name", "john")
// Where("status IN (?)", g.Slice{1,2,3})
// Where("age IN(?,?)", 18, 50)
// Where(User{ Id : 1, UserName : "john"})
func (d *AppUserDao) Where(where interface{}, args ...interface{}) *AppUserDao {
return &AppUserDao{M: d.M.Where(where, args...)}
}
// WherePri does the same logic as M.Where except that if the parameter <where>
// is a single condition like int/string/float/slice, it treats the condition as the primary
// key value. That is, if primary key is "id" and given <where> parameter as "123", the
// WherePri function treats the condition as "id=123", but M.Where treats the condition
// as string "123".
func (d *AppUserDao) WherePri(where interface{}, args ...interface{}) *AppUserDao {
return &AppUserDao{M: d.M.WherePri(where, args...)}
}
// And adds "AND" condition to the where statement.
func (d *AppUserDao) And(where interface{}, args ...interface{}) *AppUserDao {
return &AppUserDao{M: d.M.And(where, args...)}
}
// Or adds "OR" condition to the where statement.
func (d *AppUserDao) Or(where interface{}, args ...interface{}) *AppUserDao {
return &AppUserDao{M: d.M.Or(where, args...)}
}
// Group sets the "GROUP BY" statement for the model.
func (d *AppUserDao) Group(groupBy string) *AppUserDao {
return &AppUserDao{M: d.M.Group(groupBy)}
}
// Order sets the "ORDER BY" statement for the model.
func (d *AppUserDao) Order(orderBy ...string) *AppUserDao {
return &AppUserDao{M: d.M.Order(orderBy...)}
}
// Limit sets the "LIMIT" statement for the model.
// The parameter <limit> can be either one or two number, if passed two number is passed,
// it then sets "LIMIT limit[0],limit[1]" statement for the model, or else it sets "LIMIT limit[0]"
// statement.
func (d *AppUserDao) Limit(limit ...int) *AppUserDao {
return &AppUserDao{M: d.M.Limit(limit...)}
}
// Offset sets the "OFFSET" statement for the model.
// It only makes sense for some databases like SQLServer, PostgreSQL, etc.
func (d *AppUserDao) Offset(offset int) *AppUserDao {
return &AppUserDao{M: d.M.Offset(offset)}
}
// Page sets the paging number for the model.
// The parameter <page> is started from 1 for paging.
// Note that, it differs that the Limit function start from 0 for "LIMIT" statement.
func (d *AppUserDao) Page(page, limit int) *AppUserDao {
return &AppUserDao{M: d.M.Page(page, limit)}
}
// Batch sets the batch operation number for the model.
func (d *AppUserDao) Batch(batch int) *AppUserDao {
return &AppUserDao{M: d.M.Batch(batch)}
}
// Cache sets the cache feature for the model. It caches the result of the sql, which means
// if there's another same sql request, it just reads and returns the result from cache, it
// but not committed and executed into the database.
//
// If the parameter <duration> < 0, which means it clear the cache with given <name>.
// If the parameter <duration> = 0, which means it never expires.
// If the parameter <duration> > 0, which means it expires after <duration>.
//
// The optional parameter <name> is used to bind a name to the cache, which means you can later
// control the cache like changing the <duration> or clearing the cache with specified <name>.
//
// Note that, the cache feature is disabled if the model is operating on a transaction.
func (d *AppUserDao) Cache(duration time.Duration, name ...string) *AppUserDao {
return &AppUserDao{M: d.M.Cache(duration, name...)}
}
// Data sets the operation data for the model.
// The parameter <data> can be type of string/map/gmap/slice/struct/*struct, etc.
// Eg:
// Data("uid=10000")
// Data("uid", 10000)
// Data(g.Map{"uid": 10000, "name":"john"})
// Data(g.Slice{g.Map{"uid": 10000, "name":"john"}, g.Map{"uid": 20000, "name":"smith"})
func (d *AppUserDao) Data(data ...interface{}) *AppUserDao {
return &AppUserDao{M: d.M.Data(data...)}
}
// All does "SELECT FROM ..." statement for the model.
// It retrieves the records from table and returns the result as []*model.AppUser.
// It returns nil if there's no record retrieved with the given conditions from table.
//
// The optional parameter <where> is the same as the parameter of M.Where function,
// see M.Where.
func (d *AppUserDao) All(where ...interface{}) ([]*model.AppUser, error) {
all, err := d.M.All(where...)
if err != nil {
return nil, err
}
var entities []*model.AppUser
if err = all.Structs(&entities); err != nil && err != sql.ErrNoRows {
return nil, err
}
return entities, nil
}
// One retrieves one record from table and returns the result as *model.AppUser.
// It returns nil if there's no record retrieved with the given conditions from table.
//
// The optional parameter <where> is the same as the parameter of M.Where function,
// see M.Where.
func (d *AppUserDao) One(where ...interface{}) (*model.AppUser, error) {
one, err := d.M.One(where...)
if err != nil {
return nil, err
}
var entity *model.AppUser
if err = one.Struct(&entity); err != nil && err != sql.ErrNoRows {
return nil, err
}
return entity, nil
}
// FindOne retrieves and returns a single Record by M.WherePri and M.One.
// Also see M.WherePri and M.One.
func (d *AppUserDao) FindOne(where ...interface{}) (*model.AppUser, error) {
one, err := d.M.FindOne(where...)
if err != nil {
return nil, err
}
var entity *model.AppUser
if err = one.Struct(&entity); err != nil && err != sql.ErrNoRows {
return nil, err
}
return entity, nil
}
// FindAll retrieves and returns Result by by M.WherePri and M.All.
// Also see M.WherePri and M.All.
func (d *AppUserDao) FindAll(where ...interface{}) ([]*model.AppUser, error) {
all, err := d.M.FindAll(where...)
if err != nil {
return nil, err
}
var entities []*model.AppUser
if err = all.Structs(&entities); err != nil && err != sql.ErrNoRows {
return nil, err
}
return entities, nil
}
// Struct retrieves one record from table and converts it into given struct.
// The parameter <pointer> should be type of *struct/**struct. If type **struct is given,
// it can create the struct internally during converting.
//
// The optional parameter <where> is the same as the parameter of Model.Where function,
// see Model.Where.
//
// Note that it returns sql.ErrNoRows if there's no record retrieved with the given conditions
// from table and <pointer> is not nil.
//
// Eg:
// user := new(User)
// err := dao.User.Where("id", 1).Struct(user)
//
// user := (*User)(nil)
// err := dao.User.Where("id", 1).Struct(&user)
func (d *AppUserDao) Struct(pointer interface{}, where ...interface{}) error {
return d.M.Struct(pointer, where...)
}
// Structs retrieves records from table and converts them into given struct slice.
// The parameter <pointer> should be type of *[]struct/*[]*struct. It can create and fill the struct
// slice internally during converting.
//
// The optional parameter <where> is the same as the parameter of Model.Where function,
// see Model.Where.
//
// Note that it returns sql.ErrNoRows if there's no record retrieved with the given conditions
// from table and <pointer> is not empty.
//
// Eg:
// users := ([]User)(nil)
// err := dao.User.Structs(&users)
//
// users := ([]*User)(nil)
// err := dao.User.Structs(&users)
func (d *AppUserDao) Structs(pointer interface{}, where ...interface{}) error {
return d.M.Structs(pointer, where...)
}
// Scan automatically calls Struct or Structs function according to the type of parameter <pointer>.
// It calls function Struct if <pointer> is type of *struct/**struct.
// It calls function Structs if <pointer> is type of *[]struct/*[]*struct.
//
// The optional parameter <where> is the same as the parameter of Model.Where function,
// see Model.Where.
//
// Note that it returns sql.ErrNoRows if there's no record retrieved and given pointer is not empty or nil.
//
// Eg:
// user := new(User)
// err := dao.User.Where("id", 1).Scan(user)
//
// user := (*User)(nil)
// err := dao.User.Where("id", 1).Scan(&user)
//
// users := ([]User)(nil)
// err := dao.User.Scan(&users)
//
// users := ([]*User)(nil)
// err := dao.User.Scan(&users)
func (d *AppUserDao) Scan(pointer interface{}, where ...interface{}) error {
return d.M.Scan(pointer, where...)
}
// Chunk iterates the table with given size and callback function.
func (d *AppUserDao) Chunk(limit int, callback func(entities []*model.AppUser, err error) bool) {
d.M.Chunk(limit, func(result gdb.Result, err error) bool {
var entities []*model.AppUser
err = result.Structs(&entities)
if err == sql.ErrNoRows {
return false
}
return callback(entities, err)
})
}
// LockUpdate sets the lock for update for current operation.
func (d *AppUserDao) LockUpdate() *AppUserDao {
return &AppUserDao{M: d.M.LockUpdate()}
}
// LockShared sets the lock in share mode for current operation.
func (d *AppUserDao) LockShared() *AppUserDao {
return &AppUserDao{M: d.M.LockShared()}
}
// Unscoped enables/disables the soft deleting feature.
func (d *AppUserDao) Unscoped() *AppUserDao {
return &AppUserDao{M: d.M.Unscoped()}
}

View File

@ -0,0 +1,387 @@
// ==========================================================================
// This is auto-generated by gf cli tool. DO NOT EDIT THIS FILE MANUALLY.
// ==========================================================================
package internal
import (
"context"
"database/sql"
"github.com/gogf/gf/database/gdb"
"github.com/gogf/gf/frame/g"
"github.com/gogf/gf/frame/gmvc"
"time"
"Gf-Vben/app/model"
)
// AppUserRoleDao is the manager for logic model data accessing
// and custom defined data operations functions management.
type AppUserRoleDao struct {
gmvc.M
DB gdb.DB
Table string
Columns appUserRoleColumns
}
// AppUserRoleColumns defines and stores column names for table app_user_role.
type appUserRoleColumns struct {
Id string //
UserId string //
RoleId string //
}
var (
// AppUserRole is globally public accessible object for table app_user_role operations.
AppUserRole = AppUserRoleDao{
M: g.DB("default").Model("app_user_role").Safe(),
DB: g.DB("default"),
Table: "app_user_role",
Columns: appUserRoleColumns{
Id: "id",
UserId: "user_id",
RoleId: "role_id",
},
}
)
// Ctx is a chaining function, which creates and returns a new DB that is a shallow copy
// of current DB object and with given context in it.
// Note that this returned DB object can be used only once, so do not assign it to
// a global or package variable for long using.
func (d *AppUserRoleDao) Ctx(ctx context.Context) *AppUserRoleDao {
return &AppUserRoleDao{M: d.M.Ctx(ctx)}
}
// As sets an alias name for current table.
func (d *AppUserRoleDao) As(as string) *AppUserRoleDao {
return &AppUserRoleDao{M: d.M.As(as)}
}
// TX sets the transaction for current operation.
func (d *AppUserRoleDao) TX(tx *gdb.TX) *AppUserRoleDao {
return &AppUserRoleDao{M: d.M.TX(tx)}
}
// Master marks the following operation on master node.
func (d *AppUserRoleDao) Master() *AppUserRoleDao {
return &AppUserRoleDao{M: d.M.Master()}
}
// Slave marks the following operation on slave node.
// Note that it makes sense only if there's any slave node configured.
func (d *AppUserRoleDao) Slave() *AppUserRoleDao {
return &AppUserRoleDao{M: d.M.Slave()}
}
// Args sets custom arguments for model operation.
func (d *AppUserRoleDao) Args(args ...interface{}) *AppUserRoleDao {
return &AppUserRoleDao{M: d.M.Args(args...)}
}
// LeftJoin does "LEFT JOIN ... ON ..." statement on the model.
// The parameter <table> can be joined table and its joined condition,
// and also with its alias name, like:
// Table("user").LeftJoin("user_detail", "user_detail.uid=user.uid")
// Table("user", "u").LeftJoin("user_detail", "ud", "ud.uid=u.uid")
func (d *AppUserRoleDao) LeftJoin(table ...string) *AppUserRoleDao {
return &AppUserRoleDao{M: d.M.LeftJoin(table...)}
}
// RightJoin does "RIGHT JOIN ... ON ..." statement on the model.
// The parameter <table> can be joined table and its joined condition,
// and also with its alias name, like:
// Table("user").RightJoin("user_detail", "user_detail.uid=user.uid")
// Table("user", "u").RightJoin("user_detail", "ud", "ud.uid=u.uid")
func (d *AppUserRoleDao) RightJoin(table ...string) *AppUserRoleDao {
return &AppUserRoleDao{M: d.M.RightJoin(table...)}
}
// InnerJoin does "INNER JOIN ... ON ..." statement on the model.
// The parameter <table> can be joined table and its joined condition,
// and also with its alias name, like:
// Table("user").InnerJoin("user_detail", "user_detail.uid=user.uid")
// Table("user", "u").InnerJoin("user_detail", "ud", "ud.uid=u.uid")
func (d *AppUserRoleDao) InnerJoin(table ...string) *AppUserRoleDao {
return &AppUserRoleDao{M: d.M.InnerJoin(table...)}
}
// Fields sets the operation fields of the model, multiple fields joined using char ','.
// The parameter <fieldNamesOrMapStruct> can be type of string/map/*map/struct/*struct.
func (d *AppUserRoleDao) Fields(fieldNamesOrMapStruct ...interface{}) *AppUserRoleDao {
return &AppUserRoleDao{M: d.M.Fields(fieldNamesOrMapStruct...)}
}
// FieldsEx sets the excluded operation fields of the model, multiple fields joined using char ','.
// The parameter <fieldNamesOrMapStruct> can be type of string/map/*map/struct/*struct.
func (d *AppUserRoleDao) FieldsEx(fieldNamesOrMapStruct ...interface{}) *AppUserRoleDao {
return &AppUserRoleDao{M: d.M.FieldsEx(fieldNamesOrMapStruct...)}
}
// Option sets the extra operation option for the model.
func (d *AppUserRoleDao) Option(option int) *AppUserRoleDao {
return &AppUserRoleDao{M: d.M.Option(option)}
}
// OmitEmpty sets OPTION_OMITEMPTY option for the model, which automatically filers
// the data and where attributes for empty values.
func (d *AppUserRoleDao) OmitEmpty() *AppUserRoleDao {
return &AppUserRoleDao{M: d.M.OmitEmpty()}
}
// Filter marks filtering the fields which does not exist in the fields of the operated table.
func (d *AppUserRoleDao) Filter() *AppUserRoleDao {
return &AppUserRoleDao{M: d.M.Filter()}
}
// Where sets the condition statement for the model. The parameter <where> can be type of
// string/map/gmap/slice/struct/*struct, etc. Note that, if it's called more than one times,
// multiple conditions will be joined into where statement using "AND".
// Eg:
// Where("uid=10000")
// Where("uid", 10000)
// Where("money>? AND name like ?", 99999, "vip_%")
// Where("uid", 1).Where("name", "john")
// Where("status IN (?)", g.Slice{1,2,3})
// Where("age IN(?,?)", 18, 50)
// Where(User{ Id : 1, UserName : "john"})
func (d *AppUserRoleDao) Where(where interface{}, args ...interface{}) *AppUserRoleDao {
return &AppUserRoleDao{M: d.M.Where(where, args...)}
}
// WherePri does the same logic as M.Where except that if the parameter <where>
// is a single condition like int/string/float/slice, it treats the condition as the primary
// key value. That is, if primary key is "id" and given <where> parameter as "123", the
// WherePri function treats the condition as "id=123", but M.Where treats the condition
// as string "123".
func (d *AppUserRoleDao) WherePri(where interface{}, args ...interface{}) *AppUserRoleDao {
return &AppUserRoleDao{M: d.M.WherePri(where, args...)}
}
// And adds "AND" condition to the where statement.
func (d *AppUserRoleDao) And(where interface{}, args ...interface{}) *AppUserRoleDao {
return &AppUserRoleDao{M: d.M.And(where, args...)}
}
// Or adds "OR" condition to the where statement.
func (d *AppUserRoleDao) Or(where interface{}, args ...interface{}) *AppUserRoleDao {
return &AppUserRoleDao{M: d.M.Or(where, args...)}
}
// Group sets the "GROUP BY" statement for the model.
func (d *AppUserRoleDao) Group(groupBy string) *AppUserRoleDao {
return &AppUserRoleDao{M: d.M.Group(groupBy)}
}
// Order sets the "ORDER BY" statement for the model.
func (d *AppUserRoleDao) Order(orderBy ...string) *AppUserRoleDao {
return &AppUserRoleDao{M: d.M.Order(orderBy...)}
}
// Limit sets the "LIMIT" statement for the model.
// The parameter <limit> can be either one or two number, if passed two number is passed,
// it then sets "LIMIT limit[0],limit[1]" statement for the model, or else it sets "LIMIT limit[0]"
// statement.
func (d *AppUserRoleDao) Limit(limit ...int) *AppUserRoleDao {
return &AppUserRoleDao{M: d.M.Limit(limit...)}
}
// Offset sets the "OFFSET" statement for the model.
// It only makes sense for some databases like SQLServer, PostgreSQL, etc.
func (d *AppUserRoleDao) Offset(offset int) *AppUserRoleDao {
return &AppUserRoleDao{M: d.M.Offset(offset)}
}
// Page sets the paging number for the model.
// The parameter <page> is started from 1 for paging.
// Note that, it differs that the Limit function start from 0 for "LIMIT" statement.
func (d *AppUserRoleDao) Page(page, limit int) *AppUserRoleDao {
return &AppUserRoleDao{M: d.M.Page(page, limit)}
}
// Batch sets the batch operation number for the model.
func (d *AppUserRoleDao) Batch(batch int) *AppUserRoleDao {
return &AppUserRoleDao{M: d.M.Batch(batch)}
}
// Cache sets the cache feature for the model. It caches the result of the sql, which means
// if there's another same sql request, it just reads and returns the result from cache, it
// but not committed and executed into the database.
//
// If the parameter <duration> < 0, which means it clear the cache with given <name>.
// If the parameter <duration> = 0, which means it never expires.
// If the parameter <duration> > 0, which means it expires after <duration>.
//
// The optional parameter <name> is used to bind a name to the cache, which means you can later
// control the cache like changing the <duration> or clearing the cache with specified <name>.
//
// Note that, the cache feature is disabled if the model is operating on a transaction.
func (d *AppUserRoleDao) Cache(duration time.Duration, name ...string) *AppUserRoleDao {
return &AppUserRoleDao{M: d.M.Cache(duration, name...)}
}
// Data sets the operation data for the model.
// The parameter <data> can be type of string/map/gmap/slice/struct/*struct, etc.
// Eg:
// Data("uid=10000")
// Data("uid", 10000)
// Data(g.Map{"uid": 10000, "name":"john"})
// Data(g.Slice{g.Map{"uid": 10000, "name":"john"}, g.Map{"uid": 20000, "name":"smith"})
func (d *AppUserRoleDao) Data(data ...interface{}) *AppUserRoleDao {
return &AppUserRoleDao{M: d.M.Data(data...)}
}
// All does "SELECT FROM ..." statement for the model.
// It retrieves the records from table and returns the result as []*model.AppUserRole.
// It returns nil if there's no record retrieved with the given conditions from table.
//
// The optional parameter <where> is the same as the parameter of M.Where function,
// see M.Where.
func (d *AppUserRoleDao) All(where ...interface{}) ([]*model.AppUserRole, error) {
all, err := d.M.All(where...)
if err != nil {
return nil, err
}
var entities []*model.AppUserRole
if err = all.Structs(&entities); err != nil && err != sql.ErrNoRows {
return nil, err
}
return entities, nil
}
// One retrieves one record from table and returns the result as *model.AppUserRole.
// It returns nil if there's no record retrieved with the given conditions from table.
//
// The optional parameter <where> is the same as the parameter of M.Where function,
// see M.Where.
func (d *AppUserRoleDao) One(where ...interface{}) (*model.AppUserRole, error) {
one, err := d.M.One(where...)
if err != nil {
return nil, err
}
var entity *model.AppUserRole
if err = one.Struct(&entity); err != nil && err != sql.ErrNoRows {
return nil, err
}
return entity, nil
}
// FindOne retrieves and returns a single Record by M.WherePri and M.One.
// Also see M.WherePri and M.One.
func (d *AppUserRoleDao) FindOne(where ...interface{}) (*model.AppUserRole, error) {
one, err := d.M.FindOne(where...)
if err != nil {
return nil, err
}
var entity *model.AppUserRole
if err = one.Struct(&entity); err != nil && err != sql.ErrNoRows {
return nil, err
}
return entity, nil
}
// FindAll retrieves and returns Result by by M.WherePri and M.All.
// Also see M.WherePri and M.All.
func (d *AppUserRoleDao) FindAll(where ...interface{}) ([]*model.AppUserRole, error) {
all, err := d.M.FindAll(where...)
if err != nil {
return nil, err
}
var entities []*model.AppUserRole
if err = all.Structs(&entities); err != nil && err != sql.ErrNoRows {
return nil, err
}
return entities, nil
}
// Struct retrieves one record from table and converts it into given struct.
// The parameter <pointer> should be type of *struct/**struct. If type **struct is given,
// it can create the struct internally during converting.
//
// The optional parameter <where> is the same as the parameter of Model.Where function,
// see Model.Where.
//
// Note that it returns sql.ErrNoRows if there's no record retrieved with the given conditions
// from table and <pointer> is not nil.
//
// Eg:
// user := new(User)
// err := dao.User.Where("id", 1).Struct(user)
//
// user := (*User)(nil)
// err := dao.User.Where("id", 1).Struct(&user)
func (d *AppUserRoleDao) Struct(pointer interface{}, where ...interface{}) error {
return d.M.Struct(pointer, where...)
}
// Structs retrieves records from table and converts them into given struct slice.
// The parameter <pointer> should be type of *[]struct/*[]*struct. It can create and fill the struct
// slice internally during converting.
//
// The optional parameter <where> is the same as the parameter of Model.Where function,
// see Model.Where.
//
// Note that it returns sql.ErrNoRows if there's no record retrieved with the given conditions
// from table and <pointer> is not empty.
//
// Eg:
// users := ([]User)(nil)
// err := dao.User.Structs(&users)
//
// users := ([]*User)(nil)
// err := dao.User.Structs(&users)
func (d *AppUserRoleDao) Structs(pointer interface{}, where ...interface{}) error {
return d.M.Structs(pointer, where...)
}
// Scan automatically calls Struct or Structs function according to the type of parameter <pointer>.
// It calls function Struct if <pointer> is type of *struct/**struct.
// It calls function Structs if <pointer> is type of *[]struct/*[]*struct.
//
// The optional parameter <where> is the same as the parameter of Model.Where function,
// see Model.Where.
//
// Note that it returns sql.ErrNoRows if there's no record retrieved and given pointer is not empty or nil.
//
// Eg:
// user := new(User)
// err := dao.User.Where("id", 1).Scan(user)
//
// user := (*User)(nil)
// err := dao.User.Where("id", 1).Scan(&user)
//
// users := ([]User)(nil)
// err := dao.User.Scan(&users)
//
// users := ([]*User)(nil)
// err := dao.User.Scan(&users)
func (d *AppUserRoleDao) Scan(pointer interface{}, where ...interface{}) error {
return d.M.Scan(pointer, where...)
}
// Chunk iterates the table with given size and callback function.
func (d *AppUserRoleDao) Chunk(limit int, callback func(entities []*model.AppUserRole, err error) bool) {
d.M.Chunk(limit, func(result gdb.Result, err error) bool {
var entities []*model.AppUserRole
err = result.Structs(&entities)
if err == sql.ErrNoRows {
return false
}
return callback(entities, err)
})
}
// LockUpdate sets the lock for update for current operation.
func (d *AppUserRoleDao) LockUpdate() *AppUserRoleDao {
return &AppUserRoleDao{M: d.M.LockUpdate()}
}
// LockShared sets the lock in share mode for current operation.
func (d *AppUserRoleDao) LockShared() *AppUserRoleDao {
return &AppUserRoleDao{M: d.M.LockShared()}
}
// Unscoped enables/disables the soft deleting feature.
func (d *AppUserRoleDao) Unscoped() *AppUserRoleDao {
return &AppUserRoleDao{M: d.M.Unscoped()}
}

14
app/model/app_role.go Normal file
View File

@ -0,0 +1,14 @@
// ==========================================================================
// This is auto-generated by gf cli tool. Fill this file as you wish.
// ==========================================================================
package model
import (
"Gf-Vben/app/model/internal"
)
// AppRole is the golang structure for table app_role.
type AppRole internal.AppRole
// Fill with you ideas below.

14
app/model/app_user.go Normal file
View File

@ -0,0 +1,14 @@
// ==========================================================================
// This is auto-generated by gf cli tool. Fill this file as you wish.
// ==========================================================================
package model
import (
"Gf-Vben/app/model/internal"
)
// AppUser is the golang structure for table app_user.
type AppUser internal.AppUser
// Fill with you ideas below.

View File

@ -0,0 +1,14 @@
// ==========================================================================
// This is auto-generated by gf cli tool. Fill this file as you wish.
// ==========================================================================
package model
import (
"Gf-Vben/app/model/internal"
)
// AppUserRole is the golang structure for table app_user_role.
type AppUserRole internal.AppUserRole
// Fill with you ideas below.

View File

@ -0,0 +1,12 @@
// ==========================================================================
// This is auto-generated by gf cli tool. DO NOT EDIT THIS FILE MANUALLY.
// ==========================================================================
package internal
// AppRole is the golang structure for table app_role.
type AppRole struct {
Id int `orm:"id,primary" json:"id"` //
RoleName string `orm:"role_name" json:"roleName"` //
RoleValue string `orm:"role_value" json:"roleValue"` //
}

View File

@ -0,0 +1,22 @@
// ==========================================================================
// This is auto-generated by gf cli tool. DO NOT EDIT THIS FILE MANUALLY.
// ==========================================================================
package internal
import (
"github.com/gogf/gf/os/gtime"
)
// AppUser is the golang structure for table app_user.
type AppUser struct {
Id int `orm:"id,primary" json:"id"` // primary id
Username string `orm:"username,primary" json:"username"` // username
Password string `orm:"password" json:"password"` // password
Note string `orm:"note" json:"note"` //
NickName string `orm:"nick_name" json:"nickName"` // nickName
Status int `orm:"status" json:"status"` // 1:enable 2:disable
CreateAt *gtime.Time `orm:"create_at" json:"createAt"` //
UpdateAt *gtime.Time `orm:"update_at" json:"updateAt"` //
DeleteAt *gtime.Time `orm:"delete_at" json:"deleteAt"` //
}

View File

@ -0,0 +1,12 @@
// ==========================================================================
// This is auto-generated by gf cli tool. DO NOT EDIT THIS FILE MANUALLY.
// ==========================================================================
package internal
// AppUserRole is the golang structure for table app_user_role.
type AppUserRole struct {
Id int `orm:"id,primary" json:"id"` //
UserId int `orm:"user_id" json:"userId"` //
RoleId int `orm:"role_id" json:"roleId"` //
}

0
app/service/.gitkeep Normal file
View File

1
app/service/cache/token.go vendored Normal file
View File

@ -0,0 +1 @@
package cache

10
app/service/curd/curd.go Normal file
View File

@ -0,0 +1,10 @@
package curd
import "github.com/gogf/gf/frame/g"
type Curd interface {
List() (g.Map, error)
Add() error
Edit() error
Del() error
}

View File

@ -0,0 +1,11 @@
package middleware
import "github.com/gogf/gf/net/ghttp"
// 允许接口跨域请求
func CORS(r *ghttp.Request) {
corsOptions := r.Response.DefaultCORSOptions()
corsOptions.AllowHeaders += ",Access-Token"
r.Response.CORS(corsOptions)
r.Middleware.Next()
}

View File

@ -0,0 +1,139 @@
package middleware
import (
"Gf-Vben/app/dao"
jwt "github.com/gogf/gf-jwt"
"github.com/gogf/gf/crypto/gmd5"
"github.com/gogf/gf/errors/gerror"
"github.com/gogf/gf/frame/g"
"github.com/gogf/gf/net/ghttp"
"github.com/gogf/gf/os/glog"
"net/http"
"time"
)
var (
// The underlying JWT middleware.
GfJWTMiddleware *jwt.GfJWTMiddleware
)
type LoginReq struct {
Username string `p:"username" v:"required"`
Password string `p:"password" v:"required"`
}
// Initialization function,
// rewrite this function to customized your own JWT settings.
func init() {
authMiddleware, err := jwt.New(&jwt.GfJWTMiddleware{
Realm: "test zone",
Key: []byte("secret key"),
Timeout: time.Minute * 5,
MaxRefresh: time.Minute * 5,
IdentityKey: "username",
TokenLookup: "header: Authorization, query: token, cookie: jwt",
TokenHeadName: "Bearer",
TimeFunc: time.Now,
Authenticator: Authenticator,
LoginResponse: LoginResponse,
RefreshResponse: RefreshResponse,
Unauthorized: Unauthorized,
IdentityHandler: IdentityHandler,
PayloadFunc: PayloadFunc,
})
if err != nil {
glog.Fatal("JWT Error:" + err.Error())
}
GfJWTMiddleware = authMiddleware
}
// PayloadFunc is a callback function that will be called during login.
// Using this function it is possible to add additional payload data to the webtoken.
// The data is then made available during requests via c.Get("JWT_PAYLOAD").
// Note that the payload is not encrypted.
// The attributes mentioned on jwt.io can't be used as keys for the map.
// Optional, by default no additional data will be set.
func PayloadFunc(data interface{}) jwt.MapClaims {
claims := jwt.MapClaims{}
params := data.(map[string]interface{})
if len(params) > 0 {
for k, v := range params {
claims[k] = v
}
}
return claims
}
// IdentityHandler sets the identity for JWT.
func IdentityHandler(r *ghttp.Request) interface{} {
claims := jwt.ExtractClaims(r)
return claims["id"]
}
// Unauthorized is used to define customized Unauthorized callback function.
func Unauthorized(r *ghttp.Request, code int, message string) {
r.Response.WriteJson(g.Map{
"code": code,
"msg": message,
})
r.ExitAll()
}
// LoginResponse is used to define customized login-successful callback function.
func LoginResponse(r *ghttp.Request, code int, token string, expire time.Time) {
r.Response.WriteJson(g.Map{
"code": http.StatusOK,
"token": token,
"expire": expire.Format(time.RFC3339),
})
r.ExitAll()
}
// RefreshResponse is used to get a new token no matter current token is expired or not.
func RefreshResponse(r *ghttp.Request, code int, token string, expire time.Time) {
r.Response.WriteJson(g.Map{
"code": http.StatusOK,
"token": token,
"expire": expire.Format(time.RFC3339),
})
r.ExitAll()
}
// Authenticator is used to validate login parameters.
// It must return user data as user identifier, it will be stored in Claim Array.
// Check error (e) to determine the appropriate error message.
func Authenticator(r *ghttp.Request) (interface{}, error) {
req := new(LoginReq)
if err := r.Parse(req); err != nil {
return "", err
}
u, err := dao.AppUser.Where("username", req.Username).One()
if err != nil {
return nil, err
}
if u == nil {
return nil, gerror.New("用户异常")
}
if u.Status == 0 {
return nil, gerror.New("用户已禁用")
}
pw, err := gmd5.Encrypt(req.Password)
if err != nil {
return nil, err
}
if pw != u.Password {
return nil, gerror.New("用户密码错误")
}
return g.Map{
"username": u.Username,
"uuid": u.Id,
}, nil
}
func Auth(r *ghttp.Request) {
GfJWTMiddleware.MiddlewareFunc()(r)
r.Middleware.Next()
}

29
app/service/user/curd.go Normal file
View File

@ -0,0 +1,29 @@
package user
import "github.com/gogf/gf/frame/g"
type Req struct {
Page int `p:"page"`
PageSize int `p:"page_size"`
Query
}
type Query struct {
Id int `p:"id"`
Username int `p:"username"`
}
func (r Req) List() (g.Map, error) {
panic("implement me")
}
func (r Req) Add() error {
panic("implement me")
}
func (r Req) Edit() error {
panic("implement me")
}
func (r Req) Del() error {
panic("implement me")
}

View File

@ -0,0 +1,40 @@
package user
import (
"Gf-Vben/app/dao"
"Gf-Vben/app/model"
"github.com/gogf/gf/crypto/gmd5"
"github.com/gogf/gf/errors/gerror"
)
type RegisterReq struct {
Username string `p:"username" v:"required"`
Pw string `p:"password" v:"required"`
Pw2 string `p:"password2" v:"required"`
}
func (r *RegisterReq) Register() error {
result, err := dao.AppUser.FindOne("username", r.Username)
if err != nil {
return err
}
if result != nil {
return gerror.New("账号已存在")
}
if r.Pw != r.Pw2 {
return gerror.New("密码不一致")
}
pw, err := gmd5.Encrypt(r.Pw)
if err != nil {
return err
}
u := model.AppUser{
Username: r.Username,
Password: pw,
Status: 1,
}
if _, err := dao.AppUser.Save(u); err != nil {
return err
}
return nil
}

0
boot/.gitkeep Normal file
View File

7
boot/boot.go Normal file
View File

@ -0,0 +1,7 @@
package boot
// 用于应用初始化。
func init() {
//s := g.Server()
}

0
config/.gitkeep Normal file
View File

8
go.mod Normal file
View File

@ -0,0 +1,8 @@
module Gf-Vben
go 1.16
require (
github.com/gogf/gf v1.15.4
github.com/gogf/gf-jwt v1.1.2
)

View File

@ -0,0 +1,31 @@
package response
import (
"github.com/gogf/gf/net/ghttp"
)
// 数据返回通用JSON数据结构
type JsonResponse struct {
Code int `json:"code"` // 错误码((0:成功, 1:失败, >1:错误码))
Message string `json:"message"` // 提示信息
Data interface{} `json:"data"` // 返回数据(业务接口定义具体数据结构)
}
// 标准返回结果数据结构封装。
func Json(r *ghttp.Request, code int, message string, data ...interface{}) {
responseData := interface{}(nil)
if len(data) > 0 {
responseData = data[0]
}
r.Response.WriteJson(JsonResponse{
Code: code,
Message: message,
Data: responseData,
})
}
// 返回JSON数据并退出当前HTTP执行函数。
func JsonExit(r *ghttp.Request, err int, msg string, data ...interface{}) {
Json(r, err, msg, data...)
r.Exit()
}

11
main.go Normal file
View File

@ -0,0 +1,11 @@
package main
import (
_ "Gf-Vben/boot"
_ "Gf-Vben/router"
"github.com/gogf/gf/frame/g"
)
func main() {
g.Server().Run()
}

0
router/.gitkeep Normal file
View File

28
router/router.go Normal file
View File

@ -0,0 +1,28 @@
package router
import (
"Gf-Vben/app/api/curd"
"Gf-Vben/app/api/user"
"Gf-Vben/app/service/middleware"
"github.com/gogf/gf/frame/g"
"github.com/gogf/gf/net/ghttp"
)
// 你可以将路由注册放到一个文件中管理,
// 也可以按照模块拆分到不同的文件中管理,
// 但统一都放到router目录下。
func init() {
s := g.Server()
s.BindHandler("/*", func(r *ghttp.Request) {
})
s.BindMiddleware("/*", middleware.CORS)
s.BindHandler("POST:/login", middleware.GfJWTMiddleware.LoginHandler)
s.BindHandler("POST:/register", user.Register)
// 分组路由注册方式
s.Group("/api", func(group *ghttp.RouterGroup) {
group.Middleware(middleware.Auth)
group.ALL("/curd", new(curd.Controller).Curd)
group.ALL("/user/{.method}", new(user.Controller))
})
}