go(util): add custom print func
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
surtur 2022-07-13 23:18:31 +02:00
parent 621f56f5e3
commit 3401a2e58e
Signed by: wanderer
GPG Key ID: 19CE1EC1D9E0486D

@ -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,
)
}
}