init model and api file

v3
veypi 2 months ago
parent 3fb1e16f80
commit 61d61f28c8

@ -1,42 +0,0 @@
#
# Makefile
# Copyright (C) 2024 veypi <i@veypi.com>
# 2024-07-31 18:38
# Distributed under terms of the MIT license.
#
db=mysql://root:123456@localhost:3306/oa
all:
@echo "Makefile needs your attention"
.PHONY:build
build:
@go build -o ./build/oa
fmt:
@goctl api format --dir ./protoc/api/
gen_sql:
@goctl model mysql ddl --database oa -d ./models -s ./protoc/sql/20240801061157_base.sql
# add sql script
# sqlx migrate --source ./protoc/sql add base
# create database
# sqlx database create -D $(db)
gen_db:
@sqlx database drop -D $(db)
@sqlx database create -D $(db)
@sqlx migrate --source ./protoc/sql run -D $(db)
gen_api: fmt
@goctl api format --dir ./protoc/api/
@goctl api go -api ./protoc/api/all.api -dir ./
ts_dir= ../oaweb/composables/api/
gen_ts: fmt
@goctl api ts -api ./protoc/api/all.api -dir $(ts_dir)
run:
@go run main.go -f ./etc/main.yaml

@ -0,0 +1,59 @@
package access
import (
"github.com/veypi/OneBD/rest"
"oa/cfg"
M "oa/models"
)
func useAccess(r rest.Router) {
r.Get("/", accessList)
r.Post("/", accessPost)
}
func accessList(x *rest.X) (any, error) {
opts := &M.AccessList{}
err := x.Parse(opts)
if err != nil {
return nil, err
}
data := make([]*M.Access, 0, 10)
query := cfg.DB()
if opts.CreatedAt != nil {
query = query.Where("created_at > ?", opts.CreatedAt)
}
if opts.UpdatedAt != nil {
query = query.Where("updated_at > ?", opts.UpdatedAt)
}
query = query.Where("app_id LIKE ?", opts.AppID)
if opts.UserID != nil {
query = query.Where("user_id LIKE ?", opts.UserID)
}
if opts.RoleID != nil {
query = query.Where("role_id LIKE ?", opts.RoleID)
}
if opts.Name != nil {
query = query.Where("name LIKE ?", opts.Name)
}
err = query.Find(&data).Error
return data, err
}
func accessPost(x *rest.X) (any, error) {
opts := &M.AccessPost{}
err := x.Parse(opts)
if err != nil {
return nil, err
}
data := &M.Access{}
data.AppID = opts.AppID
data.UserID = opts.UserID
data.RoleID = opts.RoleID
data.Name = opts.Name
data.TID = opts.TID
data.Level = opts.Level
err = cfg.DB().Create(data).Error
return data, err
}

@ -0,0 +1,16 @@
//
// Copyright (C) 2024 veypi <i@veypi.com>
// 2024-09-23 16:28:13
// Distributed under terms of the MIT license.
//
// Auto generated by OneBD. DO NOT EDIT
package access
import (
"github.com/veypi/OneBD/rest"
)
func Use(r rest.Router) {
useAccess(r)
}

@ -0,0 +1,131 @@
package app
import (
"github.com/veypi/OneBD/rest"
M "oa/models"
"oa/cfg"
"strings"
"github.com/google/uuid"
)
func useApp(r rest.Router) {
r.Delete("/:app_id", appDelete)
r.Get("/:app_id", appGet)
r.Get("/", appList)
r.Patch("/:app_id", appPatch)
r.Post("/", appPost)
r.Put("/:app_id", appPut)
}
func appDelete(x *rest.X) (any, error) {
opts := &M.AppDelete{}
err := x.Parse(opts)
if err != nil {
return nil, err
}
data := &M.App{}
err = cfg.DB().Where("id = ?", opts.ID).Delete(data).Error
return data, err
}
func appGet(x *rest.X) (any, error) {
opts := &M.AppGet{}
err := x.Parse(opts)
if err != nil {
return nil, err
}
data := &M.App{}
err = cfg.DB().Where("id = ?", opts.ID).First(data).Error
return data, err
}
func appList(x *rest.X) (any, error) {
opts := &M.AppList{}
err := x.Parse(opts)
if err != nil {
return nil, err
}
data := make([]*M.App, 0, 10)
query := cfg.DB()
if opts.Name != nil {
query = query.Where("name LIKE ?", opts.Name)
}
err = query.Find(&data).Error
return data, err
}
func appPatch(x *rest.X) (any, error) {
opts := &M.AppPatch{}
err := x.Parse(opts)
if err != nil {
return nil, err
}
data := &M.App{}
err = cfg.DB().Where("id = ?", opts.ID).First(data).Error
if err != nil {
return nil, err
}
optsMap := make(map[string]interface{})
if opts.Name != nil {
optsMap["name"] = opts.Name
}
if opts.Icon != nil {
optsMap["icon"] = opts.Icon
}
if opts.Des != nil {
optsMap["des"] = opts.Des
}
if opts.Participate != nil {
optsMap["participate"] = opts.Participate
}
if opts.InitRoleID != nil {
optsMap["init_role_id"] = opts.InitRoleID
}
err = cfg.DB().Model(data).Updates(optsMap).Error
return data, err
}
func appPost(x *rest.X) (any, error) {
opts := &M.AppPost{}
err := x.Parse(opts)
if err != nil {
return nil, err
}
data := &M.App{}
data.ID = strings.ReplaceAll(uuid.New().String(), "-", "")
data.Name = opts.Name
data.Icon = opts.Icon
data.Des = opts.Des
data.Participate = opts.Participate
err = cfg.DB().Create(data).Error
return data, err
}
func appPut(x *rest.X) (any, error) {
opts := &M.AppPut{}
err := x.Parse(opts)
if err != nil {
return nil, err
}
data := &M.App{}
err = cfg.DB().Where("id = ?", opts.ID).First(data).Error
if err != nil {
return nil, err
}
optsMap := map[string]interface{}{
"id": opts.ID,
"name": opts.Name,
"icon": opts.Icon,
"des": opts.Des,
"participate": opts.Participate,
"init_role_id": opts.InitRoleID,
}
err = cfg.DB().Model(data).Updates(optsMap).Error
return data, err
}

@ -0,0 +1,126 @@
package app
import (
"github.com/veypi/OneBD/rest"
M "oa/models"
"oa/cfg"
"strings"
"github.com/google/uuid"
)
func useAppUser(r rest.Router) {
r.Patch("/:app_user_id", appUserPatch)
r.Post("/", appUserPost)
r.Put("/:app_user_id", appUserPut)
r.Delete("/:app_user_id", appUserDelete)
r.Get("/:app_user_id", appUserGet)
r.Get("/", appUserList)
}
func appUserPatch(x *rest.X) (any, error) {
opts := &M.AppUserPatch{}
err := x.Parse(opts)
if err != nil {
return nil, err
}
data := &M.AppUser{}
err = cfg.DB().Where("id = ?", opts.ID).First(data).Error
if err != nil {
return nil, err
}
optsMap := make(map[string]interface{})
if opts.AppID != nil {
optsMap["app_id"] = opts.AppID
}
if opts.UserID != nil {
optsMap["user_id"] = opts.UserID
}
if opts.Status != nil {
optsMap["status"] = opts.Status
}
err = cfg.DB().Model(data).Updates(optsMap).Error
return data, err
}
func appUserPost(x *rest.X) (any, error) {
opts := &M.AppUserPost{}
err := x.Parse(opts)
if err != nil {
return nil, err
}
data := &M.AppUser{}
data.ID = strings.ReplaceAll(uuid.New().String(), "-", "")
data.AppID = opts.AppID
data.UserID = opts.UserID
data.Status = opts.Status
err = cfg.DB().Create(data).Error
return data, err
}
func appUserPut(x *rest.X) (any, error) {
opts := &M.AppUserPut{}
err := x.Parse(opts)
if err != nil {
return nil, err
}
data := &M.AppUser{}
err = cfg.DB().Where("id = ?", opts.ID).First(data).Error
if err != nil {
return nil, err
}
optsMap := map[string]interface{}{
"id": opts.ID,
"status": opts.Status,
}
err = cfg.DB().Model(data).Updates(optsMap).Error
return data, err
}
func appUserDelete(x *rest.X) (any, error) {
opts := &M.AppUserDelete{}
err := x.Parse(opts)
if err != nil {
return nil, err
}
data := &M.AppUser{}
err = cfg.DB().Where("id = ?", opts.ID).Delete(data).Error
return data, err
}
func appUserGet(x *rest.X) (any, error) {
opts := &M.AppUserGet{}
err := x.Parse(opts)
if err != nil {
return nil, err
}
data := &M.AppUser{}
err = cfg.DB().Where("id = ?", opts.ID).First(data).Error
return data, err
}
func appUserList(x *rest.X) (any, error) {
opts := &M.AppUserList{}
err := x.Parse(opts)
if err != nil {
return nil, err
}
data := make([]*M.AppUser, 0, 10)
query := cfg.DB()
if opts.AppID != nil {
query = query.Where("app_id LIKE ?", opts.AppID)
}
if opts.UserID != nil {
query = query.Where("user_id LIKE ?", opts.UserID)
}
if opts.Status != nil {
query = query.Where("status LIKE ?", opts.Status)
}
err = query.Find(&data).Error
return data, err
}

@ -0,0 +1,18 @@
//
// Copyright (C) 2024 veypi <i@veypi.com>
// 2024-09-23 16:28:13
// Distributed under terms of the MIT license.
//
// Auto generated by OneBD. DO NOT EDIT
package app
import (
"github.com/veypi/OneBD/rest"
)
func Use(r rest.Router) {
useApp(r)
useAppUser(r.SubRouter(":app_id/app_user"))
useResource(r.SubRouter(":app_id/resource"))
}

@ -0,0 +1,63 @@
package app
import (
"github.com/veypi/OneBD/rest"
"oa/cfg"
M "oa/models"
)
func useResource(r rest.Router) {
r.Post("/", resourcePost)
r.Delete("/", resourceDelete)
r.Get("/", resourceList)
}
func resourcePost(x *rest.X) (any, error) {
opts := &M.ResourcePost{}
err := x.Parse(opts)
if err != nil {
return nil, err
}
data := &M.Resource{}
data.AppID = opts.AppID
data.Name = opts.Name
data.Des = opts.Des
err = cfg.DB().Create(data).Error
return data, err
}
func resourceDelete(x *rest.X) (any, error) {
opts := &M.ResourceDelete{}
err := x.Parse(opts)
if err != nil {
return nil, err
}
data := &M.Resource{
AppID: opts.AppID,
Name: opts.Name,
}
err = cfg.DB().Delete(data).Error
return data, err
}
func resourceList(x *rest.X) (any, error) {
opts := &M.ResourceList{}
err := x.Parse(opts)
if err != nil {
return nil, err
}
data := make([]*M.Resource, 0, 10)
query := cfg.DB()
if opts.CreatedAt != nil {
query = query.Where("created_at > ?", opts.CreatedAt)
}
if opts.UpdatedAt != nil {
query = query.Where("updated_at > ?", opts.UpdatedAt)
}
query = query.Where("app_id = ?", opts.AppID)
err = query.Find(&data).Error
return data, err
}

@ -0,0 +1,23 @@
//
// Copyright (C) 2024 veypi <i@veypi.com>
// 2024-09-20 16:10:16
// Distributed under terms of the MIT license.
//
// Auto generated by OneBD. DO NOT EDIT
package api
import (
"github.com/veypi/OneBD/rest"
"oa/api/access"
"oa/api/app"
"oa/api/role"
"oa/api/user"
)
func Use(r rest.Router) {
access.Use(r.SubRouter("access"))
app.Use(r.SubRouter("app"))
role.Use(r.SubRouter("role"))
user.Use(r.SubRouter("user"))
}

@ -0,0 +1,16 @@
//
// Copyright (C) 2024 veypi <i@veypi.com>
// 2024-09-23 16:28:13
// Distributed under terms of the MIT license.
//
// Auto generated by OneBD. DO NOT EDIT
package role
import (
"github.com/veypi/OneBD/rest"
)
func Use(r rest.Router) {
useRole(r)
}

@ -0,0 +1,122 @@
package role
import (
"github.com/veypi/OneBD/rest"
M "oa/models"
"oa/cfg"
"strings"
"github.com/google/uuid"
)
func useRole(r rest.Router) {
r.Put("/:role_id", rolePut)
r.Delete("/:role_id", roleDelete)
r.Get("/:role_id", roleGet)
r.Get("/", roleList)
r.Patch("/:role_id", rolePatch)
r.Post("/", rolePost)
}
func rolePut(x *rest.X) (any, error) {
opts := &M.RolePut{}
err := x.Parse(opts)
if err != nil {
return nil, err
}
data := &M.Role{}
err = cfg.DB().Where("id = ?", opts.ID).First(data).Error
if err != nil {
return nil, err
}
optsMap := map[string]interface{}{
"id": opts.ID,
"name": opts.Name,
"des": opts.Des,
"app_id": opts.AppID,
}
err = cfg.DB().Model(data).Updates(optsMap).Error
return data, err
}
func roleDelete(x *rest.X) (any, error) {
opts := &M.RoleDelete{}
err := x.Parse(opts)
if err != nil {
return nil, err
}
data := &M.Role{}
err = cfg.DB().Where("id = ?", opts.ID).Delete(data).Error
return data, err
}
func roleGet(x *rest.X) (any, error) {
opts := &M.RoleGet{}
err := x.Parse(opts)
if err != nil {
return nil, err
}
data := &M.Role{}
err = cfg.DB().Where("id = ?", opts.ID).First(data).Error
return data, err
}
func roleList(x *rest.X) (any, error) {
opts := &M.RoleList{}
err := x.Parse(opts)
if err != nil {
return nil, err
}
data := make([]*M.Role, 0, 10)
query := cfg.DB()
if opts.Name != nil {
query = query.Where("name LIKE ?", opts.Name)
}
err = query.Find(&data).Error
return data, err
}
func rolePatch(x *rest.X) (any, error) {
opts := &M.RolePatch{}
err := x.Parse(opts)
if err != nil {
return nil, err
}
data := &M.Role{}
err = cfg.DB().Where("id = ?", opts.ID).First(data).Error
if err != nil {
return nil, err
}
optsMap := make(map[string]interface{})
if opts.Name != nil {
optsMap["name"] = opts.Name
}
if opts.Des != nil {
optsMap["des"] = opts.Des
}
if opts.AppID != nil {
optsMap["app_id"] = opts.AppID
}
err = cfg.DB().Model(data).Updates(optsMap).Error
return data, err
}
func rolePost(x *rest.X) (any, error) {
opts := &M.RolePost{}
err := x.Parse(opts)
if err != nil {
return nil, err
}
data := &M.Role{}
data.ID = strings.ReplaceAll(uuid.New().String(), "-", "")
data.Name = opts.Name
data.Des = opts.Des
data.AppID = opts.AppID
err = cfg.DB().Create(data).Error
return data, err
}

