diff --git a/.gitignore b/.gitignore index c6cf6d0d..7183c552 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ .DS_Store +.mirc .idea __debug_bin !*.example diff --git a/Makefile b/Makefile index 5bdaf0d5..1b103821 100644 --- a/Makefile +++ b/Makefile @@ -79,7 +79,7 @@ windows-x64: @CGO_ENABLED=$(CGO_ENABLED) GOOS=windows GOARCH=amd64 go build -pgo=auto -trimpath -tags '$(TAGS)' -ldflags '$(LDFLAGS)' -o $(RELEASE_WINDOWS_AMD64)/$(TARGET_BIN).exe .PHONY: generate -generate: gen-mir gen-rpc +generate: gen-mir gen-rpc gen-enum .PHONY: gen-mir gen-mir: @@ -92,6 +92,11 @@ gen-rpc: @buf generate proto @go fmt ./auto/rpc/... +.PHONY: gen-enum +gen-enum: + @go generate ./internal/model/enum/... + go fmt ./internal/model/enum/... + .PHONY: proto-mod proto-mod: @cd proto/ && buf mod update diff --git a/auto/api/m/v1/user.go b/auto/api/m/v1/user.go index a7f3c208..7b6842fe 100644 --- a/auto/api/m/v1/user.go +++ b/auto/api/m/v1/user.go @@ -1,6 +1,6 @@ // Code generated by go-mir. DO NOT EDIT. // versions: -// - mir 5.0.0 +// - mir 5.0.1 package v1 diff --git a/auto/api/r/v1/user.go b/auto/api/r/v1/user.go index 0025c283..5fc6f743 100644 --- a/auto/api/r/v1/user.go +++ b/auto/api/r/v1/user.go @@ -1,6 +1,6 @@ // Code generated by go-mir. DO NOT EDIT. // versions: -// - mir 5.0.0 +// - mir 5.0.1 package v1 diff --git a/auto/api/s/v1/user.go b/auto/api/s/v1/user.go index 6f22345d..053acf88 100644 --- a/auto/api/s/v1/user.go +++ b/auto/api/s/v1/user.go @@ -1,6 +1,6 @@ // Code generated by go-mir. DO NOT EDIT. // versions: -// - mir 5.0.0 +// - mir 5.0.1 package v1 diff --git a/auto/api/v1/admin.go b/auto/api/v1/admin.go index 733d19f6..3b0e9606 100644 --- a/auto/api/v1/admin.go +++ b/auto/api/v1/admin.go @@ -1,6 +1,6 @@ // Code generated by go-mir. DO NOT EDIT. // versions: -// - mir 5.0.0 +// - mir 5.0.1 package v1 diff --git a/auto/api/v1/alipay_priv.go b/auto/api/v1/alipay_priv.go index 43347cbb..3330907f 100644 --- a/auto/api/v1/alipay_priv.go +++ b/auto/api/v1/alipay_priv.go @@ -1,6 +1,6 @@ // Code generated by go-mir. DO NOT EDIT. // versions: -// - mir 5.0.0 +// - mir 5.0.1 package v1 diff --git a/auto/api/v1/alipay_pub.go b/auto/api/v1/alipay_pub.go index 56d23040..a6fdeef9 100644 --- a/auto/api/v1/alipay_pub.go +++ b/auto/api/v1/alipay_pub.go @@ -1,6 +1,6 @@ // Code generated by go-mir. DO NOT EDIT. // versions: -// - mir 5.0.0 +// - mir 5.0.1 package v1 diff --git a/auto/api/v1/core.go b/auto/api/v1/core.go index f933fb3b..2df5e66b 100644 --- a/auto/api/v1/core.go +++ b/auto/api/v1/core.go @@ -1,6 +1,6 @@ // Code generated by go-mir. DO NOT EDIT. // versions: -// - mir 5.0.0 +// - mir 5.0.1 package v1 diff --git a/auto/api/v1/followship.go b/auto/api/v1/followship.go index 208b9d90..b8f9bc09 100644 --- a/auto/api/v1/followship.go +++ b/auto/api/v1/followship.go @@ -1,6 +1,6 @@ // Code generated by go-mir. DO NOT EDIT. // versions: -// - mir 5.0.0 +// - mir 5.0.1 package v1 diff --git a/auto/api/v1/friendship.go b/auto/api/v1/friendship.go index b288249c..12e96946 100644 --- a/auto/api/v1/friendship.go +++ b/auto/api/v1/friendship.go @@ -1,6 +1,6 @@ // Code generated by go-mir. DO NOT EDIT. // versions: -// - mir 5.0.0 +// - mir 5.0.1 package v1 diff --git a/auto/api/v1/loose.go b/auto/api/v1/loose.go index 3794051b..4a77b98d 100644 --- a/auto/api/v1/loose.go +++ b/auto/api/v1/loose.go @@ -1,6 +1,6 @@ // Code generated by go-mir. DO NOT EDIT. // versions: -// - mir 5.0.0 +// - mir 5.0.1 package v1 diff --git a/auto/api/v1/priv.go b/auto/api/v1/priv.go index 8ebfc91f..f6ab299d 100644 --- a/auto/api/v1/priv.go +++ b/auto/api/v1/priv.go @@ -1,6 +1,6 @@ // Code generated by go-mir. DO NOT EDIT. // versions: -// - mir 5.0.0 +// - mir 5.0.1 package v1 diff --git a/auto/api/v1/pub.go b/auto/api/v1/pub.go index 2d9274d2..a9864d98 100644 --- a/auto/api/v1/pub.go +++ b/auto/api/v1/pub.go @@ -1,6 +1,6 @@ // Code generated by go-mir. DO NOT EDIT. // versions: -// - mir 5.0.0 +// - mir 5.0.1 package v1 diff --git a/auto/api/v1/relax.go b/auto/api/v1/relax.go index e1a3f0cc..45bf50e2 100644 --- a/auto/api/v1/relax.go +++ b/auto/api/v1/relax.go @@ -1,6 +1,6 @@ // Code generated by go-mir. DO NOT EDIT. // versions: -// - mir 5.0.0 +// - mir 5.0.1 package v1 diff --git a/auto/api/v1/site.go b/auto/api/v1/site.go index 918ba2ae..d8d412d9 100644 --- a/auto/api/v1/site.go +++ b/auto/api/v1/site.go @@ -1,6 +1,6 @@ // Code generated by go-mir. DO NOT EDIT. // versions: -// - mir 5.0.0 +// - mir 5.0.1 package v1 diff --git a/auto/api/v1/trends.go b/auto/api/v1/trends.go index b7f26b58..f91ea61b 100644 --- a/auto/api/v1/trends.go +++ b/auto/api/v1/trends.go @@ -1,6 +1,6 @@ // Code generated by go-mir. DO NOT EDIT. // versions: -// - mir 5.0.0 +// - mir 5.0.1 package v1 diff --git a/auto/api/x/v1/user.go b/auto/api/x/v1/user.go index 963fd3a3..83b9d26a 100644 --- a/auto/api/x/v1/user.go +++ b/auto/api/x/v1/user.go @@ -1,6 +1,6 @@ // Code generated by go-mir. DO NOT EDIT. // versions: -// - mir 5.0.0 +// - mir 5.0.1 package v1 diff --git a/go.mod b/go.mod index 75caa7a4..e6e9cd2c 100644 --- a/go.mod +++ b/go.mod @@ -6,7 +6,7 @@ require ( github.com/Masterminds/semver/v3 v3.2.1 github.com/RoaringBitmap/roaring v1.9.4 github.com/afocus/captcha v0.0.0-20191010092841-4bd1f21c8868 - github.com/alimy/mir/v5 v5.0.0 + github.com/alimy/mir/v5 v5.0.1 github.com/alimy/tryst v1.1.0 github.com/aliyun/aliyun-oss-go-sdk v3.0.2+incompatible github.com/allegro/bigcache/v3 v3.1.0 @@ -27,6 +27,7 @@ require ( github.com/grafana/pyroscope-go v1.2.2 github.com/huaweicloud/huaweicloud-sdk-go-obs v3.24.9+incompatible github.com/json-iterator/go v1.1.12 + github.com/livekit/mageutil v0.0.0-20250511045019-0f1ff63f7731 github.com/meilisearch/meilisearch-go v0.27.2 github.com/minio/minio-go/v7 v7.0.84 github.com/onsi/ginkgo/v2 v2.23.4 diff --git a/go.sum b/go.sum index 8aa11745..f0e8016a 100644 --- a/go.sum +++ b/go.sum @@ -9,8 +9,8 @@ github.com/RoaringBitmap/roaring v1.9.4 h1:yhEIoH4YezLYT04s1nHehNO64EKFTop/wBhxv github.com/RoaringBitmap/roaring v1.9.4/go.mod h1:6AXUsoIEzDTFFQCe1RbGA6uFONMhvejWj5rqITANK90= github.com/afocus/captcha v0.0.0-20191010092841-4bd1f21c8868 h1:uFrPOl1VBt/Abfl2z+A/DFc+AwmFLxEHR1+Yq6cXvww= github.com/afocus/captcha v0.0.0-20191010092841-4bd1f21c8868/go.mod h1:srphKZ1i+yGXxl/LpBS7ZIECTjCTPzZzAMtJWoG3sLo= -github.com/alimy/mir/v5 v5.0.0 h1:cclOvvZXErSjWOJIKP/TGm20V43D7aQzOGiBs5cDtNg= -github.com/alimy/mir/v5 v5.0.0/go.mod h1:R76XQiU3K7T4V0aOcd4r5OeO7Gf8yTIVtnLbt1LLf2U= +github.com/alimy/mir/v5 v5.0.1 h1:tPGUo5C0hUNZhGwOFJjqn9wDJAdb3XJmNxI9KwejRl0= +github.com/alimy/mir/v5 v5.0.1/go.mod h1:R76XQiU3K7T4V0aOcd4r5OeO7Gf8yTIVtnLbt1LLf2U= github.com/alimy/tryst v1.1.0 h1:EiGiTLLw9n6bfg1WwnqoZTb1gnDHDHxozjfE/cuVjlI= github.com/alimy/tryst v1.1.0/go.mod h1:t/Ocn3Qd2P8Sg5VIL11s1H7cBCYZcDy+VNwiFHix+lI= github.com/aliyun/aliyun-oss-go-sdk v3.0.2+incompatible h1:8psS8a+wKfiLt1iVDX79F7Y6wUM49Lcha2FMXt4UM8g= @@ -194,6 +194,8 @@ github.com/leodido/go-urn v1.4.0 h1:WT9HwE9SGECu3lg4d/dIA+jxlljEa1/ffXKmRjqdmIQ= github.com/leodido/go-urn v1.4.0/go.mod h1:bvxc+MVxLKB4z00jd1z+Dvzr47oO32F/QSNjSBOlFxI= github.com/lib/pq v1.10.9 h1:YXG7RB+JIjhP29X+OtkiDnYaXQwpS4JEWq7dtCCRUEw= github.com/lib/pq v1.10.9/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o= +github.com/livekit/mageutil v0.0.0-20250511045019-0f1ff63f7731 h1:9x+U2HGLrSw5ATTo469PQPkqzdoU7be46ryiCDO3boc= +github.com/livekit/mageutil v0.0.0-20250511045019-0f1ff63f7731/go.mod h1:Rs3MhFwutWhGwmY1VQsygw28z5bWcnEYmS1OG9OxjOQ= github.com/magiconair/properties v1.8.7 h1:IeQXZAiQcpL9mgcAe1Nu6cX9LLw6ExEHKjN0VQdvPDY= github.com/magiconair/properties v1.8.7/go.mod h1:Dhd985XPs7jluiymwWYZ0G4Z61jb3vdS329zhj2hYo0= github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0= diff --git a/internal/model/enum/builtin_enum.go b/internal/model/enum/builtin_enum.go index b2eeb1b7..149a747f 100644 --- a/internal/model/enum/builtin_enum.go +++ b/internal/model/enum/builtin_enum.go @@ -1,14 +1,14 @@ // Code generated by go-enum DO NOT EDIT. -// Version: -// Revision: -// Build Date: -// Built By: +// Version: v0.7.0 +// Revision: 03ade876e762757c985a1cde66576bd63f75d7cd +// Build Date: 2025-04-20T09:27:58+0000 +// Built By: alimy package enum import ( "database/sql/driver" - "encoding/json" + json "encoding/json" "errors" "fmt" "strconv" diff --git a/magefile.go b/magefile.go new file mode 100644 index 00000000..2720500d --- /dev/null +++ b/magefile.go @@ -0,0 +1,116 @@ +//go:build mage +// +build mage + +package main + +import ( + "fmt" + "go/build" + "os" + "os/exec" + "path/filepath" + + "github.com/alimy/mir/v5/core" + "github.com/alimy/mir/v5/engine" + "github.com/livekit/mageutil" +) + +var Default = Generate + +// regenerate mir and protobuf +func Generate() (err error) { + return anyFun(cleanAuto, Mir, Rpc, Enum, Fmt) +} + +// regenerate mir RESTful API interface +func Mir() error { + fmt.Println("Generating mir") + if err := engine.Generate( + core.UseGin(), + core.Schema("mirc"), + core.SinkPath("auto"), + core.WatchCtxDone(true), + core.RunMode(core.InSerialMode), + ); err != nil { + return err + } + return gofmt("./auto/api/...") +} + +// regenerate RPC API interface +func Rpc() error { + fmt.Println("Generating gRPC source code") + cmd := exec.Command("buf", "generate", "proto") + mageutil.ConnectStd(cmd) + if err := cmd.Run(); err != nil { + return err + } + return gofmt("./auto/rpc/...") +} + +func Enum() error { + fmt.Println("Generating Enum source code") + cmd := exec.Command("go", "generate", "./internal/model/enum/...") + mageutil.ConnectStd(cmd) + if err := cmd.Run(); err != nil { + return err + } + return gofmt("./internal/model/enum/...") +} + +// run tests +func Test() error { + fmt.Println("Testing start") + cmd := exec.Command("go", "test", "-race", "./...") + connectStd(cmd) + return cmd.Run() +} + +// format source code +func Fmt() error { + return gofmt("./...") +} + +func gofmt(pattern string) error { + fmt.Printf("Formating source code [%s]\n", pattern) + cmd := exec.Command("go", "fmt", pattern) + mageutil.ConnectStd(cmd) + return cmd.Run() +} + +func getToolPath(name string) (string, error) { + if p, err := exec.LookPath(name); err == nil { + return p, nil + } + // check under gopath + gopath := os.Getenv("GOPATH") + if gopath == "" { + gopath = build.Default.GOPATH + } + p := filepath.Join(gopath, "bin", name) + if _, err := os.Stat(p); err != nil { + return "", err + } + return p, nil +} + +func cleanAuto() error { + fmt.Println("Delete auto directory") + cmd := exec.Command("rm", "-rf", "auto") + connectStd(cmd) + return cmd.Run() +} + +func connectStd(cmd *exec.Cmd) { + cmd.Stdout = os.Stdout + cmd.Stderr = os.Stderr +} + +func anyFun(fn ...func() error) (err error) { + for _, f := range fn { + if err = f(); err != nil { + break + } + } + return +} diff --git a/mirc/gen.go b/mirc/gen.go index 0e0009ac..2e77eece 100644 --- a/mirc/gen.go +++ b/mirc/gen.go @@ -18,8 +18,8 @@ import ( func main() { log.Println("[Mir] generate code start") if err := Generate( - Schema("web", "space", "localoss", "bot", "admin"), UseGin(), + Schema("web", "space", "localoss", "bot", "admin"), SinkPath("../auto"), WatchCtxDone(true), RunMode(InSerialMode),