8000 feat(tool): add env for using prutal to marshal by xiaost · Pull Request #1759 · cloudwego/kitex · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

feat(tool): add env for using prutal to marshal #1759

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions tool/internal_pkg/generator/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -605,11 +605,11 @@ func (g *generator) setImports(name string, pkg *PackageInfo) {
pkg.AddImports("fmt")
}
if m.GenArgResultStruct {
if env.UseProtoc() {
pkg.AddImports("proto")
} else {
if env.UsePrutalMarshal() {
// reuse "proto" so that no need to change code templates ...
pkg.AddImport("proto", "github.com/cloudwego/prutal")
} else {
pkg.AddImports("proto")
}
} else {
// for method Arg and Result
Expand Down
14 changes: 13 additions & 1 deletion tool/internal_pkg/util/env/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,19 @@ import (
func UseProtoc() bool {
v := os.Getenv("KITEX_TOOL_USE_PROTOC")
if v == "" {
return false // disable protoc by default
return false // false by default
}
ok, _ := strconv.ParseBool(v)
return ok
}

func UsePrutalMarshal() bool {
if !UseProtoc() {
return true // if not using protoc, can only use prutal
}
v := os.Getenv("KITEX_TOOL_USE_PRUTAL_MARSHAL")
if v == "" {
return false // false by default
}
ok, _ := strconv.ParseBool(v)
return ok
Expand Down
16 changes: 16 additions & 0 deletions tool/internal_pkg/util/env/env_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,19 @@ func TestUseProtoc(t *testing.T) {
use = UseProtoc()
test.Assert(t, use == false, use)
}

func TestUsePrutalMarshal(t *testing.T) {
use := UsePrutalMarshal() // default: true
test.Assert(t, use == true, use)

t.Setenv("KITEX_TOOL_USE_PROTOC", "0")
use = UsePrutalMarshal()
test.Assert(t, use == true, use)

t.Setenv("KITEX_TOOL_USE_PROTOC", "1")
use = UsePrutalMarshal()
test.Assert(t, use == false, use)
t.Setenv("KITEX_TOOL_USE_PRUTAL_MARSHAL", "1")
use = UsePrutalMarshal()
test.Assert(t, use == true, use)
}
0