feat: 更新模块路径为 v2,修正文档和代码中的相关引用

This commit is contained in:
Rogee
2025-09-10 14:54:16 +08:00
parent 8bcc2cbdad
commit 0d05d70fb1
18 changed files with 328 additions and 308 deletions

View File

@@ -3,7 +3,7 @@
## Install ## Install
``` ```
go install go.ipao.vip/atomctl@latest go install go.ipao.vip/atomctl/v2@latest
``` ```
## 命令列表 ## 命令列表
@@ -11,45 +11,49 @@ go install go.ipao.vip/atomctl@latest
### 生成命令 ### 生成命令
#### gen model (别名m) #### gen model (别名m)
- 描述生成jet模型
- 描述:生成 jet 模型
- 功能: - 功能:
- 从PostgreSQL数据库生成模型 - PostgreSQL 数据库生成模型
- 使用database/transform.yaml配置文件进行类型转换 - 使用 database/transform.yaml 配置文件进行类型转换
- 支持忽略特定表和枚举 - 支持忽略特定表和枚举
- 生成JSON标签 - 生成 JSON 标签
- 支持自定义字段类型映射 - 支持自定义字段类型映射
- 自动生成数据库schema文件 - 自动生成数据库 schema 文件
#### gen provider (别名p) #### gen provider (别名p)
- 描述生成provider
- 描述:生成 provider
- 参数: - 参数:
- path可选指定生成路径默认当前目录 - path可选指定生成路径默认当前目录
- 功能: - 功能:
- 解析指定目录下的.go文件 - 解析指定目录下的.go 文件
- 查找带有@provider注释的结构体 - 查找带有@provider 注释的结构体
- 支持 `@provider(grpc|event|job):[except|only] [returnType] [group]` 注释 - 支持 `@provider(grpc|event|job):[except|only] [returnType] [group]` 注释
- 自动生成provider文件 - 自动生成 provider 文件
- 支持分组生成 - 支持分组生成
#### gen route #### gen route
- 描述:生成路由 - 描述:生成路由
- 参数: - 参数:
- path可选指定生成路径默认当前目录 - path可选指定生成路径默认当前目录
- 功能: - 功能:
- 解析app/http目录下的controller文件 - 解析 app/http 目录下的 controller 文件
- 自动生成路由定义 - 自动生成路由定义
- 支持分组生成路由 - 支持分组生成路由
- 生成完成后自动执行gen provider命令 - 生成完成后自动执行 gen provider 命令
### 数据库命令 ### 数据库命令
#### migrate (别名m) #### migrate (别名m)
- 描述:数据库迁移 - 描述:数据库迁移
- 参数: - 参数:
- action必选迁移操作up|up-by-one|up-to|create|down|down-to|fix|redo|reset|status|version - action必选迁移操作up|up-by-one|up-to|create|down|down-to|fix|redo|reset|status|version
- args可选操作参数 - args可选操作参数
- 选项: - 选项:
- -c/--config指定数据库配置文件默认config.toml - -c/--config指定数据库配置文件默认 config.toml
- 功能: - 功能:
- 执行数据库迁移 - 执行数据库迁移
- 支持创建迁移文件 - 支持创建迁移文件
@@ -59,9 +63,10 @@ go install go.ipao.vip/atomctl@latest
### 新建命令 ### 新建命令
#### new project (别名p) #### new project (别名p)
- 描述:创建新项目 - 描述:创建新项目
- 参数: - 参数:
- moduleName必选项目模块名需符合Go包名规范 - moduleName必选项目模块名需符合 Go 包名规范)
- 选项: - 选项:
- --force强制覆盖已存在项目 - --force强制覆盖已存在项目
- 功能: - 功能:
@@ -71,11 +76,12 @@ go install go.ipao.vip/atomctl@latest
- 生成完成后提示后续步骤 - 生成完成后提示后续步骤
#### new provider #### new provider
- 描述创建新的provider
- 描述:创建新的 provider
- 参数: - 参数:
- providerName必选provider名称 - providerName必选provider 名称
- 功能: - 功能:
- 在providers目录下创建新的provider - providers 目录下创建新的 provider
- 自动生成provider模板文件 - 自动生成 provider 模板文件
- 支持模板渲染 - 支持模板渲染
- 自动处理命名转换(如驼峰命名) - 自动处理命名转换(如驼峰命名)

View File

