From 6e7c7f9e8daaee62513842fd7eefb4e8d2fe8ba3 Mon Sep 17 00:00:00 2001 From: wenchy Date: Fri, 15 Aug 2025 16:23:27 +0800 Subject: [PATCH 1/2] go(BREAKING)!: use messager-level options for Load func in Messager interface --- cmd/protoc-gen-go-tableau-loader/hub.go | 8 +++++--- cmd/protoc-gen-go-tableau-loader/messager.go | 4 ++-- go.mod | 2 +- go.sum | 4 ++-- .../protoconf/loader/hero_conf.pc.go | 8 ++++---- .../go-tableau-loader/protoconf/loader/hub.pc.go | 8 +++++--- .../protoconf/loader/item_conf.pc.go | 4 ++-- .../protoconf/loader/patch_conf.pc.go | 12 ++++++------ .../protoconf/loader/test_conf.pc.go | 16 ++++++++-------- 9 files changed, 35 insertions(+), 31 deletions(-) diff --git a/cmd/protoc-gen-go-tableau-loader/hub.go b/cmd/protoc-gen-go-tableau-loader/hub.go index 6dadb63c..38df4dd2 100644 --- a/cmd/protoc-gen-go-tableau-loader/hub.go +++ b/cmd/protoc-gen-go-tableau-loader/hub.go @@ -74,7 +74,7 @@ type Messager interface { // GetStats returns stats info. GetStats() *Stats // Load fills message from file in the specified directory and format. - Load(dir string, fmt format.Format, options ...load.Option) error + Load(dir string, fmt format.Format, opts *load.MessagerOptions) error // Store writes message to file in the specified directory and format. Store(dir string, fmt format.Format, options ...store.Option) error // processAfterLoad is invoked after this messager loaded. @@ -169,7 +169,7 @@ func (x *UnimplementedMessager) GetStats() *Stats { return &x.Stats } -func (x *UnimplementedMessager) Load(dir string, format format.Format, options ...load.Option) error { +func (x *UnimplementedMessager) Load(dir string, format format.Format, opts *load.MessagerOptions) error { return nil } @@ -290,8 +290,10 @@ func (h *Hub) GetMessager(name string) Messager { // Load fills messages from files in the specified directory and format. func (h *Hub) Load(dir string, format format.Format, options ...load.Option) error { messagerMap := h.NewMessagerMap() + opts := load.ParseOptions(options...) for name, msger := range messagerMap { - if err := msger.Load(dir, format, options...); err != nil { + mopts := load.ParseMessagerOptionsFromOptions(opts, name) + if err := msger.Load(dir, format, mopts); err != nil { return errors.WithMessagef(err, "failed to load: %v", name) } } diff --git a/cmd/protoc-gen-go-tableau-loader/messager.go b/cmd/protoc-gen-go-tableau-loader/messager.go index 5fd0f391..137cc239 100644 --- a/cmd/protoc-gen-go-tableau-loader/messager.go +++ b/cmd/protoc-gen-go-tableau-loader/messager.go @@ -123,13 +123,13 @@ func genMessage(gen *protogen.Plugin, g *protogen.GeneratedFile, message *protog g.P() g.P("// Load fills ", messagerName, "'s inner message from file in the specified directory and format.") - g.P("func (x *", messagerName, ") Load(dir string, format ", formatPackage.Ident("Format"), " , options ...", loadPackage.Ident("Option"), ") error {") + g.P("func (x *", messagerName, ") Load(dir string, format ", formatPackage.Ident("Format"), " , opts *", loadPackage.Ident("MessagerOptions"), ") error {") g.P("start := ", timePackage.Ident("Now"), "()") g.P("defer func () {") g.P("x.Stats.Duration = ", timePackage.Ident("Since"), "(start)") g.P("}()") g.P("x.data = &", message.GoIdent, "{}") - g.P("err := ", loadPackage.Ident("Load"), "(x.data, dir, format, options...)") + g.P("err := ", loadPackage.Ident("LoadMessagerInDir"), "(x.data, dir, format, opts)") g.P("if err != nil {") g.P("return err") g.P("}") diff --git a/go.mod b/go.mod index 36b3afb7..42f919e3 100644 --- a/go.mod +++ b/go.mod @@ -7,7 +7,7 @@ require ( github.com/pkg/errors v0.9.1 github.com/pmezard/go-difflib v1.0.0 github.com/stretchr/testify v1.10.0 - github.com/tableauio/tableau v0.13.1-0.20250729035848-d72aa4ead3c4 + github.com/tableauio/tableau v0.13.1-0.20250815080041-1ac1b4e6f943 golang.org/x/exp v0.0.0-20230418202329-0354be287a23 google.golang.org/protobuf v1.34.2 ) diff --git a/go.sum b/go.sum index 408c552e..e411a8c2 100644 --- a/go.sum +++ b/go.sum @@ -100,8 +100,8 @@ github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOf github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= github.com/subchen/go-xmldom v1.1.2 h1:7evI2YqfYYOnuj+PBwyaOZZYjl3iWq35P6KfBUw9jeU= github.com/subchen/go-xmldom v1.1.2/go.mod h1:6Pg/HuX5/T4Jlj0IPJF1sRxKVoI/rrKP6LIMge9d5/8= -github.com/tableauio/tableau v0.13.1-0.20250729035848-d72aa4ead3c4 h1:4xwjLqGulwJLjo7yr4z8jjbYo37H1X9j92D8aA6EIng= -github.com/tableauio/tableau v0.13.1-0.20250729035848-d72aa4ead3c4/go.mod h1:EitY0lyJa8gP6tBkzWhS2WvYhC8hyWPGXoR4QPQ+Qmw= +github.com/tableauio/tableau v0.13.1-0.20250815080041-1ac1b4e6f943 h1:36NL5g7jmFx/e3F/98DVj2JdN5URuVvzRo+jniXct2s= +github.com/tableauio/tableau v0.13.1-0.20250815080041-1ac1b4e6f943/go.mod h1:EitY0lyJa8gP6tBkzWhS2WvYhC8hyWPGXoR4QPQ+Qmw= github.com/twitchyliquid64/golang-asm v0.15.1 h1:SU5vSMR7hnwNxj24w34ZyCi/FmDZTkS4MhqMhdFk5YI= github.com/twitchyliquid64/golang-asm v0.15.1/go.mod h1:a1lVb/DtPvCB8fslRZhAngC2+aY1QWCk3Cedj/Gdt08= github.com/xuri/efp v0.0.0-20220603152613-6918739fd470 h1:6932x8ltq1w4utjmfMPVj09jdMlkY0aiA6+Skbtl3/c= diff --git a/test/go-tableau-loader/protoconf/loader/hero_conf.pc.go b/test/go-tableau-loader/protoconf/loader/hero_conf.pc.go index b9b00332..f94d762c 100644 --- a/test/go-tableau-loader/protoconf/loader/hero_conf.pc.go +++ b/test/go-tableau-loader/protoconf/loader/hero_conf.pc.go @@ -53,13 +53,13 @@ func (x *HeroConf) Data() *protoconf.HeroConf { } // Load fills HeroConf's inner message from file in the specified directory and format. -func (x *HeroConf) Load(dir string, format format.Format, options ...load.Option) error { +func (x *HeroConf) Load(dir string, format format.Format, opts *load.MessagerOptions) error { start := time.Now() defer func() { x.Stats.Duration = time.Since(start) }() x.data = &protoconf.HeroConf{} - err := load.Load(x.data, dir, format, options...) + err := load.LoadMessagerInDir(x.data, dir, format, opts) if err != nil { return err } @@ -194,13 +194,13 @@ func (x *HeroBaseConf) Data() *protoconf.HeroBaseConf { } // Load fills HeroBaseConf's inner message from file in the specified directory and format. -func (x *HeroBaseConf) Load(dir string, format format.Format, options ...load.Option) error { +func (x *HeroBaseConf) Load(dir string, format format.Format, opts *load.MessagerOptions) error { start := time.Now() defer func() { x.Stats.Duration = time.Since(start) }() x.data = &protoconf.HeroBaseConf{} - err := load.Load(x.data, dir, format, options...) + err := load.LoadMessagerInDir(x.data, dir, format, opts) if err != nil { return err } diff --git a/test/go-tableau-loader/protoconf/loader/hub.pc.go b/test/go-tableau-loader/protoconf/loader/hub.pc.go index f70c49cf..a80fb21a 100644 --- a/test/go-tableau-loader/protoconf/loader/hub.pc.go +++ b/test/go-tableau-loader/protoconf/loader/hub.pc.go @@ -26,7 +26,7 @@ type Messager interface { // GetStats returns stats info. GetStats() *Stats // Load fills message from file in the specified directory and format. - Load(dir string, fmt format.Format, options ...load.Option) error + Load(dir string, fmt format.Format, opts *load.MessagerOptions) error // Store writes message to file in the specified directory and format. Store(dir string, fmt format.Format, options ...store.Option) error // processAfterLoad is invoked after this messager loaded. @@ -121,7 +121,7 @@ func (x *UnimplementedMessager) GetStats() *Stats { return &x.Stats } -func (x *UnimplementedMessager) Load(dir string, format format.Format, options ...load.Option) error { +func (x *UnimplementedMessager) Load(dir string, format format.Format, opts *load.MessagerOptions) error { return nil } @@ -242,8 +242,10 @@ func (h *Hub) GetMessager(name string) Messager { // Load fills messages from files in the specified directory and format. func (h *Hub) Load(dir string, format format.Format, options ...load.Option) error { messagerMap := h.NewMessagerMap() + opts := load.ParseOptions(options...) for name, msger := range messagerMap { - if err := msger.Load(dir, format, options...); err != nil { + mopts := load.ParseMessagerOptionsFromOptions(opts, name) + if err := msger.Load(dir, format, mopts); err != nil { return errors.WithMessagef(err, "failed to load: %v", name) } } diff --git a/test/go-tableau-loader/protoconf/loader/item_conf.pc.go b/test/go-tableau-loader/protoconf/loader/item_conf.pc.go index c8169c91..52a9610b 100644 --- a/test/go-tableau-loader/protoconf/loader/item_conf.pc.go +++ b/test/go-tableau-loader/protoconf/loader/item_conf.pc.go @@ -102,13 +102,13 @@ func (x *ItemConf) Data() *protoconf.ItemConf { } // Load fills ItemConf's inner message from file in the specified directory and format. -func (x *ItemConf) Load(dir string, format format.Format, options ...load.Option) error { +func (x *ItemConf) Load(dir string, format format.Format, opts *load.MessagerOptions) error { start := time.Now() defer func() { x.Stats.Duration = time.Since(start) }() x.data = &protoconf.ItemConf{} - err := load.Load(x.data, dir, format, options...) + err := load.LoadMessagerInDir(x.data, dir, format, opts) if err != nil { return err } diff --git a/test/go-tableau-loader/protoconf/loader/patch_conf.pc.go b/test/go-tableau-loader/protoconf/loader/patch_conf.pc.go index fe045329..3ac31cd2 100644 --- a/test/go-tableau-loader/protoconf/loader/patch_conf.pc.go +++ b/test/go-tableau-loader/protoconf/loader/patch_conf.pc.go @@ -45,13 +45,13 @@ func (x *PatchReplaceConf) Data() *protoconf.PatchReplaceConf { } // Load fills PatchReplaceConf's inner message from file in the specified directory and format. -func (x *PatchReplaceConf) Load(dir string, format format.Format, options ...load.Option) error { +func (x *PatchReplaceConf) Load(dir string, format format.Format, opts *load.MessagerOptions) error { start := time.Now() defer func() { x.Stats.Duration = time.Since(start) }() x.data = &protoconf.PatchReplaceConf{} - err := load.Load(x.data, dir, format, options...) + err := load.LoadMessagerInDir(x.data, dir, format, opts) if err != nil { return err } @@ -114,13 +114,13 @@ func (x *PatchMergeConf) Data() *protoconf.PatchMergeConf { } // Load fills PatchMergeConf's inner message from file in the specified directory and format. -func (x *PatchMergeConf) Load(dir string, format format.Format, options ...load.Option) error { +func (x *PatchMergeConf) Load(dir string, format format.Format, opts *load.MessagerOptions) error { start := time.Now() defer func() { x.Stats.Duration = time.Since(start) }() x.data = &protoconf.PatchMergeConf{} - err := load.Load(x.data, dir, format, options...) + err := load.LoadMessagerInDir(x.data, dir, format, opts) if err != nil { return err } @@ -194,13 +194,13 @@ func (x *RecursivePatchConf) Data() *protoconf.RecursivePatchConf { } // Load fills RecursivePatchConf's inner message from file in the specified directory and format. -func (x *RecursivePatchConf) Load(dir string, format format.Format, options ...load.Option) error { +func (x *RecursivePatchConf) Load(dir string, format format.Format, opts *load.MessagerOptions) error { start := time.Now() defer func() { x.Stats.Duration = time.Since(start) }() x.data = &protoconf.RecursivePatchConf{} - err := load.Load(x.data, dir, format, options...) + err := load.LoadMessagerInDir(x.data, dir, format, opts) if err != nil { return err } diff --git a/test/go-tableau-loader/protoconf/loader/test_conf.pc.go b/test/go-tableau-loader/protoconf/loader/test_conf.pc.go index 96cec9d8..a3194def 100644 --- a/test/go-tableau-loader/protoconf/loader/test_conf.pc.go +++ b/test/go-tableau-loader/protoconf/loader/test_conf.pc.go @@ -78,13 +78,13 @@ func (x *ActivityConf) Data() *protoconf.ActivityConf { } // Load fills ActivityConf's inner message from file in the specified directory and format. -func (x *ActivityConf) Load(dir string, format format.Format, options ...load.Option) error { +func (x *ActivityConf) Load(dir string, format format.Format, opts *load.MessagerOptions) error { start := time.Now() defer func() { x.Stats.Duration = time.Since(start) }() x.data = &protoconf.ActivityConf{} - err := load.Load(x.data, dir, format, options...) + err := load.LoadMessagerInDir(x.data, dir, format, opts) if err != nil { return err } @@ -413,13 +413,13 @@ func (x *ChapterConf) Data() *protoconf.ChapterConf { } // Load fills ChapterConf's inner message from file in the specified directory and format. -func (x *ChapterConf) Load(dir string, format format.Format, options ...load.Option) error { +func (x *ChapterConf) Load(dir string, format format.Format, opts *load.MessagerOptions) error { start := time.Now() defer func() { x.Stats.Duration = time.Since(start) }() x.data = &protoconf.ChapterConf{} - err := load.Load(x.data, dir, format, options...) + err := load.LoadMessagerInDir(x.data, dir, format, opts) if err != nil { return err } @@ -493,13 +493,13 @@ func (x *ThemeConf) Data() *protoconf.ThemeConf { } // Load fills ThemeConf's inner message from file in the specified directory and format. -func (x *ThemeConf) Load(dir string, format format.Format, options ...load.Option) error { +func (x *ThemeConf) Load(dir string, format format.Format, opts *load.MessagerOptions) error { start := time.Now() defer func() { x.Stats.Duration = time.Since(start) }() x.data = &protoconf.ThemeConf{} - err := load.Load(x.data, dir, format, options...) + err := load.LoadMessagerInDir(x.data, dir, format, opts) if err != nil { return err } @@ -593,13 +593,13 @@ func (x *TaskConf) Data() *protoconf.TaskConf { } // Load fills TaskConf's inner message from file in the specified directory and format. -func (x *TaskConf) Load(dir string, format format.Format, options ...load.Option) error { +func (x *TaskConf) Load(dir string, format format.Format, opts *load.MessagerOptions) error { start := time.Now() defer func() { x.Stats.Duration = time.Since(start) }() x.data = &protoconf.TaskConf{} - err := load.Load(x.data, dir, format, options...) + err := load.LoadMessagerInDir(x.data, dir, format, opts) if err != nil { return err } From 34bb0c5258fb17218d07af4334e89a5278218802 Mon Sep 17 00:00:00 2001 From: wenchy Date: Fri, 15 Aug 2025 17:04:41 +0800 Subject: [PATCH 2/2] chore: update tableau pkg --- go.mod | 2 +- go.sum | 4 ++-- third_party/_submodules/tableau | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/go.mod b/go.mod index 42f919e3..2baff54a 100644 --- a/go.mod +++ b/go.mod @@ -7,7 +7,7 @@ require ( github.com/pkg/errors v0.9.1 github.com/pmezard/go-difflib v1.0.0 github.com/stretchr/testify v1.10.0 - github.com/tableauio/tableau v0.13.1-0.20250815080041-1ac1b4e6f943 + github.com/tableauio/tableau v0.13.1-0.20250815085205-2917481cc73f golang.org/x/exp v0.0.0-20230418202329-0354be287a23 google.golang.org/protobuf v1.34.2 ) diff --git a/go.sum b/go.sum index e411a8c2..b08b353d 100644 --- a/go.sum +++ b/go.sum @@ -100,8 +100,8 @@ github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOf github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= github.com/subchen/go-xmldom v1.1.2 h1:7evI2YqfYYOnuj+PBwyaOZZYjl3iWq35P6KfBUw9jeU= github.com/subchen/go-xmldom v1.1.2/go.mod h1:6Pg/HuX5/T4Jlj0IPJF1sRxKVoI/rrKP6LIMge9d5/8= -github.com/tableauio/tableau v0.13.1-0.20250815080041-1ac1b4e6f943 h1:36NL5g7jmFx/e3F/98DVj2JdN5URuVvzRo+jniXct2s= -github.com/tableauio/tableau v0.13.1-0.20250815080041-1ac1b4e6f943/go.mod h1:EitY0lyJa8gP6tBkzWhS2WvYhC8hyWPGXoR4QPQ+Qmw= +github.com/tableauio/tableau v0.13.1-0.20250815085205-2917481cc73f h1:Nf0UX+/p5tzm9c2KyfdqM9oxMb3ZuP5sGr60zK8xmvk= +github.com/tableauio/tableau v0.13.1-0.20250815085205-2917481cc73f/go.mod h1:EitY0lyJa8gP6tBkzWhS2WvYhC8hyWPGXoR4QPQ+Qmw= github.com/twitchyliquid64/golang-asm v0.15.1 h1:SU5vSMR7hnwNxj24w34ZyCi/FmDZTkS4MhqMhdFk5YI= github.com/twitchyliquid64/golang-asm v0.15.1/go.mod h1:a1lVb/DtPvCB8fslRZhAngC2+aY1QWCk3Cedj/Gdt08= github.com/xuri/efp v0.0.0-20220603152613-6918739fd470 h1:6932x8ltq1w4utjmfMPVj09jdMlkY0aiA6+Skbtl3/c= diff --git a/third_party/_submodules/tableau b/third_party/_submodules/tableau index d72aa4ea..2917481c 160000 --- a/third_party/_submodules/tableau +++ b/third_party/_submodules/tableau @@ -1 +1 @@ -Subproject commit d72aa4ead3c42155400e8262b5de81a160ac0700 +Subproject commit 2917481cc73f954301f2cb46de81ed727148deb6