@ -0,0 +1,17 @@
//
// Copyright (C) 2024 veypi <i@veypi.com>
// 2024-09-23 16:28:13
// Distributed under terms of the MIT license.
//
// Auto generated by OneBD. DO NOT EDIT
package user
import (
"github.com/veypi/OneBD/rest"
)
func Use(r rest.Router) {
useUser(r)
useUserRole(r.SubRouter(":user_id/user_role"))
}

@ -0,0 +1,149 @@
package user
import (
"github.com/veypi/OneBD/rest"
M "oa/models"
"oa/cfg"
"strings"
"github.com/google/uuid"
)
func useUser(r rest.Router) {
r.Delete("/:user_id", userDelete)
r.Get("/:user_id", userGet)
r.Get("/", userList)
r.Patch("/:user_id", userPatch)
r.Post("/", userPost)
r.Put("/:user_id", userPut)
}
func userDelete(x *rest.X) (any, error) {
opts := &M.UserDelete{}
err := x.Parse(opts)
if err != nil {
return nil, err
}
data := &M.User{}
err = cfg.DB().Where("id = ?", opts.ID).Delete(data).Error
return data, err
}
func userGet(x *rest.X) (any, error) {
opts := &M.UserGet{}
err := x.Parse(opts)
if err != nil {
return nil, err
}
data := &M.User{}
err = cfg.DB().Where("id = ?", opts.ID).First(data).Error
return data, err
}
func userList(x *rest.X) (any, error) {
opts := &M.UserList{}
err := x.Parse(opts)
if err != nil {
return nil, err
}
data := make([]*M.User, 0, 10)
query := cfg.DB()
if opts.Username != nil {
query = query.Where("username LIKE ?", opts.Username)
}
if opts.Nickname != nil {
query = query.Where("nickname LIKE ?", opts.Nickname)
}
if opts.Email != nil {
query = query.Where("email LIKE ?", opts.Email)
}
if opts.Phone != nil {
query = query.Where("phone LIKE ?", opts.Phone)
}
if opts.Status != nil {
query = query.Where("status = ?", opts.Status)
}
err = query.Find(&data).Error
return data, err
}
func userPatch(x *rest.X) (any, error) {
opts := &M.UserPatch{}
err := x.Parse(opts)
if err != nil {
return nil, err
}
data := &M.User{}
err = cfg.DB().Where("id = ?", opts.ID).First(data).Error
if err != nil {
return nil, err
}
optsMap := make(map[string]interface{})
if opts.Username != nil {
optsMap["username"] = opts.Username
}
if opts.Nickname != nil {
optsMap["nickname"] = opts.Nickname
}
if opts.Icon != nil {
optsMap["icon"] = opts.Icon
}
if opts.Email != nil {
optsMap["email"] = opts.Email
}
if opts.Phone != nil {
optsMap["phone"] = opts.Phone
}
if opts.Status != nil {
optsMap["status"] = opts.Status
}
err = cfg.DB().Model(data).Updates(optsMap).Error
return data, err
}
func userPost(x *rest.X) (any, error) {
opts := &M.UserPost{}
err := x.Parse(opts)
if err != nil {
return nil, err
}
data := &M.User{}
data.ID = strings.ReplaceAll(uuid.New().String(), "-", "")
data.Username = opts.Username
data.Nickname = opts.Nickname
data.Icon = opts.Icon
data.Email = opts.Email
data.Phone = opts.Phone
data.Status = opts.Status
err = cfg.DB().Create(data).Error
return data, err
}
func userPut(x *rest.X) (any, error) {
opts := &M.UserPut{}
err := x.Parse(opts)
if err != nil {
return nil, err
}
data := &M.User{}
err = cfg.DB().Where("id = ?", opts.ID).First(data).Error
if err != nil {
return nil, err
}
optsMap := map[string]interface{}{
"id": opts.ID,
"username": opts.Username,
"nickname": opts.Nickname,
"icon": opts.Icon,
"email": opts.Email,
"phone": opts.Phone,
"status": opts.Status,
}
err = cfg.DB().Model(data).Updates(optsMap).Error
return data, err
}

@ -0,0 +1,117 @@
package user
import (
"github.com/veypi/OneBD/rest"
M "oa/models"
"oa/cfg"
"strings"
"github.com/google/uuid"
)
func useUserRole(r rest.Router) {
r.Get("/:user_role_id", userRoleGet)
r.Get("/", userRoleList)
r.Patch("/:user_role_id", userRolePatch)
r.Post("/", userRolePost)
r.Put("/:user_role_id", userRolePut)
r.Delete("/:user_role_id", userRoleDelete)
}
func userRoleGet(x *rest.X) (any, error) {
opts := &M.UserRoleGet{}
err := x.Parse(opts)
if err != nil {
return nil, err
}
data := &M.UserRole{}
err = cfg.DB().Where("id = ?", opts.ID).First(data).Error
return data, err
}
func userRoleList(x *rest.X) (any, error) {
opts := &M.UserRoleList{}
err := x.Parse(opts)
if err != nil {
return nil, err
}
data := make([]*M.UserRole, 0, 10)
query := cfg.DB()
if opts.Status != nil {
query = query.Where("status LIKE ?", opts.Status)
}
err = query.Find(&data).Error
return data, err
}
func userRolePatch(x *rest.X) (any, error) {
opts := &M.UserRolePatch{}
err := x.Parse(opts)
if err != nil {
return nil, err
}
data := &M.UserRole{}
err = cfg.DB().Where("id = ?", opts.ID).First(data).Error
if err != nil {
return nil, err
}
optsMap := make(map[string]interface{})
if opts.UserID != nil {
optsMap["user_id"] = opts.UserID
}
if opts.Status != nil {
optsMap["status"] = opts.Status
}
err = cfg.DB().Model(data).Updates(optsMap).Error
return data, err
}
func userRolePost(x *rest.X) (any, error) {
opts := &M.UserRolePost{}
err := x.Parse(opts)
if err != nil {
return nil, err
}
data := &M.UserRole{}
data.ID = strings.ReplaceAll(uuid.New().String(), "-", "")
data.UserID = opts.UserID
data.RoleID = opts.RoleID
data.Status = opts.Status
err = cfg.DB().Create(data).Error
return data, err
}
func userRolePut(x *rest.X) (any, error) {
opts := &M.UserRolePut{}
err := x.Parse(opts)
if err != nil {
return nil, err
}
data := &M.UserRole{}
err = cfg.DB().Where("id = ?", opts.ID).First(data).Error
if err != nil {
return nil, err
}
optsMap := map[string]interface{}{
"id": opts.ID,
"status": opts.Status,
}
err = cfg.DB().Model(data).Updates(optsMap).Error
return data, err
}
func userRoleDelete(x *rest.X) (any, error) {
opts := &M.UserRoleDelete{}
err := x.Parse(opts)
if err != nil {
return nil, err
}
data := &M.UserRole{}
err = cfg.DB().Where("id = ?", opts.ID).Delete(data).Error
return data, err
}

@ -0,0 +1,43 @@
//
// cfg.go
// Copyright (C) 2024 veypi <i@veypi.com>
// 2024-09-20 16:10:16
// Distributed under terms of the MIT license.
//
package cfg
import (
"github.com/veypi/OneBD/rest"
"github.com/veypi/utils/flags"
"github.com/veypi/utils/logv"
)
type config struct {
rest.RestConf
DSN string `json:"dsn"`
}
var Config = &config{}
var CMD = flags.New("oa", "the backend server of oa")
var CfgDump = CMD.SubCommand("cfg", "generate cfg file")
var configFile = CMD.String("f", "./dev.yaml", "the config file")
func init() {
CMD.StringVar(&Config.Host, "h", "0.0.0.0", "host")
CMD.IntVar(&Config.Port, "p", 4000, "port")
CMD.StringVar(&Config.LoggerLevel, "l", "info", "log level")
CMD.StringVar(&Config.DSN, "dsn", "root:123456@tcp(127.0.0.1:3306)/test?charset=utf8&parseTime=True&loc=Local", "data source name")
CMD.Before = func() error {
flags.LoadCfg(*configFile, Config)
CMD.Parse()
logv.SetLevel(logv.AssertFuncErr(logv.ParseLevel(Config.LoggerLevel)))
return nil
}
CfgDump.Command = func() error {
flags.DumpCfg(*configFile, Config)
return nil
}
}

@ -0,0 +1,52 @@
//
// db.go
// Copyright (C) 2024 veypi <i@veypi.com>
// 2024-09-20 16:10:16
// Distributed under terms of the MIT license.
//
package cfg
import (
"gorm.io/driver/mysql"
"gorm.io/gorm"
"gorm.io/gorm/logger"
)
var db *gorm.DB
var cmdDB = CMD.SubCommand("db", "database operations")
var cmdMigrate = cmdDB.SubCommand("migrate", "migrate database")
var ObjList = make([]any, 0, 10)
func init() {
cmdMigrate.Command = func() error {
// create table without constraints
DB().DisableForeignKeyConstraintWhenMigrating = true
err := DB().AutoMigrate(ObjList...)
if err != nil {
return err
}
// create constraints
DB().DisableForeignKeyConstraintWhenMigrating = false
return DB().AutoMigrate(ObjList...)
}
cmdDB.SubCommand("drop", "drop database").Command = func() error {
return DB().Migrator().DropTable(ObjList...)
}
}
func DB() *gorm.DB {
if db == nil {
var err error
db, err = gorm.Open(mysql.New(mysql.Config{
DSN: Config.DSN,
}), &gorm.Config{
Logger: logger.Default.LogMode(logger.Silent),
})
if err != nil {
panic(err)
}
}
return db
}

@ -1,38 +0,0 @@
//
// response.go
// Copyright (C) 2024 veypi <i@veypi.com>
// 2024-08-01 16:42
// Distributed under terms of the MIT license.
//
package errs
import (
"net/http"
"github.com/go-sql-driver/mysql"
"github.com/zeromicro/go-zero/core/logx"
"github.com/zeromicro/go-zero/rest/httpx"
)
func Response(w http.ResponseWriter, resp interface{}, err error) {
if err != nil {
code := http.StatusInternalServerError
msg := err.Error()
switch e := err.(type) {
case *CodeErr:
code = e.Code
msg = e.Msg
case *mysql.MySQLError:
logx.Info(e.Error())
code = http.StatusBadRequest
msg = e.Message
}
w.WriteHeader(code)
w.Write([]byte(msg))
} else if resp != nil {
httpx.OkJson(w, resp)
} else {
httpx.Ok(w)
}
}

@ -1,10 +0,0 @@
name: oa
host: 0.0.0.0
port: 4000
verbose: true
uuid: FR9P5t8debxc11aFF
db: root:123456@tcp(localhost:3306)/oa
auth:
AccessSecret: AMpjwQHwVjGsb1WC4WG6
AccessExpire: 3600

@ -1,51 +1,26 @@
module oa
go 1.21.5
go 1.22.5
replace github.com/veypi/OneBD => ../../../workspace/OneBD/
replace github.com/veypi/utils => ../../../workspace/OceanCurrent/utils/
require (
github.com/go-sql-driver/mysql v1.8.1
github.com/google/uuid v1.6.0
github.com/veypi/utils v0.3.6
github.com/zeromicro/go-zero v1.7.0
github.com/veypi/OneBD v0.0.0-00010101000000-000000000000
github.com/veypi/utils v0.3.7
gorm.io/driver/mysql v1.5.7
gorm.io/gorm v1.25.12
)
require (
filippo.io/edwards25519 v1.1.0 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/cenkalti/backoff/v4 v4.3.0 // indirect
github.com/cespare/xxhash/v2 v2.3.0 // indirect
github.com/fatih/color v1.17.0 // indirect
github.com/go-logr/logr v1.4.2 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/golang-jwt/jwt/v4 v4.5.0 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.20.0 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/openzipkin/zipkin-go v0.4.3 // indirect
github.com/pelletier/go-toml/v2 v2.2.2 // indirect
github.com/prometheus/client_golang v1.19.1 // indirect
github.com/prometheus/client_model v0.5.0 // indirect
github.com/prometheus/common v0.48.0 // indirect
github.com/prometheus/procfs v0.12.0 // indirect
github.com/spaolacci/murmur3 v1.1.0 // indirect
go.opentelemetry.io/otel v1.24.0 // indirect
go.opentelemetry.io/otel/exporters/jaeger v1.17.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.24.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.24.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.24.0 // indirect
go.opentelemetry.io/otel/exporters/stdout/stdouttrace v1.24.0 // indirect
go.opentelemetry.io/otel/exporters/zipkin v1.24.0 // indirect
go.opentelemetry.io/otel/metric v1.24.0 // indirect
go.opentelemetry.io/otel/sdk v1.24.0 // indirect
go.opentelemetry.io/otel/trace v1.24.0 // indirect
go.opentelemetry.io/proto/otlp v1.3.1 // indirect
go.uber.org/automaxprocs v1.5.3 // indirect
golang.org/x/net v0.27.0 // indirect
golang.org/x/sys v0.22.0 // indirect
golang.org/x/text v0.16.0 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20240711142825-46eb208f015d // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240701130421-f6361c86f094 // indirect
google.golang.org/grpc v1.65.0 // indirect
google.golang.org/protobuf v1.34.2 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
github.com/go-sql-driver/mysql v1.7.0 // indirect
github.com/jinzhu/inflection v1.0.0 // indirect
github.com/jinzhu/now v1.1.5 // indirect
github.com/rs/zerolog v1.17.2 // indirect
golang.org/x/net v0.0.0-20190620200207-3b0461eec859 // indirect
golang.org/x/text v0.14.0 // indirect
gopkg.in/natefinch/lumberjack.v2 v2.0.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)

