gotohelm

package
v0.0.0-...-b8771ce Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2024 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Overview

package gotohelm implements a source to source compiler (transpiler) from go to helm templates.

gotohelm relies on the go compiler to type check code and on go test to assert the correctness thereof. Doing so allows the transpiling process to generally "trust" the code that's being transpiled. After the initial parsing and type checking, a collection of AST rewrites are performed to convert various bits of go syntax into (mostly) equivalent but more easily transpilable syntax.

gotohelm takes the approach of bootstrapping a rudimentary LISP-y programming language within helm templates using the available builtins.

# Functions Functions are "implemented" by abusing the `include` builtin and are turned into `define` blocks. Return values are wrapped in a dictionary and marshalled to JSON. (Almost like Internet Explorer circa 2011). Function calls are then a pipline of `(include NAME ARGS...) | fromJson | get RETURNKEY`

# Interop Transpiled go functions can be invoked within existing templates using the following syntax: `((include NAME (dict "a" (list ARGS...))) | fromJson | get "r")`

Limitations

  • There is no "trap door" to fallback to raw templates
  • Switch statements, in all forms, are not currently supported
  • Code must deal with the "lowest common denominator" of .Values in the form of map[string]any. Values coalescing has not yet been implemented.
  • Type assertions don't work.
  • Many helpers and bits of syntax are missing.
  • Most forms of incompatibility are handled with panics and fmt.Sprintf.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LoadPackages

func LoadPackages(cfg *packages.Config, patterns ...string) ([]*packages.Package, error)

LoadPackages is a wrapper around packages.Load that performs a handful of AST rewrites followed by a second invocation of packages.Load to appropriately populate the AST. AST rewriting is done to keep the transpilation process to be as simple as possible. Any unsuported or non-trivially supported expressions/statements will be rewritten to supported equivalents instead. If need be, the rewritten files can also be dumped to disk and have assertions made

Types

type Assignment

type Assignment struct {
	LHS Node
	New bool
	RHS Node
}

func (*Assignment) Write

func (a *Assignment) Write(w io.Writer)

type Binary

type Binary struct {
	LHS Node
	Op  string
	RHS Node
}

func (*Binary) Write

func (b *Binary) Write(w io.Writer)

type Block

type Block struct {
	Statements []Node
}

func (*Block) Write

func (b *Block) Write(w io.Writer)

type BuiltInCall

type BuiltInCall struct {
	FuncName  string
	Arguments []Node
}

func (*BuiltInCall) Write

func (c *BuiltInCall) Write(w io.Writer)

type Call

type Call struct {
	FuncName  string
	Arguments []Node
}

func (*Call) Write

func (c *Call) Write(w io.Writer)

type Chart

type Chart struct {
	Files []*File
}

func Transpile

func Transpile(pkg *packages.Package) (_ *Chart, err error)

type DictLiteral

type DictLiteral struct {
	KeysValues []*KeyValue
}

func (*DictLiteral) Write

func (d *DictLiteral) Write(w io.Writer)

type File

type File struct {
	Source string
	Name   string
	Header string
	Funcs  []*Func
}

func (*File) Write

func (f *File) Write(w io.Writer)

type Func

type Func struct {
	Namespace  string
	Name       string
	Params     []Node
	Statements []Node
}

func (*Func) Write

func (f *Func) Write(w io.Writer)

type Ident

type Ident struct {
	Name string
}

func (*Ident) Write

func (i *Ident) Write(w io.Writer)

type IfStmt

type IfStmt struct {
	Init Node
	Cond Node
	Body Node
	Else Node
}

func (*IfStmt) Write

func (i *IfStmt) Write(w io.Writer)

type KeyValue

type KeyValue struct {
	Key   string
	Value Node
}

func (*KeyValue) Write

func (p *KeyValue) Write(w io.Writer)

type Literal

type Literal struct {
	Value string
}

func NewLiteral

func NewLiteral(unquoted string) *Literal

func (*Literal) Write

func (l *Literal) Write(w io.Writer)

type Nil

type Nil struct{}

func (*Nil) Write

func (*Nil) Write(w io.Writer)

type Node

type Node interface {
	Write(io.Writer)
}

type ParenExpr

type ParenExpr struct {
	Expr Node
}

func (*ParenExpr) Write

func (s *ParenExpr) Write(w io.Writer)

type Range

type Range struct {
	Key   Node
	Value Node
	Over  Node
	Body  Node
}

func (*Range) Write

func (r *Range) Write(w io.Writer)

type Return

type Return struct {
	Expr Node
}

func (*Return) Write

func (r *Return) Write(w io.Writer)

type Selector

type Selector struct {
	Expr  Node
	Field string
}

func (*Selector) Write

func (s *Selector) Write(w io.Writer)

type Statement

type Statement struct {
	NoCapture bool
	Expr      Node
}

func (*Statement) Write

func (s *Statement) Write(w io.Writer)

type Transpiler

type Transpiler struct {
	Package   *packages.Package
	Fset      *token.FileSet
	Files     []*ast.File
	TypesInfo *types.Info
	// contains filtered or unexported fields
}

func (*Transpiler) Transpile

func (t *Transpiler) Transpile() *Chart

type Unsupported

type Unsupported struct {
	Node ast.Node
	Msg  string
	Fset *token.FileSet
}

func (*Unsupported) Error

func (u *Unsupported) Error() string

Directories

Path Synopsis
package helmette implements golang analogs for the constructs present within the helm template rendering environment.
package helmette implements golang analogs for the constructs present within the helm template rendering environment.
internal
bootstrap
Welcome to the magical bootstrap package.
Welcome to the magical bootstrap package.

Jump to

Keyboard shortcuts

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