v1

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Jul 9, 2026 License: MIT Imports: 0 Imported by: 0

Documentation

Overview

Package v1 is the stable public surface for golib. The Builder interface and Result type here are the contract callers depend on across releases; the implementation lives in v1alpha1 and may change between alpha revisions.

Example (Value)

WithValue sets the payload; the name is optional. Built without WithName, the Result's Name is empty.

package main

import (
	"fmt"

	"github.com/cnuss/golib"
)

func main() {
	res := golib.New[int]().WithValue(42).Build()

	fmt.Printf("name=%q value=%d\n", res.Name, res.Value)
}
Output:
name="" value=42
Example (ZeroValue)

The zero value of T is returned when WithValue is never called.

package main

import (
	"fmt"

	"github.com/cnuss/golib"
)

func main() {
	res := golib.New[int]().WithName("count").Build()

	fmt.Printf("name=%q value=%d\n", res.Name, res.Value)
}
Output:
name="count" value=0

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Builder

type Builder[T any] interface {
	// WithName sets a display name carried into the Result. Unset, the name is
	// empty.
	WithName(name string) Builder[T]
	// WithValue sets the payload the builder produces. Unset, Build returns the
	// zero value of T.
	WithValue(v T) Builder[T]
	// Build assembles the configured value and returns it. It is the terminal
	// step; calling it more than once returns the same Result.
	Build() Result[T]
	// Name returns the configured name (empty if WithName was never called).
	Name() string
}

Builder assembles a value of type T from optional configuration. Configure it with the With* methods (each returns the Builder for chaining), then call the terminal Build to produce a Result. Obtain one from golib.New.

type Result

type Result[T any] struct {
	Name  string `json:"name,omitempty"`
	Value T      `json:"value"`
}

Result is the structured output of Builder.Build. The json tags make it drop straight into encoding/json and compatible marshalers.

Jump to

Keyboard shortcuts

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