@ -1,152 +1,39 @@
filippo.io/edwards25519 v1.1.0 h1:FNf4tywRC1HmFuKW5xopWpigGjJKiJSV0Cqo0cJWDaA=
filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/DATA-DOG/go-sqlmock v1.5.2 h1:OcvFkGmslmlZibjAjaHm3L//6LiuBgolP7OputlJIzU=
github.com/DATA-DOG/go-sqlmock v1.5.2/go.mod h1:88MAG/4G7SMwSE3CeA0ZKzrT5CiOU3OJ+JlNzwDqpNU=
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
github.com/cenkalti/backoff/v4 v4.3.0 h1:MyRJ/UdXutAwSAT+s3wNd7MfTIcy71VQueUuFK343L8=
github.com/cenkalti/backoff/v4 v4.3.0/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyYozVcomhLiZE=
github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs=
github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
github.com/BurntSushi/toml v1.4.0 h1:kuoIxZQy2WRRk1pttg9asf+WVv6tWQuBNVmK8+nqPr0=
github.com/BurntSushi/toml v1.4.0/go.mod h1:ukJfTF/6rtPPRCnwkur4qwRxa8vTRFBF0uk2lLoLwho=
github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4=
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/fatih/color v1.17.0 h1:GlRw1BRJxkpqUCBKzKOw098ed57fEsKeNjpTe3cSjK4=
github.com/fatih/color v1.17.0/go.mod h1:YZ7TlrGPkiz6ku9fK3TLD/pl3CpsiFyu8N92HLgmosI=
github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
github.com/go-logr/logr v1.4.2 h1:6pFjapn8bFcIbiKo3XT4j/BhANplGihG6tvd+8rYgrY=
github.com/go-logr/logr v1.4.2/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag=
github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE=
github.com/go-sql-driver/mysql v1.8.1 h1:LedoTUt/eveggdHS9qUFC1EFSa8bU2+1pZjSRpvNJ1Y=
github.com/go-sql-driver/mysql v1.8.1/go.mod h1:wEBSXgmK//2ZFJyE+qWnIsVGmvmEKlqwuVSjsCm7DZg=
github.com/golang-jwt/jwt/v4 v4.5.0 h1:7cYmW1XlMY7h7ii7UhUyChSgS5wUJEnm9uZVTGqOWzg=
github.com/golang-jwt/jwt/v4 v4.5.0/go.mod h1:m21LjoU+eqJr34lmDMbreY2eSTRJ1cv77w39/MY0Ch0=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/go-sql-driver/mysql v1.7.0 h1:ueSltNNllEqE3qcWBTD0iQd3IpL/6U+mJxLkazJ7YPc=
github.com/go-sql-driver/mysql v1.7.0/go.mod h1:OXbVy3sEdcQ2Doequ6Z5BW6fXNQTmx+9S1MCJN5yJMI=
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/grpc-ecosystem/grpc-gateway/v2 v2.20.0 h1:bkypFPDjIYGfCYD5mRBvpqxfYX1YCS1PXdKYWi8FsN0=
github.com/grpc-ecosystem/grpc-gateway/v2 v2.20.0/go.mod h1:P+Lt/0by1T8bfcF3z737NnSbmxQAppXMRziHUxPOC8k=
github.com/h2non/parth v0.0.0-20190131123155-b4df798d6542 h1:2VTzZjLZBgl62/EtslCrtky5vbi9dd7HrQPQIx6wqiw=
github.com/h2non/parth v0.0.0-20190131123155-b4df798d6542/go.mod h1:Ow0tF8D4Kplbc8s8sSb3V2oUCygFHVp8gC3Dn6U4MNI=
github.com/kardianos/service v1.2.2/go.mod h1:CIMRFEJVL+0DS1a3Nx06NaMn4Dz63Ng6O7dl0qH0zVM=
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/openzipkin/zipkin-go v0.4.3 h1:9EGwpqkgnwdEIJ+Od7QVSEIH+ocmm5nPat0G7sjsSdg=
github.com/openzipkin/zipkin-go v0.4.3/go.mod h1:M9wCJZFWCo2RiY+o1eBCEMe0Dp2S5LDHcMZmk3RmK7c=
github.com/pelletier/go-toml/v2 v2.2.2 h1:aYUidT7k73Pcl9nb2gScu7NSrKCSHIDE89b3+6Wq+LM=
github.com/pelletier/go-toml/v2 v2.2.2/go.mod h1:1t835xjRzz80PqgE6HHgN2JOsmgYu/h4qDAS4n929Rs=
github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD/E=
github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc=
github.com/jinzhu/now v1.1.5 h1:/o9tlHleP7gOFmsnYNz3RGnqzefHA47wQpKrrdTIwXQ=
github.com/jinzhu/now v1.1.5/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8=
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/prashantv/gostub v1.1.0 h1:BTyx3RfQjRHnUWaGF9oQos79AlQ5k8WNktv7VGvVH4g=
github.com/prashantv/gostub v1.1.0/go.mod h1:A5zLQHz7ieHGG7is6LLXLz7I8+3LZzsrV0P1IAHhP5U=
github.com/prometheus/client_golang v1.19.1 h1:wZWJDwK+NameRJuPGDhlnFgx8e8HN3XHQeLaYJFJBOE=
github.com/prometheus/client_golang v1.19.1/go.mod h1:mP78NwGzrVks5S2H6ab8+ZZGJLZUq1hoULYBAYBw1Ho=
github.com/prometheus/client_model v0.5.0 h1:VQw1hfvPvk3Uv6Qf29VrPF32JB6rtbgI6cYPYQjL0Qw=
github.com/prometheus/client_model v0.5.0/go.mod h1:dTiFglRmd66nLR9Pv9f0mZi7B7fk5Pm3gvsjB5tr+kI=
github.com/prometheus/common v0.48.0 h1:QO8U2CdOzSn1BBsmXJXduaaW+dY/5QLjfB8svtSzKKE=
github.com/prometheus/common v0.48.0/go.mod h1:0/KsvlIEfPQCQ5I2iNSAWKPZziNCvRs5EC6ILDTlAPc=
github.com/prometheus/procfs v0.12.0 h1:jluTpSng7V9hY0O2R9DzzJHYb2xULk9VTR1V1R/k6Bo=
github.com/prometheus/procfs v0.12.0/go.mod h1:pcuDEFsWDnvcgNzo4EEweacyhjeA9Zk3cnaOZAZEfOo=
github.com/rogpeppe/go-internal v1.10.0 h1:TMyTOH3F/DB16zRVcYyreMH6GnZZrwQVAoYjRBZyWFQ=
github.com/rogpeppe/go-internal v1.10.0/go.mod h1:UQnix2H7Ngw/k4C5ijL5+65zddjncjaFoBhdsK/akog=
github.com/rs/xid v1.2.1/go.mod h1:+uKXf+4Djp6Md1KODXJxgGQPKngRmWyn10oCKFzNHOQ=
github.com/rs/zerolog v1.17.2 h1:RMRHFw2+wF7LO0QqtELQwo8hqSmqISyCJeFeAAuWcRo=
github.com/rs/zerolog v1.17.2/go.mod h1:9nvC1axdVrAHcu/s9taAVfBuIdTZLVQmKQyvrUjF5+I=
github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
github.com/spaolacci/murmur3 v1.1.0 h1:7c1g84S4BPRrfL5Xrdp6fOJ206sU9y293DDHaoy0bLI=
github.com/spaolacci/murmur3 v1.1.0/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
github.com/stretchr/objx v0.5.2 h1:xuMeJ0Sdp5ZMRXx/aWO6RZxdr3beISkG5/G/aIRr3pY=
github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/urfave/cli/v2 v2.2.0/go.mod h1:SE9GqnLQmjVa0iPEY0f1w3ygNIYcIJ0OKPMoW2caLfQ=
github.com/veypi/utils v0.3.6 h1:czLbFXzDwMGe03RJ2NxenKhtXVSMknVKkx5tTQQfKJA=
github.com/veypi/utils v0.3.6/go.mod h1:ElH1LPatrmw7d+GPFNk7UcnSOdNFajV3P44mi6wBXh8=
github.com/zenazn/goji v0.9.0/go.mod h1:7S9M489iMyHBNxwZnk9/EHS098H4/F6TATF2mIxtB1Q=
github.com/zeromicro/go-zero v1.7.0 h1:B+y7tUVlo3qVQ6F0I0R9bi+Dq4I1QdO9ZB+dz1r0p1s=
github.com/zeromicro/go-zero v1.7.0/go.mod h1:ypW4PzQI+jUrMcNJDDQ+7YW+pE+tMua9Xj/pmtmS1Dc=
go.opentelemetry.io/otel v1.24.0 h1:0LAOdjNmQeSTzGBzduGe/rU4tZhMwL5rWgtp9Ku5Jfo=
go.opentelemetry.io/otel v1.24.0/go.mod h1:W7b9Ozg4nkF5tWI5zsXkaKKDjdVjpD4oAt9Qi/MArHo=
go.opentelemetry.io/otel/exporters/jaeger v1.17.0 h1:D7UpUy2Xc2wsi1Ras6V40q806WM07rqoCWzXu7Sqy+4=
go.opentelemetry.io/otel/exporters/jaeger v1.17.0/go.mod h1:nPCqOnEH9rNLKqH/+rrUjiMzHJdV1BlpKcTwRTyKkKI=
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.24.0 h1:t6wl9SPayj+c7lEIFgm4ooDBZVb01IhLB4InpomhRw8=
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.24.0/go.mod h1:iSDOcsnSA5INXzZtwaBPrKp/lWu/V14Dd+llD0oI2EA=
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.24.0 h1:Mw5xcxMwlqoJd97vwPxA8isEaIoxsta9/Q51+TTJLGE=
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.24.0/go.mod h1:CQNu9bj7o7mC6U7+CA/schKEYakYXWr79ucDHTMGhCM=
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.24.0 h1:Xw8U6u2f8DK2XAkGRFV7BBLENgnTGX9i4rQRxJf+/vs=
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.24.0/go.mod h1:6KW1Fm6R/s6Z3PGXwSJN2K4eT6wQB3vXX6CVnYX9NmM=
go.opentelemetry.io/otel/exporters/stdout/stdouttrace v1.24.0 h1:s0PHtIkN+3xrbDOpt2M8OTG92cWqUESvzh2MxiR5xY8=
go.opentelemetry.io/otel/exporters/stdout/stdouttrace v1.24.0/go.mod h1:hZlFbDbRt++MMPCCfSJfmhkGIWnX1h3XjkfxZUjLrIA=
go.opentelemetry.io/otel/exporters/zipkin v1.24.0 h1:3evrL5poBuh1KF51D9gO/S+N/1msnm4DaBqs/rpXUqY=
go.opentelemetry.io/otel/exporters/zipkin v1.24.0/go.mod h1:0EHgD8R0+8yRhUYJOGR8Hfg2dpiJQxDOszd5smVO9wM=
go.opentelemetry.io/otel/metric v1.24.0 h1:6EhoGWWK28x1fbpA4tYTOWBkPefTDQnb8WSGXlc88kI=
go.opentelemetry.io/otel/metric v1.24.0/go.mod h1:VYhLe1rFfxuTXLgj4CBiyz+9WYBA8pNGJgDcSFRKBco=
go.opentelemetry.io/otel/sdk v1.24.0 h1:YMPPDNymmQN3ZgczicBY3B6sf9n62Dlj9pWD3ucgoDw=
go.opentelemetry.io/otel/sdk v1.24.0/go.mod h1:KVrIYw6tEubO9E96HQpcmpTKDVn9gdv35HoYiQWGDFg=
go.opentelemetry.io/otel/trace v1.24.0 h1:CsKnnL4dUAr/0llH9FKuc698G04IrpWV0MQA/Y1YELI=
go.opentelemetry.io/otel/trace v1.24.0/go.mod h1:HPc3Xr/cOApsBI154IU0OI0HJexz+aw5uPdbs3UCjNU=
go.opentelemetry.io/proto/otlp v1.3.1 h1:TrMUixzpM0yuc/znrFTP9MMRh8trP93mkCiDVeXrui0=
go.opentelemetry.io/proto/otlp v1.3.1/go.mod h1:0X1WI4de4ZsLrrJNLAQbFeLCm3T7yBkR0XqQ7niQU+8=
go.uber.org/automaxprocs v1.5.3 h1:kWazyxZUrS3Gs4qUpbwo5kEIMGe/DAvi5Z4tl2NW4j8=
go.uber.org/automaxprocs v1.5.3/go.mod h1:eRbA25aqJrxAbsLO0xy5jVwPt7FQnRgjW+efnwa1WM0=
go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto=
go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859 h1:R/3boaszxrf1GEUWTVDzSKVwLmSJpwZ1yqXm8j0v2QI=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.27.0 h1:5K3Njcw06/l2y9vpGCSdcxWOYHOUk3dVNGDXN+FvAys=
golang.org/x/net v0.27.0/go.mod h1:dDi0PyhWNoiUOrAS8uXv/vnScO4wnHQO4mj9fn/RytE=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20201015000850-e3ed0017c211/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.22.0 h1:RI27ohtqKCnwULzJLqkv897zojh5/DwS/ENaMzUOaWI=
golang.org/x/sys v0.22.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.16.0 h1:a94ExnEXNtEwYLGJSIUxnWoxoRz/ZcCsV63ROupILh4=
golang.org/x/text v0.16.0/go.mod h1:GhwF1Be+LQoKShO3cGOHzqOgRrGaYc9AvblQOmPVHnI=
golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
golang.org/x/tools v0.0.0-20190828213141-aed303cbaa74/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
google.golang.org/genproto/googleapis/api v0.0.0-20240711142825-46eb208f015d h1:kHjw/5UfflP/L5EbledDrcG4C2597RtymmGRZvHiCuY=
google.golang.org/genproto/googleapis/api v0.0.0-20240711142825-46eb208f015d/go.mod h1:mw8MG/Qz5wfgYr6VqVCiZcHe/GJEfI+oGGDCohaVgB0=
google.golang.org/genproto/googleapis/rpc v0.0.0-20240701130421-f6361c86f094 h1:BwIjyKYGsK9dMCBOorzRri8MQwmi7mT9rGHsCEinZkA=
google.golang.org/genproto/googleapis/rpc v0.0.0-20240701130421-f6361c86f094/go.mod h1:Ue6ibwXGpU+dqIcODieyLOcgj7z8+IcskoNIgZxtrFY=
google.golang.org/grpc v1.65.0 h1:bs/cUb4lp1G5iImFFd3u5ixQzweKizoZJAwBNLR42lc=
google.golang.org/grpc v1.65.0/go.mod h1:WgYC2ypjlB0EiQi6wdKixMqukr6lBc0Vo+oOgjrM5ZQ=
google.golang.org/protobuf v1.34.2 h1:6xV6lTsCfpGD21XK49h7MhtcApnLqkfYgPcdHftf6hg=
google.golang.org/protobuf v1.34.2/go.mod h1:qYOHts0dSfpeUzUFpOMr/WGzszTmLH+DiWniOlNbLDw=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
gopkg.in/h2non/gock.v1 v1.1.2 h1:jBbHXgGBK/AoPVfJh5x4r/WxIrElvbLel8TCZkkZJoY=
gopkg.in/h2non/gock.v1 v1.1.2/go.mod h1:n7UGz/ckNChHiK05rDoiC4MYSunEC/lyaUm2WWaDva0=
gopkg.in/natefinch/lumberjack.v2 v2.0.0 h1:1Lc07Kr7qY4U2YPouBjpCLxpiyxIVoxqXgkXLknAOE8=
gopkg.in/natefinch/lumberjack.v2 v2.0.0/go.mod h1:l0ndWWf7gzL7RNwBG7wST/UCcT4T24xpD6X8LsfU/+k=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
k8s.io/utils v0.0.0-20240711033017-18e509b52bc8 h1:pUdcCO1Lk/tbT5ztQWOBi5HBgbBP1J8+AsQnQCKsi8A=
k8s.io/utils v0.0.0-20240711033017-18e509b52bc8/go.mod h1:OLgZIPagt7ERELqWJFomSt595RzquPNLL48iOWgYOg0=
gorm.io/driver/mysql v1.5.7 h1:MndhOPYOfEp2rHKgkZIhJ16eVUIRf2HmzgoPmh7FCWo=
gorm.io/driver/mysql v1.5.7/go.mod h1:sEtPWMiqiN1N1cMXoXmBbd8C6/l+TESwriotuRRpkDM=
gorm.io/gorm v1.25.7/go.mod h1:hbnx/Oo0ChWMn1BIhpy1oYozzpM15i4YPuHDmfYtwg8=
gorm.io/gorm v1.25.12 h1:I0u8i2hWQItBq1WfE0o2+WuL9+8L21K9e2HHSTE/0f8=
gorm.io/gorm v1.25.12/go.mod h1:xh7N7RHfYlNc5EmcI/El95gXusucDrQnHXe0+CgWcLQ=

