mirror of
https://github.com/gohugoio/hugo.git
synced 2025-09-01 22:42:45 +02:00
@@ -26,7 +26,7 @@ func init() {
|
||||
|
||||
ns := &internal.TemplateFuncsNamespace{
|
||||
Name: name,
|
||||
Context: func(args ...interface{}) (interface{}, error) { return ctx, nil },
|
||||
Context: func(args ...any) (any, error) { return ctx, nil },
|
||||
}
|
||||
|
||||
ns.AddMethodMapping(ctx.Getenv,
|
||||
|
10
tpl/os/os.go
10
tpl/os/os.go
@@ -53,7 +53,7 @@ type Namespace struct {
|
||||
|
||||
// Getenv retrieves the value of the environment variable named by the key.
|
||||
// It returns the value, which will be empty if the variable is not present.
|
||||
func (ns *Namespace) Getenv(key interface{}) (string, error) {
|
||||
func (ns *Namespace) Getenv(key any) (string, error) {
|
||||
skey, err := cast.ToStringE(key)
|
||||
if err != nil {
|
||||
return "", nil
|
||||
@@ -85,7 +85,7 @@ func readFile(fs afero.Fs, filename string) (string, error) {
|
||||
// ReadFile reads the file named by filename relative to the configured WorkingDir.
|
||||
// It returns the contents as a string.
|
||||
// There is an upper size limit set at 1 megabytes.
|
||||
func (ns *Namespace) ReadFile(i interface{}) (string, error) {
|
||||
func (ns *Namespace) ReadFile(i any) (string, error) {
|
||||
s, err := cast.ToStringE(i)
|
||||
if err != nil {
|
||||
return "", err
|
||||
@@ -99,7 +99,7 @@ func (ns *Namespace) ReadFile(i interface{}) (string, error) {
|
||||
}
|
||||
|
||||
// ReadDir lists the directory contents relative to the configured WorkingDir.
|
||||
func (ns *Namespace) ReadDir(i interface{}) ([]_os.FileInfo, error) {
|
||||
func (ns *Namespace) ReadDir(i any) ([]_os.FileInfo, error) {
|
||||
path, err := cast.ToStringE(i)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -114,7 +114,7 @@ func (ns *Namespace) ReadDir(i interface{}) ([]_os.FileInfo, error) {
|
||||
}
|
||||
|
||||
// FileExists checks whether a file exists under the given path.
|
||||
func (ns *Namespace) FileExists(i interface{}) (bool, error) {
|
||||
func (ns *Namespace) FileExists(i any) (bool, error) {
|
||||
path, err := cast.ToStringE(i)
|
||||
if err != nil {
|
||||
return false, err
|
||||
@@ -133,7 +133,7 @@ func (ns *Namespace) FileExists(i interface{}) (bool, error) {
|
||||
}
|
||||
|
||||
// Stat returns the os.FileInfo structure describing file.
|
||||
func (ns *Namespace) Stat(i interface{}) (_os.FileInfo, error) {
|
||||
func (ns *Namespace) Stat(i any) (_os.FileInfo, error) {
|
||||
path, err := cast.ToStringE(i)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@@ -34,7 +34,7 @@ func TestReadFile(t *testing.T) {
|
||||
|
||||
for _, test := range []struct {
|
||||
filename string
|
||||
expect interface{}
|
||||
expect any
|
||||
}{
|
||||
{filepath.FromSlash("/f/f1.txt"), "f1-content"},
|
||||
{filepath.FromSlash("f/f1.txt"), "f1-content"},
|
||||
@@ -64,7 +64,7 @@ func TestFileExists(t *testing.T) {
|
||||
|
||||
for _, test := range []struct {
|
||||
filename string
|
||||
expect interface{}
|
||||
expect any
|
||||
}{
|
||||
{filepath.FromSlash("/f/f1.txt"), true},
|
||||
{filepath.FromSlash("f/f1.txt"), true},
|
||||
@@ -91,7 +91,7 @@ func TestStat(t *testing.T) {
|
||||
|
||||
for _, test := range []struct {
|
||||
filename string
|
||||
expect interface{}
|
||||
expect any
|
||||
}{
|
||||
{filepath.FromSlash("/f/f1.txt"), int64(10)},
|
||||
{filepath.FromSlash("f/f1.txt"), int64(10)},
|
||||
|
Reference in New Issue
Block a user