Documentation
¶
Index ¶
- Constants
- Variables
- func GenInternalTemplates() error
- func GetInternalTemplates() embed.FS
- func GetTemplateDir(subDir string) (string, error)
- func InternalTemplateNameToPath() map[string]string
- func IsTemplateURL(templateNamePathOrURL string) bool
- func ReadTemplate(dir string, fs afero.Fs) error
- func RenderFSTemplate(srcFS afero.Fs, srcDir string, destFS afero.Fs, destDir string, ...) error
- func RenderLocalTemplate(sourceDir, destDir string, force bool, tc *TemplateConfig) error
- func Transfer(srcFS embed.FS) (afero.Fs, error)
- func ValidateProjectName(s string) error
- func WriteToDisk(destFS afero.Fs, root string, force bool) error
- type FieldTemplate
- type FieldType
- type ProjectTemplate
- type StackTemplate
- type Template
- type TemplateConfig
- type TemplateRepository
Constants ¶
const ( // BaseTemplateDir is the name of the directory containing templates. BaseTemplateDir = "templates" // InternalTemplateDir is the name of the directory containing internal templates. InternalTemplateDir = "templates/internal" // ExternalTemplateDir is the name of the directory containing external templates. ExternalTemplateDir = "templates/external" // GitDir is the name of the folder git uses to store information. GitDir = ".git" // KusionYaml is a config file which describe all params of a template KusionYaml = "kusion.yaml" )
Variables ¶
var ( // file flag, create or upate CreateOrUpdate = os.O_WRONLY | os.O_CREATE | os.O_TRUNC // default directory permission, 700 DefaultDirectoryPermission os.FileMode = 0o700 // default file permission, 600 DefaultFilePermission os.FileMode = 0o600 )
var (
// The Git URL for Kusion program templates
KusionTemplateGitRepository = "https://github.com/KusionStack/kusion-templates"
)
These are variables instead of constants in order that they can be set using the `-X` `ldflag` at build time, if necessary.
Functions ¶
func GenInternalTemplates ¶
func GenInternalTemplates() error
GenInternalTemplates save localTemplates(FS) to internal-templates(target directory)
func GetInternalTemplates ¶ added in v0.5.0
Export internal templates which is embed in binary
func GetTemplateDir ¶
GetTemplateDir returns the directory in which templates on the current machine are stored.
func InternalTemplateNameToPath ¶ added in v0.5.0
InternalTemplateNameToPath return a map of template name to path
func IsTemplateURL ¶
IsTemplateURL returns true if templateNamePathOrURL starts with "https://".
func ReadTemplate ¶ added in v0.5.0
Read files' content from local dir into file system
func RenderFSTemplate ¶ added in v0.5.0
func RenderFSTemplate(srcFS afero.Fs, srcDir string, destFS afero.Fs, destDir string, tc *TemplateConfig) error
RenderFSTemplate does the actual copy operation from source FS to destination FS.
func RenderLocalTemplate ¶ added in v0.5.0
func RenderLocalTemplate(sourceDir, destDir string, force bool, tc *TemplateConfig) error
RenderLocalTemplate does the actual copy operation from source directory to a destination directory.
func ValidateProjectName ¶
ValidateProjectName ensures a project name is valid, if it is not it returns an error with a message suitable for display to an end user.
Types ¶
type FieldTemplate ¶
type FieldTemplate struct { // Name represents the field name, required Name string `json:"name,omitempty" yaml:"name,omitempty"` // Description represents the field description, optional Description string `json:"description,omitempty" yaml:"description,omitempty"` // Type can be string/int/bool/float/array/map/struct/any, required Type FieldType `json:"type,omitempty" yaml:"type,omitempty"` // Default represents default value for all FieldType Default interface{} `json:"default,omitempty" yaml:"default,omitempty"` // Elem is effective only when type is ArrayField Elem *FieldTemplate `json:"elem,omitempty" yaml:"elem,omitempty"` // Key is effective only when type is MapField Key *FieldTemplate `json:"key,omitempty" yaml:"key,omitempty"` // Value is effective only when type is MapField Value *FieldTemplate `json:"value,omitempty" yaml:"value,omitempty"` // Fields is effective only when type is StructField Fields []*FieldTemplate `json:"fields,omitempty" yaml:"fields,omitempty"` }
FieldTemplate can describe all kinds of type, including primitive and composite.
func (*FieldTemplate) RestoreActualValue ¶
func (f *FieldTemplate) RestoreActualValue(input string) (actual interface{}, err error)
RestoreActualValue help to transfer input to actual value according to its type
type FieldType ¶
type FieldType string
FieldType includes field type that can be unmarshalled directly
func (FieldType) IsPrimitive ¶
IsPrimitive indicate the give field is one of StringField, IntField, FloatField, BoolField or not
type ProjectTemplate ¶
type ProjectTemplate struct { // ProjectName is a required fully qualified name. ProjectName string `json:"projectName" yaml:"projectName"` // Description is an optional description of the template. Description string `json:"description,omitempty" yaml:"description,omitempty"` // Quickstart contains optional text to be displayed after template creation. Quickstart string `json:"quickstart,omitempty" yaml:"quickstart,omitempty"` // ProjectFields contains configuration in project level ProjectFields []*FieldTemplate `json:"projectFields,omitempty" yaml:"projectFields,omitempty"` // StackTemplates contains configuration in stack level StackTemplates []*StackTemplate `json:"stacks,omitempty" yaml:"stacks,omitempty"` }
ProjectTemplate is a Kusion project template manifest.
func LoadProjectTemplate ¶
func LoadProjectTemplate(path string) (*ProjectTemplate, error)
LoadProjectTemplate reads a project definition from a file.
type StackTemplate ¶
type StackTemplate struct { // Name is stack name Name string `json:"name" yaml:"name"` // Fields contains all stack fields definition Fields []*FieldTemplate `json:"fields,omitempty" yaml:"fields,omitempty"` }
StackTemplates contains configuration in stack level
type Template ¶
type Template struct { Dir string // The directory containing kusion.yaml. Name string // The name of the template. *ProjectTemplate }
Template represents a project template.
func LoadTemplate ¶
LoadTemplate returns a template from a path.
type TemplateConfig ¶ added in v0.4.4
type TemplateConfig struct { // ProjectName is project name, as well as root dir name ProjectName string `json:"projectName"` // ProjectConfig contains configuration in project level ProjectConfig map[string]interface{} `json:"projectConfig,omitempty"` // StacksConfig contains configuration in stack level, can be multi-stack or single-stack StacksConfig map[string]map[string]interface{} `json:"stacksConfig,omitempty"` }
TemplateConfig contains all config items to render the chosen project
type TemplateRepository ¶
type TemplateRepository struct { Root string // The full path to the root directory of the repository. SubDirectory string // The full path to the subdirectory within the repository. ShouldDelete bool // Whether the root directory should be deleted. }
TemplateRepository represents a repository of templates.
func RetrieveTemplates ¶
func RetrieveTemplates(templateNamePathOrURL string, online bool) (TemplateRepository, error)
RetrieveTemplates retrieves a "template repository" based on the specified name, path, or URL.
func (TemplateRepository) Delete ¶
func (repo TemplateRepository) Delete() error
Delete deletes the template repository.
func (TemplateRepository) Templates ¶
func (repo TemplateRepository) Templates() ([]Template, error)
Templates lists the templates in the repository.