@ -1,9 +0,0 @@
package config
import "github.com/zeromicro/go-zero/rest"
type Config struct {
rest.RestConf
DB string
UUID string
}

@ -1,29 +0,0 @@
package app
import (
"fmt"
"net/http"
"oa/errs"
"oa/internal/logic/app"
"oa/internal/svc"
"oa/internal/types"
"github.com/zeromicro/go-zero/rest/httpx"
)
func LoginHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.AppReq
if err := httpx.Parse(r, &req); err != nil {
errs.Response(w, nil, err)
return
}
fmt.Printf("\n|%v|\n", req)
l := app.NewLoginLogic(r.Context(), svcCtx)
resp, err := l.Login(&req)
errs.Response(w, resp, err)
}
}

@ -1,60 +0,0 @@
// Code generated by goctl. DO NOT EDIT.
package handler
import (
"net/http"
app "oa/internal/handler/app"
user "oa/internal/handler/user"
"oa/internal/svc"
"github.com/zeromicro/go-zero/rest"
)
func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
server.AddRoutes(
[]rest.Route{
{
Method: http.MethodGet,
Path: "/login/:pa",
Handler: app.LoginHandler(serverCtx),
},
},
rest.WithPrefix("/api/app"),
)
server.AddRoutes(
[]rest.Route{
{
Method: http.MethodPost,
Path: "/",
Handler: user.RegHandler(serverCtx),
},
{
Method: http.MethodHead,
Path: "/:id",
Handler: user.LoginHandler(serverCtx),
},
},
rest.WithPrefix("/api/user"),
)
server.AddRoutes(
rest.WithMiddlewares(
[]rest.Middleware{serverCtx.Auth},
[]rest.Route{
{
Method: http.MethodGet,
Path: "/",
Handler: user.ListHandler(serverCtx),
},
{
Method: http.MethodGet,
Path: "/:id",
Handler: user.GetHandler(serverCtx),
},
}...,
),
rest.WithPrefix("/api/user"),
)
}

@ -1,26 +0,0 @@
package user
import (
"net/http"
"oa/errs"
"github.com/zeromicro/go-zero/rest/httpx"
"oa/internal/logic/user"
"oa/internal/svc"
"oa/internal/types"
)
func GetHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.GetReq
if err := httpx.Parse(r, &req); err != nil {
errs.Response(w, nil, err)
return
}
l := user.NewGetLogic(r.Context(), svcCtx)
resp, err := l.Get(&req)
errs.Response(w, resp, err)
}
}

@ -1,26 +0,0 @@
package user
import (
"net/http"
"oa/errs"
"github.com/zeromicro/go-zero/rest/httpx"
"oa/internal/logic/user"
"oa/internal/svc"
"oa/internal/types"
)
func ListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.ListReq
if err := httpx.Parse(r, &req); err != nil {
errs.Response(w, nil, err)
return
}
l := user.NewListLogic(r.Context(), svcCtx)
resp, err := l.List(&req)
errs.Response(w, resp, err)
}
}

@ -1,26 +0,0 @@
package user
import (
"net/http"
"oa/errs"
"github.com/zeromicro/go-zero/rest/httpx"
"oa/internal/logic/user"
"oa/internal/svc"
"oa/internal/types"
)
func LoginHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.LoginReq
if err := httpx.Parse(r, &req); err != nil {
errs.Response(w, nil, err)
return
}
l := user.NewLoginLogic(r.Context(), svcCtx)
_, err := l.Login(&req)
errs.Response(w, nil, err)
}
}

@ -1,26 +0,0 @@
package user
import (
"net/http"
"oa/errs"
"oa/internal/logic/user"
"oa/internal/svc"
"oa/internal/types"
"github.com/zeromicro/go-zero/rest/httpx"
)
func RegHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.RegReq
if err := httpx.Parse(r, &req); err != nil {
errs.Response(w, nil, err)
return
}
l := user.NewRegLogic(r.Context(), svcCtx)
err := l.Reg(&req)
errs.Response(w, nil, err)
}
}

@ -1,29 +0,0 @@
package app
import (
"context"
"oa/internal/svc"
"oa/internal/types"
"github.com/zeromicro/go-zero/core/logx"
)
type LoginLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewLoginLogic(ctx context.Context, svcCtx *svc.ServiceContext) *LoginLogic {
return &LoginLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *LoginLogic) Login(req *types.AppReq) (resp *types.AppResp, err error) {
// todo: add your logic here and delete this line
return
}

@ -1,30 +0,0 @@
package user
import (
"context"
"oa/internal/svc"
"oa/internal/types"
"github.com/zeromicro/go-zero/core/logx"
)
type GetLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewGetLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetLogic {
return &GetLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *GetLogic) Get(req *types.GetReq) (resp *types.UserResp, err error) {
// todo: add your logic here and delete this line
return
}

@ -1,30 +0,0 @@
package user
import (
"context"
"oa/internal/svc"
"oa/internal/types"
"github.com/zeromicro/go-zero/core/logx"
)
type ListLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ListLogic {
return &ListLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *ListLogic) List(req *types.ListReq) (resp []types.UserResp, err error) {
// todo: add your logic here and delete this line
return
}

@ -1,65 +0,0 @@
package user
import (
"context"
"database/sql"
"fmt"
"strings"
"time"
"oa/errs"
"oa/internal/svc"
"oa/internal/types"
"oa/models"
"github.com/google/uuid"
"github.com/veypi/utils"
"github.com/zeromicro/go-zero/core/logx"
)
type LoginLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewLoginLogic(ctx context.Context, svcCtx *svc.ServiceContext) *LoginLogic {
return &LoginLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *LoginLogic) Login(req *types.LoginReq) (string, error) {
// todo: add your logic here and delete this line
m := models.NewUserModel(l.svcCtx.Sqlx())
fmt.Printf("\n|%v|\n", req)
var u *models.User
var err error
switch req.Typ {
case "email":
u, err = m.FindOneByEmail(l.ctx, sql.NullString{String: req.Id, Valid: true})
case "phone":
u, err = m.FindOneByPhone(l.ctx, sql.NullString{String: req.Id, Valid: true})
default:
u, err = m.FindOneByUsername(l.ctx, req.Id)
}
if err != nil {
return "", errs.UserNotFound.WithErr(err)
}
temp, err := utils.AesDecrypt(u.CheckCode, []byte(req.Pwd))
if err != nil || temp != u.RealCode {
return "", errs.UserPwdInvalid
}
t := models.Token{
Code: strings.ReplaceAll(uuid.New().String(), "-", ""),
Expired: time.Now().Add(time.Hour * 24),
ClientId: req.Client,
AppId: l.svcCtx.Config.UUID,
UserId: u.Id,
}
_, err = models.NewTokenModel(l.svcCtx.Sqlx()).Insert(l.ctx, &t)
return "", err
}

@ -1,56 +0,0 @@
package user
import (
"context"
"fmt"
"math/rand"
"strings"
"time"
"oa/errs"
"oa/internal/svc"
"oa/internal/types"
"oa/models"
"github.com/google/uuid"
"github.com/veypi/utils"
"github.com/zeromicro/go-zero/core/logx"
)
type RegLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewRegLogic(ctx context.Context, svcCtx *svc.ServiceContext) *RegLogic {
return &RegLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *RegLogic) Reg(req *types.RegReq) error {
// todo: add your logic here and delete this line
r := rand.New(rand.NewSource(time.Now().UnixNano()))
m := models.NewUserModel(l.svcCtx.Sqlx())
u := &models.User{
Id: strings.ReplaceAll(uuid.New().String(), "-", ""),
Created: time.Now(),
Updated: time.Now(),
Username: req.Username,
RealCode: utils.RandSeq(32),
Icon: fmt.Sprintf("/media/icon/default/%04d.jpg", r.Intn(230)),
Space: 300,
}
var err error
u.CheckCode, err = utils.AesEncrypt(u.RealCode, []byte(req.Pwd))
if err != nil {
return errs.ArgsInvalid.WithErr(err)
}
l.Infof("user: %v", u.Id)
_, err = m.Insert(l.ctx, u)
return err
}

@ -1,25 +0,0 @@
package middleware
import (
"context"
"net/http"
)
type AuthMiddleware struct {
ID string `json:"id"`
}
func NewAuthMiddleware() *AuthMiddleware {
return &AuthMiddleware{}
}
func (m *AuthMiddleware) Handle(next http.HandlerFunc) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
// TODO generate middleware implement function, delete after code implementation
// Passthrough to next handler if need
// val := r.Header.Get("User-Agent")
ctx := context.WithValue(r.Context(), "u", "123")
next(w, r.WithContext(ctx))
}
}

@ -1,29 +0,0 @@
package svc
import (
"oa/internal/config"
"oa/internal/middleware"
"github.com/zeromicro/go-zero/core/stores/sqlx"
"github.com/zeromicro/go-zero/rest"
)
type ServiceContext struct {
Config config.Config
Auth rest.Middleware
_conn sqlx.SqlConn
}
func (s *ServiceContext) Sqlx() sqlx.SqlConn {
if s._conn == nil {
s._conn = sqlx.NewMysql(s.Config.DB)
}
return s._conn
}
func NewServiceContext(c config.Config) *ServiceContext {
return &ServiceContext{
Config: c,
Auth: middleware.NewAuthMiddleware().Handle,
}
}

@ -1,53 +0,0 @@
// Code generated by goctl. DO NOT EDIT.
package types
type AppReq struct {
Appname string `form:"username"`
Password string `json:"password"`
Pa string `path:"pa"`
}
type AppResp struct {
Id int64 `json:"id"`
Name string `json:"name"`
Token string `json:"token"`
ExpireAt string `json:"expireAt"`
}
type LoginReq struct {
Id string `path:"id"`
Pwd string `form:"pwd"`
Client string `form:"client"`
Typ string `form:"typ,optional"`
}
type RegReq struct {
Username string `json:"username"`
Pwd string `json:"pwd"`
}
type Auth struct {
Authorization string `header:"authorization"`
}
type GetReq struct {
Id int64 `path:"id"`
}
type ListReq struct {
Username string `query:"username"`
}
type UserResp struct {
Id string `json:"id"`
Created uint `json:"created"`
Updated uint `json:"updated"`
Username string `json:"username"`
Nickname string `json:"nickname"`
Email string `json:"email"`
Phone string `json:"phone"`
Icon string `json:"icon"`
Status int64 `json:"status"` // 状态0ok1disabled
Used int64 `json:"used"`
Space int64 `json:"space"`
}

@ -1,31 +1,41 @@
//
// main.go
// Copyright (C) 2024 veypi <i@veypi.com>
// 2024-09-20 16:10:16
// Distributed under terms of the MIT license.
//
package main
import (
"flag"
"fmt"
"oa/internal/config"
"oa/internal/handler"
"oa/internal/svc"
"oa/api"
"oa/cfg"
_ "oa/models"
"github.com/zeromicro/go-zero/core/conf"
"github.com/zeromicro/go-zero/rest"
"github.com/veypi/OneBD/rest"
"github.com/veypi/OneBD/rest/middlewares"
"github.com/veypi/utils/logv"
)
var configFile = flag.String("f", "etc/main.yaml", "the config file")
func main() {
flag.Parse()
var c config.Config
conf.MustLoad(*configFile, &c)
server := rest.MustNewServer(c.RestConf)
defer server.Stop()
cfg.CMD.Command = runWeb
cfg.CMD.Parse()
err := cfg.CMD.Run()
if err != nil {
logv.Warn().Msg(err.Error())
}
}
ctx := svc.NewServiceContext(c)
handler.RegisterHandlers(server, ctx)
func runWeb() error {
app, err := rest.New(&cfg.Config.RestConf)
if err != nil {
return err
}
apiRouter := app.Router().SubRouter("api")
api.Use(apiRouter)
fmt.Printf("Starting server at %s:%d...\n", c.Host, c.Port)
server.Start()
apiRouter.Use(middlewares.JsonResponse)
apiRouter.SetErrFunc(middlewares.JsonErrorResponse)
app.Router().Print()
return app.Run()
}

