Documentation ¶
Index ¶
- Constants
- Variables
- func InitResourceByDir(group string, embFs embed.FS, innerScanPathList []string) error
- func InitResourceGroupByLanguage(group string, embFs embed.FS, innerScanPath string, langList []string) error
- func RegisterSettings(funcSettings map[string]interface{})
- func SettingResourceRootPath(root string)
- type EmbedResource
- func GetResourceByLanguage(group string, innerPath string, lang string) (EmbedResource, error)
- func GetResourceByLanguageDefault(group string, innerPath string) (EmbedResource, error)
- func GetResourceGroupByDir(group string, innerScanPath string) ([]EmbedResource, error)
- func GetResourceListByLanguage(group string, innerScanPath string, lang string) ([]EmbedResource, error)
- func NewEmbedResourceAsDir(root string, efs embed.FS, pathDir string, lang string, loadNow bool) ([]EmbedResource, error)
- func NewEmbedResourceAsFile(root string, efs embed.FS, pathFile string, lang string, loadNow bool) (EmbedResource, error)
- type LanguageResource
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 ¶
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 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 ¶
Click to show internal directories.
Click to hide internal directories.