1 Star 0 Fork 0

go-libs/db-xorm

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
provider.go 2.63 KB
一键复制 编辑 原始数据 按行查看 历史
非一般 提交于 2025-04-25 15:06 +08:00 . generate default target
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// Author: wsfuyibing <682805@qq.com>
// Date: 2024-08-02
package gen_service
import (
"context"
"gitee.com/go-libs/console"
"gitee.com/go-libs/db-xorm/db/commands"
"gitee.com/go-libs/db-xorm/db/commands/base"
)
const (
Name = base.CommandNameService
Description = "Generate service files"
DefaultTargetPath = "app/http/services"
)
// Provider
// is a component used to generate service files.
type Provider struct {
common *commands.Common
command *console.Command
}
// Before
// is a before runner hook handler for command.
func (o *Provider) Before(_ context.Context, _ *console.Container, command *console.Command) (err error) {
// log.Config().SetLevel("error")
// Read and validate
// options value.
//
// --base-dir
// --dsn
for _, fn := range []func() error{
func() error { return o.common.ReadBaseDir(command, base.OptBaseDir, base.OptBaseDirDefault) },
func() error { return o.common.BuildModule(command) },
func() error { return o.common.ReadDsn(command, base.OptDsn) },
func() error { return o.common.ReadExport(command, base.OptExport) },
func() error { return o.common.ReadModelPath(command, base.OptModelPath, base.OptModelPathDefault) },
func() error { return o.common.ReadOverride(command, base.OptOverride) },
func() error { return o.common.ReadPrefix(command, base.OptPrefix) },
func() error { return o.common.ReadTargetPath(command, base.OptTargetPath, DefaultTargetPath) },
func() error { return o.common.RegisterDatabase() },
} {
if err = fn(); err != nil {
break
}
}
return
}
// Run
// is a runner hook handler for command.
func (o *Provider) Run(ctx context.Context, container *console.Container, command *console.Command) (err error) {
var tables []*base.Table
// Return error
// if tables list failed.
if tables, err = o.common.ListTable(ctx, command, false); err != nil {
return
}
// Iterate
// tables and generate it.
for _, table := range tables {
if err = (&Generator{
Common: o.common,
Command: command,
Container: container,
Table: table,
}).Run(ctx); err != nil {
break
}
}
return
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/go-libs/db-xorm.git
git@gitee.com:go-libs/db-xorm.git
go-libs
db-xorm
db-xorm
v1.2.8

搜索帮助