@ -0,0 +1,21 @@
package models
import "time"
type AccessList struct {
CreatedAt *time.Time `json:"created_at" parse:"query"`
UpdatedAt *time.Time `json:"updated_at" parse:"query"`
AppID string `json:"app_id" gorm:"index;type:varchar(32)" parse:"json"`
UserID *string `json:"user_id" gorm:"index;type:varchar(32);default: null" parse:"json"`
RoleID *string `json:"role_id" gorm:"index;type:varchar(32);default: null" parse:"json"`
Name *string `json:"name" parse:"json"`
}
type AccessPost struct {
AppID string `json:"app_id" gorm:"index;type:varchar(32)" parse:"json"`
UserID *string `json:"user_id" gorm:"index;type:varchar(32);default: null" parse:"json"`
RoleID *string `json:"role_id" gorm:"index;type:varchar(32);default: null" parse:"json"`
Name string `json:"name" parse:"json"`
TID string `json:"tid" parse:"json"`
Level string `json:"level" parse:"json"`
}

@ -0,0 +1,24 @@
//
// access.go
// Copyright (C) 2024 veypi <i@veypi.com>
// 2024-09-23 16:21
// Distributed under terms of the MIT license.
//
package models
type Access struct {
BaseDate
AppID string `json:"app_id" gorm:"index;type:varchar(32)" methods:"post,list" parse:"json"`
App *App `json:"app" gorm:"foreignKey:ID;references:AppID"`
UserID *string `json:"user_id" gorm:"index;type:varchar(32);default: null" methods:"post,list" parse:"json"`
User *User `json:"user"`
RoleID *string `json:"role_id" gorm:"index;type:varchar(32);default: null" methods:"post,list" parse:"json"`
Role *Role `json:"role"`
Name string `json:"name" methods:"post,*list" parse:"json"`
TID string `json:"tid" methods:"post" parse:"json"`
Level string `json:"level" methods:"post" parse:"json"`
}

@ -1,29 +0,0 @@
package models
import "github.com/zeromicro/go-zero/core/stores/sqlx"
var _ AccessModel = (*customAccessModel)(nil)
type (
// AccessModel is an interface to be customized, add more methods here,
// and implement the added methods in customAccessModel.
AccessModel interface {
accessModel
withSession(session sqlx.Session) AccessModel
}
customAccessModel struct {
*defaultAccessModel
}
)
// NewAccessModel returns a model for the database table.
func NewAccessModel(conn sqlx.SqlConn) AccessModel {
return &customAccessModel{
defaultAccessModel: newAccessModel(conn),
}
}
func (m *customAccessModel) withSession(session sqlx.Session) AccessModel {
return NewAccessModel(sqlx.NewSqlConnFromSession(session))
}

