@@ -22,12 +22,12 @@ var (
2222
2323var (
2424 mu = & sync.RWMutex {}
25- registry = map [string ]interface {} {}
25+ registry = map [string ]any {}
2626)
2727
2828// Register a type for marshalling and unmarshalling.
2929// The type must currently implement proto.Message.
30- func Register (v interface {} ) error {
30+ func Register (v any ) error {
3131 mu .Lock ()
3232 defer mu .Unlock ()
3333
@@ -45,9 +45,9 @@ func Register(v interface{}) error {
4545 name := TypeName (v )
4646 registry [name ] = v
4747 // TODO(aj) Temporary migration solution for go module upgrade
48- if strings .HasPrefix (name , "github.com/lytics/lio/vendor/" ) {
48+ if after , ok0 := strings .CutPrefix (name , "github.com/lytics/lio/vendor/" ); ok0 {
4949 // If we're the pre go.mod, register the other namespace
50- otherName := strings . TrimPrefix ( name , "github.com/lytics/lio/vendor/" )
50+ otherName := after
5151 registry [otherName ] = v
5252 } else {
5353 // If we're using go.mod, register the old namespace
@@ -59,7 +59,7 @@ func Register(v interface{}) error {
5959
6060// Marshal the value into bytes. The function returns
6161// the type name, the bytes, or an error.
62- func Marshal (v interface {} ) (string , []byte , error ) {
62+ func Marshal (v any ) (string , []byte , error ) {
6363 mu .RLock ()
6464 defer mu .RUnlock ()
6565
@@ -78,7 +78,7 @@ func Marshal(v interface{}) (string, []byte, error) {
7878
7979// Unmarshal the bytes into a value whos type is given,
8080// or return an error.
81- func Unmarshal (buf []byte , name string ) (interface {} , error ) {
81+ func Unmarshal (buf []byte , name string ) (any , error ) {
8282 mu .RLock ()
8383 defer mu .RUnlock ()
8484
@@ -96,7 +96,7 @@ func Unmarshal(buf []byte, name string) (interface{}, error) {
9696
9797// TypeName of a value. This name is used in the registry
9898// to distinguish types.
99- func TypeName (v interface {} ) string {
99+ func TypeName (v any ) string {
100100 rt := reflect .TypeOf (v )
101101 pkg := rt .PkgPath ()
102102 name := rt .Name ()
@@ -108,12 +108,12 @@ func TypeName(v interface{}) string {
108108 return pkg + "/" + name
109109}
110110
111- func protoMarshal (v interface {} ) ([]byte , error ) {
111+ func protoMarshal (v any ) ([]byte , error ) {
112112 pb := v .(proto.Message )
113113 return proto .Marshal (pb )
114114}
115115
116- func protoUnmarshal (buf []byte , v interface {} ) error {
116+ func protoUnmarshal (buf []byte , v any ) error {
117117 pb := v .(proto.Message )
118118 return proto .Unmarshal (buf , pb )
119119}
0 commit comments