@@ -10,8 +10,8 @@ import (
_ "github.com/lib/pq" _ "github.com/lib/pq"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"go.ipao.vip/atomctl/pkg/utils" "go.ipao.vip/atomctl/v2/pkg/utils"
"go.ipao.vip/atomctl/pkg/utils/generator" "go.ipao.vip/atomctl/v2/pkg/utils/generator"
) )
func CommandGenEnum(root *cobra.Command) { func CommandGenEnum(root *cobra.Command) {

View File

@@ -6,7 +6,7 @@ import (
"regexp" "regexp"
"strings" "strings"
astModel "go.ipao.vip/atomctl/pkg/ast/model" astModel "go.ipao.vip/atomctl/v2/pkg/ast/model"
"github.com/go-jet/jet/v2/generator/metadata" "github.com/go-jet/jet/v2/generator/metadata"
"github.com/go-jet/jet/v2/generator/postgres" "github.com/go-jet/jet/v2/generator/postgres"
@@ -19,9 +19,9 @@ import (
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"github.com/spf13/viper" "github.com/spf13/viper"
"go.ipao.vip/atomctl/pkg/ast/model" "go.ipao.vip/atomctl/v2/pkg/ast/model"
pgDatabase "go.ipao.vip/atomctl/pkg/postgres" pgDatabase "go.ipao.vip/atomctl/v2/pkg/postgres"
"go.ipao.vip/atomctl/pkg/utils/gomod" "go.ipao.vip/atomctl/v2/pkg/utils/gomod"
) )
func CommandGenModel(root *cobra.Command) { func CommandGenModel(root *cobra.Command) {

View File

@@ -6,11 +6,11 @@ import (
"path/filepath" "path/filepath"
"strings" "strings"
"go.ipao.vip/atomctl/pkg/ast/provider"
"go.ipao.vip/atomctl/pkg/utils/gomod"
"github.com/samber/lo" "github.com/samber/lo"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"go.ipao.vip/atomctl/v2/pkg/ast/provider"
"go.ipao.vip/atomctl/v2/pkg/utils/gomod"
) )
func CommandGenProvider(root *cobra.Command) { func CommandGenProvider(root *cobra.Command) {

View File

@@ -10,8 +10,8 @@ import (
"github.com/samber/lo" "github.com/samber/lo"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"go.ipao.vip/atomctl/pkg/ast/route" "go.ipao.vip/atomctl/v2/pkg/ast/route"
"go.ipao.vip/atomctl/pkg/utils/gomod" "go.ipao.vip/atomctl/v2/pkg/utils/gomod"
) )
func CommandGenRoute(root *cobra.Command) { func CommandGenRoute(root *cobra.Command) {
@@ -27,7 +27,7 @@ func CommandGenRoute(root *cobra.Command) {
root.AddCommand(cmd) root.AddCommand(cmd)
} }
// https://go.ipao.vip/atomctl/pkg/swag?tab=readme-ov-file#api-operation // https://go.ipao.vip/atomctl/v2/pkg/swag?tab=readme-ov-file#api-operation
func commandGenRouteE(cmd *cobra.Command, args []string) error { func commandGenRouteE(cmd *cobra.Command, args []string) error {
var err error var err error
var path string var path string

View File

@@ -3,12 +3,12 @@ package cmd
import ( import (
"context" "context"
"go.ipao.vip/atomctl/pkg/postgres"
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/pressly/goose/v3" "github.com/pressly/goose/v3"
"github.com/samber/lo" "github.com/samber/lo"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"go.ipao.vip/atomctl/v2/pkg/postgres"
) )
// migrate // migrate

View File

@@ -8,10 +8,10 @@ import (
"strings" "strings"
"text/template" "text/template"
"go.ipao.vip/atomctl/pkg/utils/gomod"
"go.ipao.vip/atomctl/templates"
"github.com/samber/lo" "github.com/samber/lo"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"go.ipao.vip/atomctl/v2/pkg/utils/gomod"
"go.ipao.vip/atomctl/v2/templates"
) )
// CommandNewProvider 注册 new_provider 命令 // CommandNewProvider 注册 new_provider 命令
@@ -79,12 +79,18 @@ func commandNewEventE(cmd *cobra.Command, args []string) error {
var destPath string var destPath string
if relPath == "publisher.go.tpl" { if relPath == "publisher.go.tpl" {
if only == "subscriber" { return nil } if only == "subscriber" {
return nil
}
destPath = filepath.Join(publisherPath, snakeName+".go") destPath = filepath.Join(publisherPath, snakeName+".go")
} else if relPath == "subscriber.go.tpl" { } else if relPath == "subscriber.go.tpl" {
if only == "publisher" { return nil } if only == "publisher" {
return nil
}
destPath = filepath.Join(subscriberPath, snakeName+".go") destPath = filepath.Join(subscriberPath, snakeName+".go")
} else { return nil } } else {
return nil
}
tmpl, err := template.ParseFS(templates.Events, path) tmpl, err := template.ParseFS(templates.Events, path)
if err != nil { if err != nil {
@@ -117,17 +123,25 @@ func commandNewEventE(cmd *cobra.Command, args []string) error {
} else { } else {
// ensure file exists with basic header // ensure file exists with basic header
if _, statErr := os.Stat(topicsPath); os.IsNotExist(statErr) { if _, statErr := os.Stat(topicsPath); os.IsNotExist(statErr) {
if err := os.MkdirAll(filepath.Dir(topicsPath), os.ModePerm); err != nil { return err } if err := os.MkdirAll(filepath.Dir(topicsPath), os.ModePerm); err != nil {
return err
}
header := "package events\n\n// topics generated by atomctl\n\n" header := "package events\n\n// topics generated by atomctl\n\n"
if err := os.WriteFile(topicsPath, []byte(header), 0o644); err != nil { return err } if err := os.WriteFile(topicsPath, []byte(header), 0o644); err != nil {
return err
}
} }
// check duplicate // check duplicate
content, _ := os.ReadFile(topicsPath) content, _ := os.ReadFile(topicsPath)
if !strings.Contains(string(content), "Topic"+camelName+" ") && !strings.Contains(string(content), topicLine) { if !strings.Contains(string(content), "Topic"+camelName+" ") && !strings.Contains(string(content), topicLine) {
f, err := os.OpenFile(topicsPath, os.O_APPEND|os.O_WRONLY, 0o644) f, err := os.OpenFile(topicsPath, os.O_APPEND|os.O_WRONLY, 0o644)
if err != nil { return err } if err != nil {
return err
}
defer f.Close() defer f.Close()
if _, err := f.WriteString(topicLine); err != nil { return err } if _, err := f.WriteString(topicLine); err != nil {
return err
}
} }
} }

View File

@@ -7,10 +7,10 @@ import (
"path/filepath" "path/filepath"
"text/template" "text/template"
"go.ipao.vip/atomctl/pkg/utils/gomod"
"go.ipao.vip/atomctl/templates"
"github.com/samber/lo" "github.com/samber/lo"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"go.ipao.vip/atomctl/v2/pkg/utils/gomod"
"go.ipao.vip/atomctl/v2/templates"
) )
// CommandNewProvider 注册 new_provider 命令 // CommandNewProvider 注册 new_provider 命令

View File

@@ -9,11 +9,11 @@ import (
"strings" "strings"
"text/template" "text/template"
"go.ipao.vip/atomctl/pkg/utils/gomod"
"go.ipao.vip/atomctl/templates"
"github.com/samber/lo" "github.com/samber/lo"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"go.ipao.vip/atomctl/v2/pkg/utils/gomod"
"go.ipao.vip/atomctl/v2/templates"
) )
func CommandNewModule(root *cobra.Command) { func CommandNewModule(root *cobra.Command) {

View File

@@ -13,8 +13,8 @@ import (
"github.com/pkg/errors" "github.com/pkg/errors"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"go.ipao.vip/atomctl/pkg/utils/gomod" "go.ipao.vip/atomctl/v2/pkg/utils/gomod"
"go.ipao.vip/atomctl/templates" "go.ipao.vip/atomctl/v2/templates"
) )
// 验证包名是否合法:支持域名、路径分隔符和常见字符 // 验证包名是否合法:支持域名、路径分隔符和常见字符

View File

@@ -9,9 +9,9 @@ import (
"strings" "strings"
"text/template" "text/template"
"go.ipao.vip/atomctl/templates"
"github.com/iancoleman/strcase" "github.com/iancoleman/strcase"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"go.ipao.vip/atomctl/v2/templates"
) )
// CommandNewProvider 注册 new_provider 命令 // CommandNewProvider 注册 new_provider 命令

2
go.mod
View File

@@ -1,4 +1,4 @@
module go.ipao.vip/atomctl module go.ipao.vip/atomctl/v2
go 1.23.2 go 1.23.2

View File

@@ -1,9 +1,9 @@
package main package main
import ( import (
"go.ipao.vip/atomctl/cmd"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"go.ipao.vip/atomctl/v2/cmd"
) )
func main() { func main() {

View File

@@ -10,7 +10,7 @@ import (
"github.com/samber/lo" "github.com/samber/lo"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
"go.ipao.vip/atomctl/pkg/utils/gomod" "go.ipao.vip/atomctl/v2/pkg/utils/gomod"
) )
//go:embed table.go.tpl //go:embed table.go.tpl

View File

@@ -11,7 +11,7 @@ import (
"github.com/samber/lo" "github.com/samber/lo"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
"go.ipao.vip/atomctl/pkg/utils/gomod" "go.ipao.vip/atomctl/v2/pkg/utils/gomod"
) )
func getTypePkgName(typ string) string { func getTypePkgName(typ string) string {

View File

@@ -6,8 +6,8 @@ import (
"os" "os"
"strings" "strings"
"go.ipao.vip/atomctl/pkg/utils/gomod"
"github.com/samber/lo" "github.com/samber/lo"
"go.ipao.vip/atomctl/v2/pkg/utils/gomod"
"golang.org/x/tools/imports" "golang.org/x/tools/imports"
) )

View File

@@ -8,10 +8,10 @@ import (
"path/filepath" "path/filepath"
"text/template" "text/template"
"go.ipao.vip/atomctl/pkg/utils/gomod"
"github.com/Masterminds/sprig/v3" "github.com/Masterminds/sprig/v3"
"github.com/iancoleman/strcase" "github.com/iancoleman/strcase"
"github.com/samber/lo" "github.com/samber/lo"
"go.ipao.vip/atomctl/v2/pkg/utils/gomod"
) )
//go:embed router.go.tpl //go:embed router.go.tpl

View File

@@ -7,10 +7,10 @@ import (
"go/token" "go/token"
"strings" "strings"
"go.ipao.vip/atomctl/pkg/utils/gomod"
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/samber/lo" "github.com/samber/lo"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
"go.ipao.vip/atomctl/v2/pkg/utils/gomod"
) )
type RouteDefinition struct { type RouteDefinition struct {