@ -1,92 +0,0 @@
// Code generated by goctl. DO NOT EDIT.
package models
import (
"context"
"database/sql"
"fmt"
"strings"
"time"
"github.com/zeromicro/go-zero/core/stores/builder"
"github.com/zeromicro/go-zero/core/stores/sqlx"
"github.com/zeromicro/go-zero/core/stringx"
)
var (
accessFieldNames = builder.RawFieldNames(&Access{})
accessRows = strings.Join(accessFieldNames, ",")
accessRowsExpectAutoSet = strings.Join(stringx.Remove(accessFieldNames, "`id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), ",")
accessRowsWithPlaceHolder = strings.Join(stringx.Remove(accessFieldNames, "`id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), "=?,") + "=?"
)
type (
accessModel interface {
Insert(ctx context.Context, data *Access) (sql.Result, error)
FindOne(ctx context.Context, id int64) (*Access, error)
Update(ctx context.Context, data *Access) error
Delete(ctx context.Context, id int64) error
}
defaultAccessModel struct {
conn sqlx.SqlConn
table string
}
Access struct {
Id int64 `db:"id"`
Created time.Time `db:"created"`
Updated time.Time `db:"updated"`
AppId string `db:"app_id"`
AccessId int64 `db:"access_id"`
Name string `db:"name"`
RoleId sql.NullString `db:"role_id"`
UserId sql.NullString `db:"user_id"`
Rid sql.NullString `db:"rid"` // 资源子id
Level int64 `db:"level"`
}
)
func newAccessModel(conn sqlx.SqlConn) *defaultAccessModel {
return &defaultAccessModel{
conn: conn,
table: "`access`",
}
}
func (m *defaultAccessModel) Delete(ctx context.Context, id int64) error {
query := fmt.Sprintf("delete from %s where `id` = ?", m.table)
_, err := m.conn.ExecCtx(ctx, query, id)
return err
}
func (m *defaultAccessModel) FindOne(ctx context.Context, id int64) (*Access, error) {
query := fmt.Sprintf("select %s from %s where `id` = ? limit 1", accessRows, m.table)
var resp Access
err := m.conn.QueryRowCtx(ctx, &resp, query, id)
switch err {
case nil:
return &resp, nil
case sqlx.ErrNotFound:
return nil, ErrNotFound
default:
return nil, err
}
}
func (m *defaultAccessModel) Insert(ctx context.Context, data *Access) (sql.Result, error) {
query := fmt.Sprintf("insert into %s (%s) values (?, ?, ?, ?, ?, ?, ?, ?, ?)", m.table, accessRowsExpectAutoSet)
ret, err := m.conn.ExecCtx(ctx, query, data.Created, data.Updated, data.AppId, data.AccessId, data.Name, data.RoleId, data.UserId, data.Rid, data.Level)
return ret, err
}
func (m *defaultAccessModel) Update(ctx context.Context, data *Access) error {
query := fmt.Sprintf("update %s set %s where `id` = ?", m.table, accessRowsWithPlaceHolder)
_, err := m.conn.ExecCtx(ctx, query, data.Created, data.Updated, data.AppId, data.AccessId, data.Name, data.RoleId, data.UserId, data.Rid, data.Level, data.Id)
return err
}
func (m *defaultAccessModel) tableName() string {
return m.table
}

@ -0,0 +1,117 @@
package models
import (
"time"
)
type AppDelete struct {
ID string `json:"id" gorm:"primaryKey;type:varchar(32)" parse:"path@app_id"`
}
type AppGet struct {
ID string `json:"id" gorm:"primaryKey;type:varchar(32)" parse:"path@app_id"`
Name string `json:"name" parse:"json"`
}
type AppList struct {
Name *string `json:"name" parse:"json"`
}
type AppPatch struct {
ID string `json:"id" gorm:"primaryKey;type:varchar(32)" parse:"path@app_id"`
Name *string `json:"name" parse:"json"`
Icon *string `json:"icon" parse:"json"`
Des *string `json:"des" parse:"json"`
Participate *string `json:"participate" gorm:"default:auto" parse:"json"`
InitRoleID *string `json:"init_role_id" gorm:"index;type:varchar(32)" parse:"json"`
}
type AppPost struct {
Name string `json:"name" parse:"json"`
Icon string `json:"icon" parse:"json"`
Des string `json:"des" parse:"json"`
Participate string `json:"participate" gorm:"default:auto" parse:"json"`
}
type AppPut struct {
ID string `json:"id" gorm:"primaryKey;type:varchar(32)" parse:"path@app_id"`
Name string `json:"name" parse:"json"`
Icon string `json:"icon" parse:"json"`
Des string `json:"des" parse:"json"`
Participate string `json:"participate" gorm:"default:auto" parse:"json"`
InitRoleID string `json:"init_role_id" gorm:"index;type:varchar(32)" parse:"json"`
}
type AppUserDelete struct {
ID string `json:"id" gorm:"primaryKey;type:varchar(32)" parse:"path@app_user_id"`
}
type AppUserGet struct {
ID string `json:"id" gorm:"primaryKey;type:varchar(32)" parse:"path@app_user_id"`
AppID string `json:"app_id" parse:"path"`
UserID string `json:"user_id" parse:"path"`
}
type AppUserList struct {
AppID *string `json:"app_id" parse:"path"`
UserID *string `json:"user_id" parse:"path"`
Status *string `json:"status" parse:"json"`
}
type AppUserPatch struct {
ID string `json:"id" gorm:"primaryKey;type:varchar(32)" parse:"path@app_user_id"`
AppID *string `json:"app_id" parse:"path"`
UserID *string `json:"user_id" parse:"path"`
Status *string `json:"status" parse:"json"`
}
type AppUserPost struct {
AppID string `json:"app_id" parse:"path"`
UserID string `json:"user_id" parse:"path"`
Status string `json:"status" parse:"json"`
}
type AppUserPut struct {
ID string `json:"id" gorm:"primaryKey;type:varchar(32)" parse:"path@app_user_id"`
Status string `json:"status" parse:"json"`
}
type ResourceDelete struct {
AppID string `json:"app_id" gorm:"primaryKey;type:varchar(32)" parse:"json"`
Name string `json:"name" gorm:"primaryKey" parse:"json"`
}
type ResourceList struct {
CreatedAt *time.Time `json:"created_at" parse:"query"`
UpdatedAt *time.Time `json:"updated_at" parse:"query"`
AppID string `json:"app_id" gorm:"primaryKey;type:varchar(32)" parse:"json"`
}
type ResourcePost struct {
AppID string `json:"app_id" gorm:"primaryKey;type:varchar(32)" parse:"json"`
Name string `json:"name" gorm:"primaryKey" parse:"json"`
Des string `json:"des" parse:"json"`
}

@ -0,0 +1,33 @@
package models
import ()
type App struct {
BaseModel
Name string `json:"name" methods:"get,post,put,*patch,*list" parse:"json"`
Icon string `json:"icon" methods:"post,put,*patch" parse:"json"`
Des string `json:"des" methods:"post,put,*patch" parse:"json"`
Participate string `json:"participate" gorm:"default:auto" methods:"post,put,*patch" parse:"json"`
InitRoleID string `json:"init_role_id" gorm:"index;type:varchar(32)" methods:"put,*patch" parse:"json"`
InitRole *Role `json:"init_role" gorm:"foreignKey:ID;references:InitRoleID"`
InitUrl string `json:"init_url"`
UserCount uint `json:"user_count"`
Key string `json:"-"`
}
type AppUser struct {
BaseModel
AppID string `json:"app_id" methods:"get,*list,post,*patch" parse:"path"`
App *App `json:"app"`
UserID string `json:"user_id" methods:"get,*list,post,*patch" parse:"path"`
User *User `json:"user"`
Status string `json:"status" methods:"post,put,*patch,*list" parse:"json"`
}
type Resource struct {
BaseDate
AppID string `json:"app_id" gorm:"primaryKey;type:varchar(32)" methods:"post,list,delete" parse:"json"`
App *App `json:"app" gorm:"foreignKey:ID;references:AppID"`
Name string `json:"name" gorm:"primaryKey" methods:"post,delete" parse:"json"`
Des string `json:"des" methods:"post" parse:"json"`
}

@ -1,29 +0,0 @@
package models
import "github.com/zeromicro/go-zero/core/stores/sqlx"
var _ AppModel = (*customAppModel)(nil)
type (
// AppModel is an interface to be customized, add more methods here,
// and implement the added methods in customAppModel.
AppModel interface {
appModel
withSession(session sqlx.Session) AppModel
}
customAppModel struct {
*defaultAppModel
}
)
// NewAppModel returns a model for the database table.
func NewAppModel(conn sqlx.SqlConn) AppModel {
return &customAppModel{
defaultAppModel: newAppModel(conn),
}
}
func (m *customAppModel) withSession(session sqlx.Session) AppModel {
return NewAppModel(sqlx.NewSqlConnFromSession(session))
}

@ -1,96 +0,0 @@
// Code generated by goctl. DO NOT EDIT.
package models
import (
"context"
"database/sql"
"fmt"
"strings"
"time"
"github.com/zeromicro/go-zero/core/stores/builder"
"github.com/zeromicro/go-zero/core/stores/sqlx"
"github.com/zeromicro/go-zero/core/stringx"
)
var (
appFieldNames = builder.RawFieldNames(&App{})
appRows = strings.Join(appFieldNames, ",")
appRowsExpectAutoSet = strings.Join(stringx.Remove(appFieldNames, "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), ",")
appRowsWithPlaceHolder = strings.Join(stringx.Remove(appFieldNames, "`id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), "=?,") + "=?"
)
type (
appModel interface {
Insert(ctx context.Context, data *App) (sql.Result, error)
FindOne(ctx context.Context, id string) (*App, error)
Update(ctx context.Context, data *App) error
Delete(ctx context.Context, id string) error
}
defaultAppModel struct {
conn sqlx.SqlConn
table string
}
App struct {
Id string `db:"id"`
Created time.Time `db:"created"`
Updated time.Time `db:"updated"`
Key string `db:"_key"`
Name string `db:"name"`
Icon string `db:"icon"`
Des sql.NullString `db:"des"`
UserCount int64 `db:"user_count"`
Hide int64 `db:"hide"`
JoinMethod int64 `db:"join_method"`
RoleId string `db:"role_id"`
Host string `db:"host"`
Redirect string `db:"redirect"`
Status int64 `db:"status"` // 状态0ok1disabled
}
)
func newAppModel(conn sqlx.SqlConn) *defaultAppModel {
return &defaultAppModel{
conn: conn,
table: "`app`",
}
}
func (m *defaultAppModel) Delete(ctx context.Context, id string) error {
query := fmt.Sprintf("delete from %s where `id` = ?", m.table)
_, err := m.conn.ExecCtx(ctx, query, id)
return err
}
func (m *defaultAppModel) FindOne(ctx context.Context, id string) (*App, error) {
query := fmt.Sprintf("select %s from %s where `id` = ? limit 1", appRows, m.table)
var resp App
err := m.conn.QueryRowCtx(ctx, &resp, query, id)
switch err {
case nil:
return &resp, nil
case sqlx.ErrNotFound:
return nil, ErrNotFound
default:
return nil, err
}
}
func (m *defaultAppModel) Insert(ctx context.Context, data *App) (sql.Result, error) {
query := fmt.Sprintf("insert into %s (%s) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", m.table, appRowsExpectAutoSet)
ret, err := m.conn.ExecCtx(ctx, query, data.Id, data.Created, data.Updated, data.Key, data.Name, data.Icon, data.Des, data.UserCount, data.Hide, data.JoinMethod, data.RoleId, data.Host, data.Redirect, data.Status)
return ret, err
}
func (m *defaultAppModel) Update(ctx context.Context, data *App) error {
query := fmt.Sprintf("update %s set %s where `id` = ?", m.table, appRowsWithPlaceHolder)
_, err := m.conn.ExecCtx(ctx, query, data.Created, data.Updated, data.Key, data.Name, data.Icon, data.Des, data.UserCount, data.Hide, data.JoinMethod, data.RoleId, data.Host, data.Redirect, data.Status, data.Id)
return err
}
func (m *defaultAppModel) tableName() string {
return m.table
}

@ -1,29 +0,0 @@
package models
import "github.com/zeromicro/go-zero/core/stores/sqlx"
var _ AppUserModel = (*customAppUserModel)(nil)
type (
// AppUserModel is an interface to be customized, add more methods here,
// and implement the added methods in customAppUserModel.
AppUserModel interface {
appUserModel
withSession(session sqlx.Session) AppUserModel
}
customAppUserModel struct {
*defaultAppUserModel
}
)
// NewAppUserModel returns a model for the database table.
func NewAppUserModel(conn sqlx.SqlConn) AppUserModel {
return &customAppUserModel{
defaultAppUserModel: newAppUserModel(conn),
}
}
func (m *customAppUserModel) withSession(session sqlx.Session) AppUserModel {
return NewAppUserModel(sqlx.NewSqlConnFromSession(session))
}

@ -1,103 +0,0 @@
// Code generated by goctl. DO NOT EDIT.
package models
import (
"context"
"database/sql"
"fmt"
"strings"
"time"
"github.com/zeromicro/go-zero/core/stores/builder"
"github.com/zeromicro/go-zero/core/stores/sqlx"
"github.com/zeromicro/go-zero/core/stringx"
)
var (
appUserFieldNames = builder.RawFieldNames(&AppUser{})
appUserRows = strings.Join(appUserFieldNames, ",")
appUserRowsExpectAutoSet = strings.Join(stringx.Remove(appUserFieldNames, "`id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), ",")
appUserRowsWithPlaceHolder = strings.Join(stringx.Remove(appUserFieldNames, "`id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), "=?,") + "=?"
)
type (
appUserModel interface {
Insert(ctx context.Context, data *AppUser) (sql.Result, error)
FindOne(ctx context.Context, id int64) (*AppUser, error)
FindOneByUserIdAppId(ctx context.Context, userId string, appId string) (*AppUser, error)
Update(ctx context.Context, data *AppUser) error
Delete(ctx context.Context, id int64) error
}
defaultAppUserModel struct {
conn sqlx.SqlConn
table string
}
AppUser struct {
Id int64 `db:"id"`
Created time.Time `db:"created"`
Updated time.Time `db:"updated"`
AppId string `db:"app_id"`
UserId string `db:"user_id"`
Status int64 `db:"status"` // 0: ok,1:disabled,2:applying,3:deny
}
)
func newAppUserModel(conn sqlx.SqlConn) *defaultAppUserModel {
return &defaultAppUserModel{
conn: conn,
table: "`app_user`",
}
}
func (m *defaultAppUserModel) Delete(ctx context.Context, id int64) error {
query := fmt.Sprintf("delete from %s where `id` = ?", m.table)
_, err := m.conn.ExecCtx(ctx, query, id)
return err
}
func (m *defaultAppUserModel) FindOne(ctx context.Context, id int64) (*AppUser, error) {
query := fmt.Sprintf("select %s from %s where `id` = ? limit 1", appUserRows, m.table)
var resp AppUser
err := m.conn.QueryRowCtx(ctx, &resp, query, id)
switch err {
case nil:
return &resp, nil
case sqlx.ErrNotFound:
return nil, ErrNotFound
default:
return nil, err
}
}
func (m *defaultAppUserModel) FindOneByUserIdAppId(ctx context.Context, userId string, appId string) (*AppUser, error) {
var resp AppUser
query := fmt.Sprintf("select %s from %s where `user_id` = ? and `app_id` = ? limit 1", appUserRows, m.table)
err := m.conn.QueryRowCtx(ctx, &resp, query, userId, appId)
switch err {
case nil:
return &resp, nil
case sqlx.ErrNotFound:
return nil, ErrNotFound
default:
return nil, err
}
}
func (m *defaultAppUserModel) Insert(ctx context.Context, data *AppUser) (sql.Result, error) {
query := fmt.Sprintf("insert into %s (%s) values (?, ?, ?, ?, ?)", m.table, appUserRowsExpectAutoSet)
ret, err := m.conn.ExecCtx(ctx, query, data.Created, data.Updated, data.AppId, data.UserId, data.Status)
return ret, err
}
func (m *defaultAppUserModel) Update(ctx context.Context, newData *AppUser) error {
query := fmt.Sprintf("update %s set %s where `id` = ?", m.table, appUserRowsWithPlaceHolder)
_, err := m.conn.ExecCtx(ctx, query, newData.Created, newData.Updated, newData.AppId, newData.UserId, newData.Status, newData.Id)
return err
}
func (m *defaultAppUserModel) tableName() string {
return m.table
}

@ -0,0 +1,35 @@
//
// Copyright (C) 2024 veypi <i@veypi.com>
// 2024-09-20 16:10:16
// Distributed under terms of the MIT license.
//
package models
import (
"gorm.io/gorm"
"oa/cfg"
"time"
)
type BaseModel struct {
// ID uint `json:"id" gorm:"primaryKey" methods:"get,patch,delete" parse:"path"`
ID string `json:"id" gorm:"primaryKey;type:varchar(32)" methods:"get,put,patch,delete" parse:"path"`
BaseDate
}
type BaseDate struct {
CreatedAt time.Time `json:"created_at" methods:"*list" parse:"query"`
UpdatedAt time.Time `json:"updated_at" methods:"*list" parse:"query"`
DeletedAt gorm.DeletedAt `gorm:"index" json:"-"`
}
func init() {
cfg.ObjList = append(cfg.ObjList, &AppUser{})
cfg.ObjList = append(cfg.ObjList, &Resource{})
cfg.ObjList = append(cfg.ObjList, &Access{})
cfg.ObjList = append(cfg.ObjList, &Role{})
cfg.ObjList = append(cfg.ObjList, &User{})
cfg.ObjList = append(cfg.ObjList, &UserRole{})
cfg.ObjList = append(cfg.ObjList, &App{})
}

@ -1,29 +0,0 @@
package models
import "github.com/zeromicro/go-zero/core/stores/sqlx"
var _ ResourceModel = (*customResourceModel)(nil)
type (
// ResourceModel is an interface to be customized, add more methods here,
// and implement the added methods in customResourceModel.
ResourceModel interface {
resourceModel
withSession(session sqlx.Session) ResourceModel
}
customResourceModel struct {
*defaultResourceModel
}
)
// NewResourceModel returns a model for the database table.
func NewResourceModel(conn sqlx.SqlConn) ResourceModel {
return &customResourceModel{
defaultResourceModel: newResourceModel(conn),
}
}
func (m *customResourceModel) withSession(session sqlx.Session) ResourceModel {
return NewResourceModel(sqlx.NewSqlConnFromSession(session))
}

@ -1,103 +0,0 @@
// Code generated by goctl. DO NOT EDIT.
package models
import (
"context"
"database/sql"
"fmt"
"strings"
"time"
"github.com/zeromicro/go-zero/core/stores/builder"
"github.com/zeromicro/go-zero/core/stores/sqlx"
"github.com/zeromicro/go-zero/core/stringx"
)
var (
resourceFieldNames = builder.RawFieldNames(&Resource{})
resourceRows = strings.Join(resourceFieldNames, ",")
resourceRowsExpectAutoSet = strings.Join(stringx.Remove(resourceFieldNames, "`id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), ",")
resourceRowsWithPlaceHolder = strings.Join(stringx.Remove(resourceFieldNames, "`id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), "=?,") + "=?"
)
type (
resourceModel interface {
Insert(ctx context.Context, data *Resource) (sql.Result, error)
FindOne(ctx context.Context, id int64) (*Resource, error)
FindOneByAppIdName(ctx context.Context, appId string, name string) (*Resource, error)
Update(ctx context.Context, data *Resource) error
Delete(ctx context.Context, id int64) error
}
defaultResourceModel struct {
conn sqlx.SqlConn
table string
}
Resource struct {
Id int64 `db:"id"`
Created time.Time `db:"created"`
Updated time.Time `db:"updated"`
AppId string `db:"app_id"`
Name string `db:"name"`
Des string `db:"des"`
}
)
func newResourceModel(conn sqlx.SqlConn) *defaultResourceModel {
return &defaultResourceModel{
conn: conn,
table: "`resource`",
}
}
func (m *defaultResourceModel) Delete(ctx context.Context, id int64) error {
query := fmt.Sprintf("delete from %s where `id` = ?", m.table)
_, err := m.conn.ExecCtx(ctx, query, id)
return err
}
func (m *defaultResourceModel) FindOne(ctx context.Context, id int64) (*Resource, error) {
query := fmt.Sprintf("select %s from %s where `id` = ? limit 1", resourceRows, m.table)
var resp Resource
err := m.conn.QueryRowCtx(ctx, &resp, query, id)
switch err {
case nil:
return &resp, nil
case sqlx.ErrNotFound:
return nil, ErrNotFound
default:
return nil, err
}
}
func (m *defaultResourceModel) FindOneByAppIdName(ctx context.Context, appId string, name string) (*Resource, error) {
var resp Resource
query := fmt.Sprintf("select %s from %s where `app_id` = ? and `name` = ? limit 1", resourceRows, m.table)
err := m.conn.QueryRowCtx(ctx, &resp, query, appId, name)
switch err {
case nil:
return &resp, nil
case sqlx.ErrNotFound:
return nil, ErrNotFound
default:
return nil, err
}
}
func (m *defaultResourceModel) Insert(ctx context.Context, data *Resource) (sql.Result, error) {
query := fmt.Sprintf("insert into %s (%s) values (?, ?, ?, ?, ?)", m.table, resourceRowsExpectAutoSet)
ret, err := m.conn.ExecCtx(ctx, query, data.Created, data.Updated, data.AppId, data.Name, data.Des)
return ret, err
}
func (m *defaultResourceModel) Update(ctx context.Context, newData *Resource) error {
query := fmt.Sprintf("update %s set %s where `id` = ?", m.table, resourceRowsWithPlaceHolder)
_, err := m.conn.ExecCtx(ctx, query, newData.Created, newData.Updated, newData.AppId, newData.Name, newData.Des, newData.Id)
return err
}
func (m *defaultResourceModel) tableName() string {
return m.table
}

@ -0,0 +1,43 @@
package models
import ()
type RoleDelete struct {
ID string `json:"id" gorm:"primaryKey;type:varchar(32)" parse:"path@role_id"`
}
type RoleGet struct {
ID string `json:"id" gorm:"primaryKey;type:varchar(32)" parse:"path@role_id"`
}
type RoleList struct {
Name *string `json:"name" parse:"json"`
}
type RolePatch struct {
ID string `json:"id" gorm:"primaryKey;type:varchar(32)" parse:"path@role_id"`
Name *string `json:"name" parse:"json"`
Des *string `json:"des" parse:"json"`
AppID *string `json:"app_id" gorm:"index;type:varchar(32)" parse:"json"`
}
type RolePost struct {
Name string `json:"name" parse:"json"`
Des string `json:"des" parse:"json"`
AppID string `json:"app_id" gorm:"index;type:varchar(32)" parse:"json"`
}
type RolePut struct {
ID string `json:"id" gorm:"primaryKey;type:varchar(32)" parse:"path@role_id"`
Name string `json:"name" parse:"json"`
Des string `json:"des" parse:"json"`
AppID string `json:"app_id" gorm:"index;type:varchar(32)" parse:"json"`
}

@ -0,0 +1,10 @@
package models
type Role struct {
BaseModel
Name string `json:"name" methods:"post,put,*patch,*list" parse:"json"`
Des string `json:"des" methods:"post,put,*patch" parse:"json"`
AppID string `json:"app_id" gorm:"index;type:varchar(32)" methods:"post,put,*patch" parse:"json"`
App *App `json:"app" gorm:"foreignKey:ID;references:AppID"`
UserCount uint `json:"user_count"`
}

@ -1,29 +0,0 @@
package models
import "github.com/zeromicro/go-zero/core/stores/sqlx"
var _ RoleModel = (*customRoleModel)(nil)
type (
// RoleModel is an interface to be customized, add more methods here,
// and implement the added methods in customRoleModel.
RoleModel interface {
roleModel
withSession(session sqlx.Session) RoleModel
}
customRoleModel struct {
*defaultRoleModel
}
)
// NewRoleModel returns a model for the database table.
func NewRoleModel(conn sqlx.SqlConn) RoleModel {
return &customRoleModel{
defaultRoleModel: newRoleModel(conn),
}
}
func (m *customRoleModel) withSession(session sqlx.Session) RoleModel {
return NewRoleModel(sqlx.NewSqlConnFromSession(session))
}

@ -1,89 +0,0 @@
// Code generated by goctl. DO NOT EDIT.
package models
import (
"context"
"database/sql"
"fmt"
"strings"
"time"
"github.com/zeromicro/go-zero/core/stores/builder"
"github.com/zeromicro/go-zero/core/stores/sqlx"
"github.com/zeromicro/go-zero/core/stringx"
)
var (
roleFieldNames = builder.RawFieldNames(&Role{})
roleRows = strings.Join(roleFieldNames, ",")
roleRowsExpectAutoSet = strings.Join(stringx.Remove(roleFieldNames, "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), ",")
roleRowsWithPlaceHolder = strings.Join(stringx.Remove(roleFieldNames, "`id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), "=?,") + "=?"
)
type (
roleModel interface {
Insert(ctx context.Context, data *Role) (sql.Result, error)
FindOne(ctx context.Context, id string) (*Role, error)
Update(ctx context.Context, data *Role) error
Delete(ctx context.Context, id string) error
}
defaultRoleModel struct {
conn sqlx.SqlConn
table string
}
Role struct {
Id string `db:"id"`
Created time.Time `db:"created"`
Updated time.Time `db:"updated"`
AppId string `db:"app_id"`
Name string `db:"name"`
Des string `db:"des"`
UserCount int64 `db:"user_count"`
}
)
func newRoleModel(conn sqlx.SqlConn) *defaultRoleModel {
return &defaultRoleModel{
conn: conn,
table: "`role`",
}
}
func (m *defaultRoleModel) Delete(ctx context.Context, id string) error {
query := fmt.Sprintf("delete from %s where `id` = ?", m.table)
_, err := m.conn.ExecCtx(ctx, query, id)
return err
}
func (m *defaultRoleModel) FindOne(ctx context.Context, id string) (*Role, error) {
query := fmt.Sprintf("select %s from %s where `id` = ? limit 1", roleRows, m.table)
var resp Role
err := m.conn.QueryRowCtx(ctx, &resp, query, id)
switch err {
case nil:
return &resp, nil
case sqlx.ErrNotFound:
return nil, ErrNotFound
default:
return nil, err
}
}
func (m *defaultRoleModel) Insert(ctx context.Context, data *Role) (sql.Result, error) {
query := fmt.Sprintf("insert into %s (%s) values (?, ?, ?, ?, ?, ?, ?)", m.table, roleRowsExpectAutoSet)
ret, err := m.conn.ExecCtx(ctx, query, data.Id, data.Created, data.Updated, data.AppId, data.Name, data.Des, data.UserCount)
return ret, err
}
func (m *defaultRoleModel) Update(ctx context.Context, data *Role) error {
query := fmt.Sprintf("update %s set %s where `id` = ?", m.table, roleRowsWithPlaceHolder)
_, err := m.conn.ExecCtx(ctx, query, data.Created, data.Updated, data.AppId, data.Name, data.Des, data.UserCount, data.Id)
return err
}
func (m *defaultRoleModel) tableName() string {
return m.table
}

@ -1,29 +0,0 @@
package models
import "github.com/zeromicro/go-zero/core/stores/sqlx"
var _ TokenModel = (*customTokenModel)(nil)
type (
// TokenModel is an interface to be customized, add more methods here,
// and implement the added methods in customTokenModel.
TokenModel interface {
tokenModel
withSession(session sqlx.Session) TokenModel
}
customTokenModel struct {
*defaultTokenModel
}
)
// NewTokenModel returns a model for the database table.
func NewTokenModel(conn sqlx.SqlConn) TokenModel {
return &customTokenModel{
defaultTokenModel: newTokenModel(conn),
}
}
func (m *customTokenModel) withSession(session sqlx.Session) TokenModel {
return NewTokenModel(sqlx.NewSqlConnFromSession(session))
}

@ -1,90 +0,0 @@
// Code generated by goctl. DO NOT EDIT.
package models
import (
"context"
"database/sql"
"fmt"
"strings"
"time"
"github.com/zeromicro/go-zero/core/stores/builder"
"github.com/zeromicro/go-zero/core/stores/sqlx"
"github.com/zeromicro/go-zero/core/stringx"
)
var (
tokenFieldNames = builder.RawFieldNames(&Token{})
tokenRows = strings.Join(tokenFieldNames, ",")
tokenRowsExpectAutoSet = strings.Join(stringx.Remove(tokenFieldNames, "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), ",")
tokenRowsWithPlaceHolder = strings.Join(stringx.Remove(tokenFieldNames, "`code`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), "=?,") + "=?"
)
type (
tokenModel interface {
Insert(ctx context.Context, data *Token) (sql.Result, error)
FindOne(ctx context.Context, code string) (*Token, error)
Update(ctx context.Context, data *Token) error
Delete(ctx context.Context, code string) error
}
defaultTokenModel struct {
conn sqlx.SqlConn
table string
}
Token struct {
Code string `db:"code"`
Created time.Time `db:"created"`
Updated time.Time `db:"updated"`
Expired time.Time `db:"expired"`
ClientId string `db:"client_id"`
AppId string `db:"app_id"`
UserId string `db:"user_id"`
Meta string `db:"meta"`
}
)
func newTokenModel(conn sqlx.SqlConn) *defaultTokenModel {
return &defaultTokenModel{
conn: conn,
table: "`token`",
}
}
func (m *defaultTokenModel) Delete(ctx context.Context, code string) error {
query := fmt.Sprintf("delete from %s where `code` = ?", m.table)
_, err := m.conn.ExecCtx(ctx, query, code)
return err
}
func (m *defaultTokenModel) FindOne(ctx context.Context, code string) (*Token, error) {
query := fmt.Sprintf("select %s from %s where `code` = ? limit 1", tokenRows, m.table)
var resp Token
err := m.conn.QueryRowCtx(ctx, &resp, query, code)
switch err {
case nil:
return &resp, nil
case sqlx.ErrNotFound:
return nil, ErrNotFound
default:
return nil, err
}
}
func (m *defaultTokenModel) Insert(ctx context.Context, data *Token) (sql.Result, error) {
query := fmt.Sprintf("insert into %s (%s) values (?, ?, ?, ?, ?, ?, ?, ?)", m.table, tokenRowsExpectAutoSet)
ret, err := m.conn.ExecCtx(ctx, query, data.Code, data.Created, data.Updated, data.Expired, data.ClientId, data.AppId, data.UserId, data.Meta)
return ret, err
}
func (m *defaultTokenModel) Update(ctx context.Context, data *Token) error {
query := fmt.Sprintf("update %s set %s where `code` = ?", m.table, tokenRowsWithPlaceHolder)
_, err := m.conn.ExecCtx(ctx, query, data.Created, data.Updated, data.Expired, data.ClientId, data.AppId, data.UserId, data.Meta, data.Code)
return err
}
func (m *defaultTokenModel) tableName() string {
return m.table
}

@ -0,0 +1,107 @@
package models
import ()
type UserDelete struct {
ID string `json:"id" gorm:"primaryKey;type:varchar(32)" parse:"path@user_id"`
}
type UserGet struct {
ID string `json:"id" gorm:"primaryKey;type:varchar(32)" parse:"path@user_id"`
}
type UserList struct {
Username *string `json:"username" gorm:"varchar(100);unique;default:not null" parse:"json"`
Nickname *string `json:"nickname" parse:"json"`
Email *string `json:"email" gorm:"varchar(20);unique;default:null" parse:"json"`
Phone *string `json:"phone" gorm:"varchar(50);unique;default:null" parse:"json"`
Status *uint `json:"status" parse:"json"`
}
type UserPatch struct {
ID string `json:"id" gorm:"primaryKey;type:varchar(32)" parse:"path@user_id"`
Username *string `json:"username" gorm:"varchar(100);unique;default:not null" parse:"json"`
Nickname *string `json:"nickname" parse:"json"`
Icon *string `json:"icon" parse:"json"`
Email *string `json:"email" gorm:"varchar(20);unique;default:null" parse:"json"`
Phone *string `json:"phone" gorm:"varchar(50);unique;default:null" parse:"json"`
Status *uint `json:"status" parse:"json"`
}
type UserPost struct {
Username string `json:"username" gorm:"varchar(100);unique;default:not null" parse:"json"`
Nickname string `json:"nickname" parse:"json"`
Icon string `json:"icon" parse:"json"`
Email string `json:"email" gorm:"varchar(20);unique;default:null" parse:"json"`
Phone string `json:"phone" gorm:"varchar(50);unique;default:null" parse:"json"`
Status uint `json:"status" parse:"json"`
}
type UserPut struct {
ID string `json:"id" gorm:"primaryKey;type:varchar(32)" parse:"path@user_id"`
Username string `json:"username" gorm:"varchar(100);unique;default:not null" parse:"json"`
Nickname string `json:"nickname" parse:"json"`
Icon string `json:"icon" parse:"json"`
Email string `json:"email" gorm:"varchar(20);unique;default:null" parse:"json"`
Phone string `json:"phone" gorm:"varchar(50);unique;default:null" parse:"json"`
Status uint `json:"status" parse:"json"`
}
type UserRoleDelete struct {
ID string `json:"id" gorm:"primaryKey;type:varchar(32)" parse:"path@user_role_id"`
UserID string `json:"user_id" parse:"path"`
RoleID string `json:"role_id" parse:"path"`
}
type UserRoleGet struct {
ID string `json:"id" gorm:"primaryKey;type:varchar(32)" parse:"path@user_role_id"`
}
type UserRoleList struct {
Status *string `json:"status" parse:"json"`
}
type UserRolePatch struct {
ID string `json:"id" gorm:"primaryKey;type:varchar(32)" parse:"path@user_role_id"`
UserID *string `json:"user_id" parse:"path"`
Status *string `json:"status" parse:"json"`
}
type UserRolePost struct {
UserID string `json:"user_id" parse:"path"`
RoleID string `json:"role_id" parse:"path"`
Status string `json:"status" parse:"json"`
}
type UserRolePut struct {
ID string `json:"id" gorm:"primaryKey;type:varchar(32)" parse:"path@user_role_id"`
Status string `json:"status" parse:"json"`
}

@ -0,0 +1,25 @@
package models
type User struct {
BaseModel
Username string `json:"username" gorm:"varchar(100);unique;default:not null" methods:"post,put,*patch,*list" parse:"json"`
Nickname string `json:"nickname" methods:"post,put,*patch,*list" parse:"json"`
Icon string `json:"icon" methods:"post,put,*patch" parse:"json"`
Email string `json:"email" gorm:"varchar(20);unique;default:null" methods:"post,put,*patch,*list" parse:"json"`
Phone string `json:"phone" gorm:"varchar(50);unique;default:null" methods:"post,put,*patch,*list" parse:"json"`
Status uint `json:"status" methods:"post,put,*patch,*list" parse:"json"`
RealCode string `json:"-"`
CheckCode string `json:"-"`
}
type UserRole struct {
BaseModel
UserID string `json:"user_id" methods:"post,*patch,delete" parse:"path"`
User *User `json:"user"`
RoleID string `json:"role_id" methods:"post,delete" parse:"path"`
Role *Role `json:"role"`
Status string `json:"status" methods:"post,put,*patch,*list" parse:"json"`
}

@ -1,29 +0,0 @@
package models
import "github.com/zeromicro/go-zero/core/stores/sqlx"
var _ UserModel = (*customUserModel)(nil)
type (
// UserModel is an interface to be customized, add more methods here,
// and implement the added methods in customUserModel.
UserModel interface {
userModel
withSession(session sqlx.Session) UserModel
}
customUserModel struct {
*defaultUserModel
}
)
// NewUserModel returns a model for the database table.
func NewUserModel(conn sqlx.SqlConn) UserModel {
return &customUserModel{
defaultUserModel: newUserModel(conn),
}
}
func (m *customUserModel) withSession(session sqlx.Session) UserModel {
return NewUserModel(sqlx.NewSqlConnFromSession(session))
}

@ -1,140 +0,0 @@
// Code generated by goctl. DO NOT EDIT.
package models
import (
"context"
"database/sql"
"fmt"
"strings"
"time"
"github.com/zeromicro/go-zero/core/stores/builder"
"github.com/zeromicro/go-zero/core/stores/sqlx"
"github.com/zeromicro/go-zero/core/stringx"
)
var (
userFieldNames = builder.RawFieldNames(&User{})
userRows = strings.Join(userFieldNames, ",")
userRowsExpectAutoSet = strings.Join(stringx.Remove(userFieldNames, "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), ",")
userRowsWithPlaceHolder = strings.Join(stringx.Remove(userFieldNames, "`id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), "=?,") + "=?"
)
type (
userModel interface {
Insert(ctx context.Context, data *User) (sql.Result, error)
FindOne(ctx context.Context, id string) (*User, error)
FindOneByEmail(ctx context.Context, email sql.NullString) (*User, error)
FindOneByPhone(ctx context.Context, phone sql.NullString) (*User, error)
FindOneByUsername(ctx context.Context, username string) (*User, error)
Update(ctx context.Context, data *User) error
Delete(ctx context.Context, id string) error
}
defaultUserModel struct {
conn sqlx.SqlConn
table string
}
User struct {
Id string `db:"id"` // User UUID
Created time.Time `db:"created"`
Updated time.Time `db:"updated"`
Username string `db:"username"`
Nickname string `db:"nickname"`
Email sql.NullString `db:"email"`
Phone sql.NullString `db:"phone"`
Icon string `db:"icon"`
RealCode string `db:"_real_code"`
CheckCode string `db:"_check_code"`
Status int64 `db:"status"` // 状态0ok1disabled
Used int64 `db:"used"`
Space int64 `db:"space"`
}
)
func newUserModel(conn sqlx.SqlConn) *defaultUserModel {
return &defaultUserModel{
conn: conn,
table: "`user`",
}
}
func (m *defaultUserModel) Delete(ctx context.Context, id string) error {
query := fmt.Sprintf("delete from %s where `id` = ?", m.table)
_, err := m.conn.ExecCtx(ctx, query, id)
return err
}
func (m *defaultUserModel) FindOne(ctx context.Context, id string) (*User, error) {
query := fmt.Sprintf("select %s from %s where `id` = ? limit 1", userRows, m.table)
var resp User
err := m.conn.QueryRowCtx(ctx, &resp, query, id)
switch err {
case nil:
return &resp, nil
case sqlx.ErrNotFound:
return nil, ErrNotFound
default:
return nil, err
}
}
func (m *defaultUserModel) FindOneByEmail(ctx context.Context, email sql.NullString) (*User, error) {
var resp User
query := fmt.Sprintf("select %s from %s where `email` = ? limit 1", userRows, m.table)
err := m.conn.QueryRowCtx(ctx, &resp, query, email)
switch err {
case nil:
return &resp, nil
case sqlx.ErrNotFound:
return nil, ErrNotFound
default:
return nil, err
}
}
func (m *defaultUserModel) FindOneByPhone(ctx context.Context, phone sql.NullString) (*User, error) {
var resp User
query := fmt.Sprintf("select %s from %s where `phone` = ? limit 1", userRows, m.table)
err := m.conn.QueryRowCtx(ctx, &resp, query, phone)
switch err {
case nil:
return &resp, nil
case sqlx.ErrNotFound:
return nil, ErrNotFound
default:
return nil, err
}
}
func (m *defaultUserModel) FindOneByUsername(ctx context.Context, username string) (*User, error) {
var resp User
query := fmt.Sprintf("select %s from %s where `username` = ? limit 1", userRows, m.table)
err := m.conn.QueryRowCtx(ctx, &resp, query, username)
switch err {
case nil:
return &resp, nil
case sqlx.ErrNotFound:
return nil, ErrNotFound
default:
return nil, err
}
}
func (m *defaultUserModel) Insert(ctx context.Context, data *User) (sql.Result, error) {
query := fmt.Sprintf("insert into %s (%s) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", m.table, userRowsExpectAutoSet)
ret, err := m.conn.ExecCtx(ctx, query, data.Id, data.Created, data.Updated, data.Username, data.Nickname, data.Email, data.Phone, data.Icon, data.RealCode, data.CheckCode, data.Status, data.Used, data.Space)
return ret, err
}
func (m *defaultUserModel) Update(ctx context.Context, newData *User) error {
query := fmt.Sprintf("update %s set %s where `id` = ?", m.table, userRowsWithPlaceHolder)
_, err := m.conn.ExecCtx(ctx, query, newData.Created, newData.Updated, newData.Username, newData.Nickname, newData.Email, newData.Phone, newData.Icon, newData.RealCode, newData.CheckCode, newData.Status, newData.Used, newData.Space, newData.Id)
return err
}
func (m *defaultUserModel) tableName() string {
return m.table
}

@ -1,29 +0,0 @@
package models
import "github.com/zeromicro/go-zero/core/stores/sqlx"
var _ UserRoleModel = (*customUserRoleModel)(nil)
type (
// UserRoleModel is an interface to be customized, add more methods here,
// and implement the added methods in customUserRoleModel.
UserRoleModel interface {
userRoleModel
withSession(session sqlx.Session) UserRoleModel
}
customUserRoleModel struct {
*defaultUserRoleModel
}
)
// NewUserRoleModel returns a model for the database table.
func NewUserRoleModel(conn sqlx.SqlConn) UserRoleModel {
return &customUserRoleModel{
defaultUserRoleModel: newUserRoleModel(conn),
}
}
func (m *customUserRoleModel) withSession(session sqlx.Session) UserRoleModel {
return NewUserRoleModel(sqlx.NewSqlConnFromSession(session))
}

@ -1,103 +0,0 @@
// Code generated by goctl. DO NOT EDIT.
package models
import (
"context"
"database/sql"
"fmt"
"strings"
"time"
"github.com/zeromicro/go-zero/core/stores/builder"
"github.com/zeromicro/go-zero/core/stores/sqlx"
"github.com/zeromicro/go-zero/core/stringx"
)
var (
userRoleFieldNames = builder.RawFieldNames(&UserRole{})
userRoleRows = strings.Join(userRoleFieldNames, ",")
userRoleRowsExpectAutoSet = strings.Join(stringx.Remove(userRoleFieldNames, "`id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), ",")
userRoleRowsWithPlaceHolder = strings.Join(stringx.Remove(userRoleFieldNames, "`id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), "=?,") + "=?"
)
type (
userRoleModel interface {
Insert(ctx context.Context, data *UserRole) (sql.Result, error)
FindOne(ctx context.Context, id int64) (*UserRole, error)
FindOneByUserIdRoleId(ctx context.Context, userId string, roleId string) (*UserRole, error)
Update(ctx context.Context, data *UserRole) error
Delete(ctx context.Context, id int64) error
}
defaultUserRoleModel struct {
conn sqlx.SqlConn
table string
}
UserRole struct {
Id int64 `db:"id"`
Created time.Time `db:"created"`
Updated time.Time `db:"updated"`
UserId string `db:"user_id"`
RoleId string `db:"role_id"`
Status string `db:"status"`
}
)
func newUserRoleModel(conn sqlx.SqlConn) *defaultUserRoleModel {
return &defaultUserRoleModel{
conn: conn,
table: "`user_role`",
}
}
func (m *defaultUserRoleModel) Delete(ctx context.Context, id int64) error {
query := fmt.Sprintf("delete from %s where `id` = ?", m.table)
_, err := m.conn.ExecCtx(ctx, query, id)
return err
}
func (m *defaultUserRoleModel) FindOne(ctx context.Context, id int64) (*UserRole, error) {
query := fmt.Sprintf("select %s from %s where `id` = ? limit 1", userRoleRows, m.table)
var resp UserRole
err := m.conn.QueryRowCtx(ctx, &resp, query, id)
switch err {
case nil:
return &resp, nil
case sqlx.ErrNotFound:
return nil, ErrNotFound
default:
return nil, err
}
}
func (m *defaultUserRoleModel) FindOneByUserIdRoleId(ctx context.Context, userId string, roleId string) (*UserRole, error) {
var resp UserRole
query := fmt.Sprintf("select %s from %s where `user_id` = ? and `role_id` = ? limit 1", userRoleRows, m.table)
err := m.conn.QueryRowCtx(ctx, &resp, query, userId, roleId)
switch err {
case nil:
return &resp, nil
case sqlx.ErrNotFound:
return nil, ErrNotFound
default:
return nil, err
}
}
func (m *defaultUserRoleModel) Insert(ctx context.Context, data *UserRole) (sql.Result, error) {
query := fmt.Sprintf("insert into %s (%s) values (?, ?, ?, ?, ?)", m.table, userRoleRowsExpectAutoSet)
ret, err := m.conn.ExecCtx(ctx, query, data.Created, data.Updated, data.UserId, data.RoleId, data.Status)
return ret, err
}
func (m *defaultUserRoleModel) Update(ctx context.Context, newData *UserRole) error {
query := fmt.Sprintf("update %s set %s where `id` = ?", m.table, userRoleRowsWithPlaceHolder)
_, err := m.conn.ExecCtx(ctx, query, newData.Created, newData.Updated, newData.UserId, newData.RoleId, newData.Status, newData.Id)
return err
}
func (m *defaultUserRoleModel) tableName() string {
return m.table
}

@ -1,5 +0,0 @@
package models
import "github.com/zeromicro/go-zero/core/stores/sqlx"
var ErrNotFound = sqlx.ErrNotFound

@ -1,11 +0,0 @@
syntax = "v1"
info (
title: "OA"
desc: "OA API"
author: "veypi"
email: "i@veypi.com"
)
import "user.api"
import "app.api"

@ -1,37 +0,0 @@
import "base.api"
type (
// 定义登录接口的请求体
AppReq {
appname string `form:"username"`
Password string `json:"password"`
Pa string `path:"pa"`
}
// 定义登录接口的响应体
AppResp {
Id int64 `json:"id"`
Name string `json:"name"`
Token string `json:"token"`
ExpireAt string `json:"expireAt"`
}
)
@server (
// 代表当前 service 代码块下的路由生成代码时都会被放到 app 目录下
group: app
// 定义路由前缀为 "/v1"
prefix: /api/app
)
// 定义 HTTP 服务
// 微服务名称为 main生成的代码目录和配置文件将和 user 值相关
service main {
// 定义 http.HandleFunc 转换的 go 文件名称及方法
@handler Login
// 定义接口
// 请求方法为 post
// 路由为 /app/login
// 请求体为 LoginReq
// 响应体为 LoginResp响应体必须有 returns 关键字修饰
get /login/:pa (AppReq) returns (AppResp)
}

@ -1,4 +0,0 @@
type auth {
Authorization string `header:"authorization"`
}

@ -1,59 +0,0 @@
import "base.api"
type (
LoginReq {
id string `path:"id"`
pwd string `form:"pwd"`
client string `form:"client"`
typ string `form:"typ,optional"`
}
RegReq {
username string `json:"username"`
pwd string `json:"pwd"`
}
getReq {
Id int64 `path:"id"`
}
listReq {
Username string `query:"username"`
}
userResp {
Id string `json:"id"`
Created uint `json:"created"`
Updated uint `json:"updated"`
Username string `json:"username"`
Nickname string `json:"nickname"`
Email string `json:"email"`
Phone string `json:"phone"`
Icon string `json:"icon"`
Status int64 `json:"status"` // 状态0ok1disabled
Used int64 `json:"used"`
Space int64 `json:"space"`
}
)
@server (
group: user
prefix: /api/user
)
service main {
@handler Login
head /:id (LoginReq)
@handler Reg
post / (RegReq)
}
@server (
group: user
middleware: Auth
prefix: /api/user
)
service main {
@handler get
get /:id (getReq) returns (userResp)
@handler list
get / (listReq) returns ([]userResp)
}

@ -1,150 +0,0 @@
CREATE TABLE IF NOT EXISTS `user`
(
`id` varchar(32) NOT NULL DEFAULT '' COMMENT 'User UUID',
`created` datetime DEFAULT CURRENT_TIMESTAMP NOT NULL,
`updated` datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP NOT NULL,
`username` varchar(255) NOT NULL UNIQUE,
`nickname` varchar(255) NOT NULL,
`email` varchar(255) UNIQUE,
`phone` varchar(255) UNIQUE,
`icon` varchar(255) NOT NULL DEFAULT "",
`_real_code` varchar(32) NOT NULL,
`_check_code` varchar(64) NOT NULL,
`status` int NOT NULL COMMENT '状态0ok1disabled' DEFAULT 0,
`used` int NOT NULL DEFAULT 0,
`space` int NOT NULL DEFAULT 300,
PRIMARY KEY (`id`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE IF NOT EXISTS `app`
(
`id` varchar(32) NOT NULL,
`created` datetime DEFAULT CURRENT_TIMESTAMP NOT NULL,
`updated` datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP NOT NULL,
`_key` varchar(32) NOT NULL,
`name` varchar(255) NOT NULL,
`icon` varchar(255) NOT NULL DEFAULT "",
`des` TEXT,
`user_count` int NOT NULL DEFAULT 0,
`hide` tinyint(1) NOT NULL DEFAULT 0,
`join_method` int NOT NULL DEFAULT 0,
`role_id` varchar(32) NOT NULL,
`host` varchar(255) NOT NULL DEFAULT '',
`redirect` varchar(255) NOT NULL DEFAULT '',
`status` int NOT NULL COMMENT '状态0ok1disabled' DEFAULT 0,
PRIMARY KEY (`id`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE IF NOT EXISTS `app_user`
(
id int AUTO_INCREMENT,
`created` datetime DEFAULT CURRENT_TIMESTAMP NOT NULL,
`updated` datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP NOT NULL,
`app_id` varchar(32) NOT NULL,
`user_id` varchar(32) NOT NULL,
`status` int NOT NULL DEFAULT 0 COMMENT '0: ok,1:disabled,2:applying,3:deny',
PRIMARY KEY (`id`),
unique index (`user_id`,`app_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='app_to_user';
CREATE TABLE IF NOT EXISTS `role`
(
`id` varchar(32) NOT NULL,
`created` datetime DEFAULT CURRENT_TIMESTAMP NOT NULL,
`updated` datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP NOT NULL,
`app_id` varchar(32) NOT NULL,
`name` varchar(255) NOT NULL,
`des` varchar(255) NOT NULL DEFAULT '',
`user_count` int NOT NULL DEFAULT 0,
PRIMARY KEY (`id`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE IF NOT EXISTS `user_role`
(
id int AUTO_INCREMENT,
`created` datetime DEFAULT CURRENT_TIMESTAMP NOT NULL,
`updated` datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP NOT NULL,
`user_id` varchar(32) NOT NULL,
`role_id` varchar(32) NOT NULL,
`status` varchar(32) NOT NULL DEFAULT 0,
PRIMARY KEY (`id`),
UNIQUE INDEX (`user_id`,`role_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE IF NOT EXISTS `resource`
(
id int AUTO_INCREMENT,
`created` datetime DEFAULT CURRENT_TIMESTAMP NOT NULL,
`updated` datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP NOT NULL,
`app_id` varchar(32) NOT NULL,
`name` varchar(32) NOT NULL,
`des` varchar(255) NOT NULL DEFAULT '',
PRIMARY KEY (`id`),
UNIQUE INDEX (`app_id`,`name`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE IF NOT EXISTS `access`
(
`id` int NOT NULL AUTO_INCREMENT,
`created` datetime DEFAULT CURRENT_TIMESTAMP NOT NULL,
`updated` datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP NOT NULL,
`app_id` varchar(32) NOT NULL,
`access_id` int NOT NULL DEFAULT 0,
`name` varchar(32) NOT NULL,
`role_id` varchar(32) NULL DEFAULT NULL,
`user_id` varchar(32) NULL DEFAULT NULL,
`rid` varchar(32) DEFAULT NULL COMMENT '资源子id',
`level` int NOT NULL DEFAULT 0,
-- PRIMARY KEY (`app_id`,`name`, `role_id`, `user_id`) USING BTREE,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE IF NOT EXISTS `token`
(
`code` varchar(32) NOT NULL,
`created` datetime DEFAULT CURRENT_TIMESTAMP NOT NULL,
`updated` datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP NOT NULL,
`expired` datetime NOT NULL,
`client_id` varchar(32) NOT NULL,
`app_id` varchar(32) NOT NULL,
`user_id` varchar(32) NOT NULL,
`meta` json NOT NULL,
PRIMARY KEY (`code`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
INSERT INTO `app` (`id`, `name`, `_key`, `role_id` )
VALUES ('FR9P5t8debxc11aFF', 'oa', 'AMpjwQHwVjGsb1WC4WG6', '1lytMwQL4uiNd0vsc');
INSERT INTO `resource` (`app_id`, `name`)
VALUES ('FR9P5t8debxc11aFF', 'app'),
('FR9P5t8debxc11aFF', 'user');
INSERT INTO `role` (`id`, `app_id`, `name`)
VALUES ('1lytMwQL4uiNd0vsc', 'FR9P5t8debxc11aFF', 'admin');
INSERT INTO `access` (`app_id`, `name`, `role_id`, `user_id`,`level`)
VALUES ('FR9P5t8debxc11aFF', 'app', '1lytMwQL4uiNd0vsc', NULL,5),
('FR9P5t8debxc11aFF', 'user', '1lytMwQL4uiNd0vsc', NULL,5);
Loading…
Cancel
Save