Skip to content

Commit

Permalink
feats: add 3 functions for filepaths
Browse files Browse the repository at this point in the history
  • Loading branch information
krakozaure committed Jun 14, 2023
1 parent 855df3c commit da87b06
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions funcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ package main

import (
"bytes"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"strconv"
"strings"
"text/template"

"github.com/BurntSushi/toml"
Expand Down Expand Up @@ -33,6 +35,10 @@ func getFuncMap() template.FuncMap {
f["fileSize"] = fileSize
f["isDir"] = isDir
f["isFile"] = isFile
f["joinPath"] = joinPath
f["toBackslash"] = toBackslash
f["toOsPath"] = toOsPath
f["toSlash"] = toSlash

return f
}
Expand Down Expand Up @@ -170,3 +176,23 @@ func isFile(path string) (bool, error) {
}
return info.Mode().IsRegular(), nil
}

func joinPath(segments []any) string {
string_segments := make([]string, 0, len(segments))
for _, v := range segments {
string_segments = append(string_segments, fmt.Sprint(v))
}
return filepath.Join(string_segments...)
}

func toBackslash(path string) string {
return strings.ReplaceAll(path, "/", "\\")
}

func toOsPath(path string) string {
return strings.ReplaceAll(path, "\\", string(filepath.Separator))
}

func toSlash(path string) string {
return strings.ReplaceAll(path, "\\", "/")
}

0 comments on commit da87b06

Please sign in to comment.