templates

package
v1.3.1 Latest Latest
Warning

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

Go to latest
Published: Jan 30, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Add

func Add(a, b int) int

func AddImportRegex

func AddImportRegex(regex string, path string, alias string) error

AddImportRegex add a new import regex and path to the importRegexMap it will auto import the package in the template if alias is not empty, it will use the alias as the import alias like import command "github.com/light-speak/lighthouse/command"

func Div

func Div(a, b int) int

func Mul

func Mul(a, b int) int

func Render

func Render(options *Options) error

func Sub

func Sub(a, b int) int

func UserCodeEnd

func UserCodeEnd(action string) string

func UserCodeSection

func UserCodeSection() string

func UserCodeStart

func UserCodeStart(action string) string

Types

type Import

type Import struct {
	Path  string
	Alias string
}

type Options

type Options struct {
	// Path is the path to the file
	// for example, if the Path is "cmd/cli/generate/cmd", the file will be created in the "cmd/cli/generate/cmd" directory
	Path     string
	Template string
	FileName string
	// if Package is not empty, the package name will be added to the file
	// for example, if the Package is "main", the package name will be "package main"
	// if the Package is "", it will automatically get the package name from the path
	Package string
	Data    any

	// The editable notice will be like:
	// # Code generated by github.com/light-speak/lighthouse, YOU CAN FUCKING EDIT BY YOURSELF.
	// otherwise, it will add the non-editable notice to the file
	// The non-editable notice will be like:
	// # Code generated by github.com/light-speak/lighthouse, DO NOT EDIT.
	Editable bool

	// if FileExt is not empty, the file will be created with the file extension
	// for example, if the FileExt is "go", the file will be created with the .go extension
	// if the FileExt is "", the file will be created without any extension
	FileExt string

	// if SkipIfExists is true, the file will not be created if the file already exists
	// otherwise, the file will be merged with the user code sections
	// the user code sections defined in the template with the comment:
	// # Func:xxx user code start / end. Do not remove this comment.
	// # Section: user code section start / end. Do not remove this comment.
	SkipIfExists bool

	// if SkipImport is true, the import section will not be added to the file
	SkipImport bool

	Imports []*Import

	Funcs template.FuncMap
}

Jump to

Keyboard shortcuts

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