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.
Click to show internal directories.
Click to hide internal directories.