@@ -11,6 +11,8 @@ import (
1111 pgsgo "github.com/lyft/protoc-gen-star/lang/go"
1212)
1313
14+ const TRANSFORM_PACKAGE_FOR_HASH_PARAMETER_NAME = "transform_package_for_hash"
15+
1416func register (tpl * template.Template , params pgs.Parameters ) {
1517 fns := goSharedFuncs {
1618 Context : pgsgo .InitContext (params ),
@@ -52,8 +54,24 @@ func (fns goSharedFuncs) fieldName(field pgs.Field) string {
5254 return fmt .Sprintf ("%s" , fns .Name (field ))
5355}
5456
57+ // fullPackageName constructs and returns the full package name of a message as a string.
58+ // If the parameter transform_package_for_hash is set, using the format "old=new", the function will
59+ // replace all instances of "old" with "new" in the full package name before returning the new value.
60+ // If the parameter transform_package_for_hash does not have a empty or valid value, the function will panic.
5561func (fns goSharedFuncs ) fullPackageName (msg pgs.Message ) string {
56- return fmt .Sprintf ("%s.%s.%s" , msg .Package ().ProtoName (), fns .ImportPath (msg ), fns .Name (msg ))
62+ fullPackageName := fmt .Sprintf ("%s.%s.%s" , msg .Package ().ProtoName (), fns .ImportPath (msg ), fns .Name (msg ))
63+ transformPackageForHash := fns .Params ().Str (TRANSFORM_PACKAGE_FOR_HASH_PARAMETER_NAME )
64+ if transformPackageForHash == "" {
65+ return fullPackageName
66+ }
67+
68+ replaceParts := strings .Split (transformPackageForHash , "=" )
69+ if len (replaceParts ) != 2 {
70+ // If the valud in the parameter is not in the format "old=new", the process should fail
71+ panic (fmt .Sprintf ("Invalid transform string: %s" , transformPackageForHash ))
72+ }
73+
74+ return strings .ReplaceAll (fullPackageName , replaceParts [0 ], replaceParts [1 ])
5775}
5876
5977func (fns goSharedFuncs ) lookup (f pgs.Field , name string ) string {
0 commit comments