parser

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Dec 9, 2020 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var TestExceptApp = &Appfile{
	name: "test",
	services: []*Workload{
		{
			name: "myweb",
			typ:  "worker",
			params: map[string]interface{}{
				"image": "busybox",
				"cmd":   []interface{}{"sleep", "1000"},
			},
			template: `
      output: {
        apiVersion: "apps/v1"
      	kind:       "Deployment"
      	spec: {
      		selector: matchLabels: {
      			"app.oam.dev/component": context.name
      		}
      
      		template: {
      			metadata: labels: {
      				"app.oam.dev/component": context.name
      			}
      
      			spec: {
      				containers: [{
      					name:  context.name
      					image: parameter.image
      
      					if parameter["cmd"] != _|_ {
      						command: parameter.cmd
      					}
      				}]
      			}
      		}
      
      		selector:
      			matchLabels:
      				"app.oam.dev/component": context.name
      	}
      }
      
      parameter: {
      	// +usage=Which image would you like to use for your service
      	// +short=i
      	image: string
      
      	cmd?: [...string]
      }`,
			traits: []*Trait{
				{
					name: "scaler",
					params: map[string]interface{}{
						"replicas": 10,
					},
					template: `
      output: {
      	apiVersion: "core.oam.dev/v1alpha2"
      	kind:       "ManualScalerTrait"
      	spec: {
      		replicaCount: parameter.replicas
      	}
      }
      parameter: {
      	//+short=r
      	replicas: *1 | int
      }
`,
				},
			},
		},
	},
}

TestExceptApp is test data

Functions

func DecodeJSONMarshaler

func DecodeJSONMarshaler(i json.Marshaler) (map[string]interface{}, error)

DecodeJSONMarshaler decode json.Marshaler to map[string]interface

Types

type Appfile

type Appfile struct {
	// contains filtered or unexported fields
}

Appfile describle application

func (*Appfile) Name

func (af *Appfile) Name() string

Name export appfile name

func (*Appfile) Services

func (af *Appfile) Services() []*Workload

Services export Services

func (*Appfile) TemplateValidate

func (af *Appfile) TemplateValidate() error

TemplateValidate validate Template format

type Parser

type Parser struct {
	// contains filtered or unexported fields
}

Parser is appfile parser

func NewParser

func NewParser(handler template.Handler) *Parser

NewParser create appfile parser

func (*Parser) Parse

func (pser *Parser) Parse(name string, expr map[string]interface{}) (*Appfile, error)

Parse convert map to Appfile

type Render

type Render interface {
	// WithContext(ctx interface{}) Render
	WithParams(params interface{}) Render
	WithTemplate(raw string) Render
	Complete() (*cue.Instance, error)
}

Render is cue render

type Trait

type Trait struct {
	// contains filtered or unexported fields
}

Trait is ComponentTrait

func (*Trait) Eval

func (trait *Trait) Eval(render Render) ([]v1alpha2.ComponentTrait, error)

Eval convert template to ComponentTrait

type Workload

type Workload struct {
	// contains filtered or unexported fields
}

Workload is component

func (*Workload) Eval

func (wl *Workload) Eval(render Render) (*v1alpha2.Component, error)

Eval convert template to Component

func (*Workload) Name

func (wl *Workload) Name() string

Name export workload's name

func (*Workload) Traits

func (wl *Workload) Traits() []*Trait

Traits export workload's traits

Jump to

Keyboard shortcuts

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