Add MustTempDir (#1069)

This commit is contained in:
anqiansong
2021-09-21 10:13:43 +08:00
committed by GitHub
parent 30e49f2939
commit 9a724fe907
11 changed files with 48 additions and 25 deletions

View File

@@ -4,6 +4,7 @@ import (
"bufio"
"fmt"
"io/ioutil"
"log"
"os"
"path/filepath"
"strings"
@@ -180,3 +181,13 @@ func createTemplate(file, content string, force bool) error {
_, err = f.WriteString(content)
return err
}
// MustTempDir creates a temporary directory
func MustTempDir() string {
dir, err := ioutil.TempDir("", "")
if err != nil {
log.Fatalln(err)
}
return dir
}

View File

@@ -39,7 +39,7 @@ func (s String) Upper() string {
// ReplaceAll calls the strings.ReplaceAll
func (s String) ReplaceAll(old, new string) string {
return strings.ReplaceAll(s.source, old, new)
return strings.Replace(s.source, old, new, -1)
}
// Source returns the source string value