mirror of
https://github.com/hanzoai/tasks.git
synced 2026-11-03 03:56:04 +00:00
## What changed? Integrate Go 1.26's new `go fix` into workflow. NOTE that the changes caused our linter to fire; a [separate commit](https://github.com/temporalio/temporal/pull/9337/commits/1b23f787aef370098b35829c4d17dcc06230b4c1) addresses those. ## Why? Ensure Go code is standardized/modernized. ## How did you test it? - [ ] built - [ ] run locally and tested manually - [x] covered by existing tests - [ ] added new unit test(s) - [ ] added new functional test(s)
44 lines
1.1 KiB
Go
44 lines
1.1 KiB
Go
package payloads
|
|
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
|
|
commonpb "go.temporal.io/api/common/v1"
|
|
"go.temporal.io/sdk/converter"
|
|
)
|
|
|
|
var (
|
|
defaultDataConverter = converter.GetDefaultDataConverter()
|
|
)
|
|
|
|
func EncodeString(str string) *commonpb.Payloads {
|
|
// Error can be safely ignored here becase string always can be converted.
|
|
ps, _ := defaultDataConverter.ToPayloads(str)
|
|
return ps
|
|
}
|
|
|
|
func EncodeInt(i int) *commonpb.Payloads {
|
|
// Error can be safely ignored here becase int always can be converted.
|
|
ps, _ := defaultDataConverter.ToPayloads(i)
|
|
return ps
|
|
}
|
|
|
|
func EncodeBytes(bytes []byte) *commonpb.Payloads {
|
|
// Error can be safely ignored here becase []byte always can be raw encoded.
|
|
ps, _ := defaultDataConverter.ToPayloads(bytes)
|
|
return ps
|
|
}
|
|
|
|
func Encode(value ...any) (*commonpb.Payloads, error) {
|
|
return defaultDataConverter.ToPayloads(value...)
|
|
}
|
|
|
|
func Decode(ps *commonpb.Payloads, valuePtr ...any) error {
|
|
return defaultDataConverter.FromPayloads(ps, valuePtr...)
|
|
}
|
|
|
|
func ToString(ps *commonpb.Payloads) string {
|
|
return fmt.Sprintf("[%s]", strings.Join(defaultDataConverter.ToStrings(ps), ", "))
|
|
}
|