Help us shape the future of Go! Take the 2026 Go Developer Survey

exampleutil

package
v0.2.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 8, 2026 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultRPCURL points at Filecoin Calibration, the network targeted by
	// these runnable examples.
	DefaultRPCURL    = "https://api.calibration.node.glif.io/rpc/v1"
	DefaultTimeout   = 30 * time.Minute
	MinUploadBytes   = 127
	PrivateKeyEnvVar = "SYNAPSE_PRIVATE_KEY"
	RPCURLEnvVar     = "SYNAPSE_RPC_URL"
	ChainEnvVar      = "SYNAPSE_CHAIN"
)

Variables

This section is empty.

Functions

func NewClient

func NewClient(ctx context.Context, cfg EnvConfig, extra ...synapse.ClientOption) (*synapse.Client, error)

NewClient creates a root SDK client from EnvConfig.

func NormalizeRPCURL

func NormalizeRPCURL(raw string) string

NormalizeRPCURL accepts the GLIF host-only URLs that older examples used and converts them to the JSON-RPC endpoint expected by Filecoin clients.

func OpenFile

func OpenFile(path string) (*os.File, error)

OpenFile opens a file path for reading with a contextual error.

func OpenRegularFile

func OpenRegularFile(path string) (*os.File, os.FileInfo, error)

OpenRegularFile opens a regular file for upload examples.

func ParseChain

func ParseChain(raw string) (*chain.Chain, error)

ParseChain maps SYNAPSE_CHAIN to a known chain. Empty means auto-detect from RPC.

func PrintPrepare

func PrintPrepare(w io.Writer, result *storage.PrepareResult) error

PrintPrepare writes the funding summary returned by storage.Prepare.

func ValidateUploadSize

func ValidateUploadSize(label string, size int64) error

ValidateUploadSize rejects payloads too small to produce a PieceCIDv2.

func WithTimeout

func WithTimeout(parent context.Context, timeout time.Duration) (context.Context, context.CancelFunc)

WithTimeout applies a consistent timeout to example commands.

func WriteKV

func WriteKV(w io.Writer, key string, value any) error

WriteKV writes a stable key=value line.

func WriteMap

func WriteMap(w io.Writer, prefix string, values map[string]string) error

WriteMap writes a string map in sorted key order as prefix.key=value lines.

func WriteTx

func WriteTx(w io.Writer, prefix string, result *types.WriteResult) error

WriteTx writes the transaction hash from an executed SDK write.

Types

type EnvConfig

type EnvConfig struct {
	PrivateKeyHex string
	RPCURL        string
	Chain         *chain.Chain
}

EnvConfig contains the common wallet/RPC settings shared by examples.

func LoadEnv

func LoadEnv(getenv func(string) string) (EnvConfig, error)

LoadEnv reads the standard example environment. SYNAPSE_PRIVATE_KEY is required; SYNAPSE_RPC_URL defaults to the public Calibration endpoint.

func (EnvConfig) ClientOptions

func (c EnvConfig) ClientOptions(extra ...synapse.ClientOption) []synapse.ClientOption

ClientOptions returns synapse.New options for the common environment.

type MetadataFlag

type MetadataFlag map[string]string

MetadataFlag parses repeated key=value flags into a map.

func (MetadataFlag) Map

func (m MetadataFlag) Map() map[string]string

Map returns a copy suitable for SDK option structs. Empty maps become nil.

func (*MetadataFlag) Set

func (m *MetadataFlag) Set(raw string) error

func (*MetadataFlag) String

func (m *MetadataFlag) String() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL