go(util): add custom print func
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
621f56f5e3
commit
3401a2e58e
24
util/util.go
24
util/util.go
@ -5,6 +5,7 @@ package util
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
"strings"
|
||||
@ -22,6 +23,8 @@ func CreateFolder(path string) error {
|
||||
var err error
|
||||
|
||||
if _, err = os.Stat(path); errors.Is(err, os.ErrNotExist) {
|
||||
printUtil("creating folder : " + path + " (if not exists)")
|
||||
|
||||
err = os.Mkdir(path, os.ModePerm)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
@ -37,6 +40,8 @@ func CreatePath(path string) error {
|
||||
var err error
|
||||
|
||||
if _, err = os.Stat(path); errors.Is(err, os.ErrNotExist) {
|
||||
printUtil("creating path : " + path + " (if not exists)")
|
||||
|
||||
err = os.MkdirAll(path, os.ModePerm)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
@ -45,3 +50,22 @@ func CreatePath(path string) error {
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
func getUtilLogPrefix() string {
|
||||
return " *** util: "
|
||||
}
|
||||
|
||||
func fmtUtilOut(input string) string {
|
||||
return getUtilLogPrefix() + input
|
||||
}
|
||||
|
||||
func printUtil(input string) {
|
||||
if _, err := fmt.Fprintln(os.Stderr, fmtUtilOut(input)); err != nil {
|
||||
fmt.Fprintf(
|
||||
os.Stdout,
|
||||
getUtilLogPrefix(),
|
||||
"error while printing to stderr: %q\n * original message was: %q",
|
||||
err, input,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user