embed_source

package
v1.13.0 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const (
	RenderStatusShow = "success"
	RenderStatusHide = "failure"
)

Variables

View Source
var (
	DefaultFunctions = map[string]interface{}{
		"duration":       toDuration,
		"datetime":       toDatetime,
		"success":        isSuccess,
		"failure":        isFailure,
		"truncate":       truncate,
		"urlencode":      urlencode,
		"since":          since,
		"uppercasefirst": uppercaseFirst,
		"uppercase":      strings.ToUpper,
		"lowercase":      strings.ToLower,
		"regexReplace":   regexReplace,
	}
)
View Source
var (
	ErrPathNotFoundFile = errors.New("path not found file")
)
View Source
var (
	ErrorNotSetResourceRootPath = fmt.Errorf("not set resource root path")
)

Functions

func InitResourceByDir

func InitResourceByDir(group string, embFs embed.FS, innerScanPathList []string) error

InitResourceByDir this function only load first folder then bind second file as EmbedResource list

group: resource group, most of the use path of resource folder
embFs: embed.FS some as group package by go:embed
innerScanPath: inner scan path, will use "" will scan group current path

func InitResourceGroupByLanguage

func InitResourceGroupByLanguage(group string, embFs embed.FS, innerScanPath string, langList []string) error

InitResourceGroupByLanguage

group: resource group, most of the use path of resource folder
embFs: embed.FS some as group package by go:embed
innerScanPath: inner scan path, will use "" will scan group current path
langList: lang load list

func RegisterSettings

func RegisterSettings(funcSettings map[string]interface{})

RegisterSettings most of this can use embed_source.RegisterSettings(DefaultFunctions)

func Render

func Render(template string, payload interface{}) (s string, err error)

Render parses and executes a template, returning the results in string format. Trailing or leading spaces or new-lines are not getting truncated. It is able to read templates from remote paths, local files or directly from the string.

func SettingResourceRootPath

func SettingResourceRootPath(root string)

Types

type EmbedResource

type EmbedResource interface {
	IsDir() bool
	RelativePath() string
	Lang() string

	ChangeRootPath(root string) error

	RootPath() string

	FullPath() string

	FileName() string

	Raw() ([]byte, error)

	Data() string

	Render(payload interface{}) (result string, err error)
}

func GetResourceByLanguage

func GetResourceByLanguage(group string, innerPath string, lang string) (EmbedResource, error)

GetResourceByLanguage this method will check lang and parent dir if not found will use default lang with GetResourceByLanguageDefault

group: resource group, most of the use path of resource folder
innerPath: inner path of resource folder
lang: language as i18n

return EmbedResource

func GetResourceByLanguageDefault

func GetResourceByLanguageDefault(group string, innerPath string) (EmbedResource, error)

func GetResourceGroupByDir

func GetResourceGroupByDir(group string, innerScanPath string) ([]EmbedResource, error)

func GetResourceListByLanguage

func GetResourceListByLanguage(group string, innerScanPath string, lang string) ([]EmbedResource, error)

func NewEmbedResourceAsDir

func NewEmbedResourceAsDir(root string, efs embed.FS, pathDir string, lang string, loadNow bool) ([]EmbedResource, error)

NewEmbedResourceAsDir warning: will load file content to memory

loadNow: true will load to memory struct

func NewEmbedResourceAsFile

func NewEmbedResourceAsFile(root string, efs embed.FS, pathFile string, lang string, loadNow bool) (EmbedResource, error)

NewEmbedResourceAsFile warning: will load file content to memory

loadNow: true will load to memory struct

type LanguageResource

type LanguageResource struct {
	Lang      string
	FolderMap map[string]string
}

Jump to

Keyboard shortcuts

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