Files
huangguo_server/generate/common/helper.go
T
rootandClaude Opus 5 8679200f41 Initial commit
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-15 13:57:10 +08:00

53 lines
865 B
Go

package common
import (
"fmt"
"os"
"path/filepath"
"strings"
)
// EnsurePath 创建目标目录
func EnsurePath(p string) error {
s, err := os.Stat(p)
if err != nil || !s.IsDir() {
return os.MkdirAll(p, 0755)
}
return nil
}
// TplReplace 模板变量替换
func TplReplace(content string, val map[string]string) string {
for k, v := range val {
content = strings.ReplaceAll(content, "{{"+k+"}}", v)
}
return content
}
func log(msg, level string) {
fmt.Printf("[%s] %s \n", level, msg)
}
// FirstUpper 字符串首字母大写
func FirstUpper(s string) string {
if s == "" {
return ""
}
return strings.ToUpper(s[:1]) + s[1:]
}
// FirstLower 字符串首字母小写
func FirstLower(s string) string {
if s == "" {
return ""
}
return strings.ToLower(s[:1]) + s[1:]
}
func RootPath() string {
p, _ := filepath.Abs("./")
return p
}