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

contract

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2026 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package contract defines language-neutral data contracts that can be inspected from source code and rendered into host formats such as NFlow.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RenderNFlow

func RenderNFlow(contracts []Contract) (string, error)

RenderNFlow renders valid @schema declarations and a commented pipeline example. The commented example keeps the generated file compilable until a user adds real actions.

func ValidateAll

func ValidateAll(contracts []Contract) error

ValidateAll checks every contract and rejects duplicate schema names.

Types

type Contract

type Contract struct {
	Name        string  `json:"name"`
	Description string  `json:"description,omitempty"`
	Fields      []Field `json:"fields"`
}

Contract is a named, language-neutral object shape.

func (Contract) Validate

func (c Contract) Validate() error

Validate checks names, field uniqueness, and recursive value types.

type Field

type Field struct {
	Name     string    `json:"name"`
	JSONName string    `json:"json_name,omitempty"`
	Type     ValueType `json:"type"`
	Required bool      `json:"required"`
}

Field describes one named value in a contract. JSONName is optional and defaults to Name; Required describes whether the field must be present.

type TypeKind

type TypeKind string

TypeKind is a language-independent value category.

const (
	String  TypeKind = "string"
	Integer TypeKind = "integer"
	Number  TypeKind = "number"
	Boolean TypeKind = "boolean"
	Object  TypeKind = "object"
	Array   TypeKind = "array"
	Any     TypeKind = "any"
)

type ValueType

type ValueType struct {
	Kind    TypeKind   `json:"kind"`
	Element *ValueType `json:"element,omitempty"`
}

ValueType describes a value without carrying source-language syntax. Element is used only when Kind is Array; a nil element means any.

Jump to

Keyboard shortcuts

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