go-pcore documentation¶
A pure-Go reimplementation of Puppet's Pcore type system — the data-type and value model that underpins Puppet, Hiera and Facter values, built with zero cgo.
go-pcore/pcore gives a Go program the Puppet type calculus: a type model, a
type parser, a value model, and the load-bearing operations — instance-of,
assignability, inference and rich-data serialization. Type names and semantics
track Puppet's Puppet::Pops::Types, so it is a drop-in for Puppet type
expressions. The module path is github.com/go-pcore/pcore.
Status: v0.2 — full Pcore type calculus
The complete Puppet Puppet::Pops::Types set is implemented: type model,
round-trippable parser, value model, and IsInstance / IsAssignable /
Infer / Generalize / CommonType / ToData / FromData, plus
recursive type aliases and TypeSet via a Loader type environment,
Timestamp / Timespan ranges, SemVer / SemVerRange, Init, Object,
RichData, Runtime, URI, Iterable / Iterator, Error and
Callable — at 100% coverage, gofmt + go vet clean, CI green across
the six 64-bit Go targets (amd64, arm64, riscv64, loong64, ppc64le, s390x).
Install¶
Quick taste¶
package main
import (
"fmt"
"github.com/go-pcore/pcore"
)
func main() {
t, _ := pcore.Parse("Variant[Integer[0,10], Enum['a','b']]")
fmt.Println(pcore.IsInstance(t, int64(7))) // true
fmt.Println(pcore.IsInstance(t, "a")) // true
fmt.Println(pcore.IsInstance(t, int64(99))) // false
fmt.Println(pcore.Infer([]pcore.Value{int64(1), int64(2)}))
// Array[Integer[1, 2], 2, 2]
fmt.Println(t.String()) // round-trips through Parse
}
Where to next¶
- The type calculus — every type and its parameters.
- Usage & API — the Go surface.
- Assignability & inference — the subtype lattice.
- Rich-data serialization —
ToData/FromData.