Skip to content

Commit

Permalink
protocodec: add a convenience GalaxyGet method
Browse files Browse the repository at this point in the history
We may add a similar version to the top-level package later, but for
now, type-inference leans in the direction of making it codec-specific.
  • Loading branch information
dfinkel committed May 24, 2023
1 parent 13d5328 commit 108ab0f
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions protocodec/galaxywrap_v2.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//go:build go1.18

package protocodec

import (
"context"

"github.com/vimeo/galaxycache"
)

// GalaxyGet is a simple wrapper around a Galaxy.Get method-call that takes
// care of constructing the protocodec.CodecV2, etc. (making the interface more idomatic for Go)
func GalaxyGet[C any, T pointerMessage[C]](ctx context.Context, g *galaxycache.Galaxy, key string) (T, error) {
pc := NewV2[C, T]()
getErr := g.Get(ctx, key, &pc)
if getErr != nil {
return nil, getErr
}
return pc.Get(), nil
}

0 comments on commit 108ab0f

Please sign in to comment.