upadted to 1.24.0; fixed stb and spiddped doubles in precene

This commit is contained in:
2025-03-03 09:28:41 +02:00
parent 0ecf0ddec1
commit 203f834f65
41 changed files with 1058 additions and 219 deletions

19
helper/sugar/console.go Normal file
View File

@@ -0,0 +1,19 @@
package sugar
import (
"fmt"
"github.com/logrusorgru/aurora/v4"
)
func LogSuccess(msg string) {
fmt.Printf("%s: %s\n", aurora.Green("SUCCESS"), aurora.Yellow(msg))
}
func LogError(msg string) {
fmt.Printf("%s: %s\n", aurora.Red("ERROR"), aurora.White(msg))
}
func LogWarning(msg string) {
fmt.Printf("%s: %s\n", aurora.Magenta("WARNING"), aurora.White(msg))
}

11
helper/sugar/env.go Normal file
View File

@@ -0,0 +1,11 @@
package sugar
import (
"github.com/spf13/viper"
"git.amok.space/yevhen/resource-scraper/types/constant"
)
func IsDev() bool {
return viper.GetString(constant.FlagEnv) == constant.DefaultEnvDev
}

63
helper/sugar/fs.go Normal file
View File

@@ -0,0 +1,63 @@
package sugar
import (
"fmt"
"log/slog"
"os"
"path/filepath"
"strconv"
)
func EnsureDir(dirPath ...string) (string, error) {
outPath := filepath.Join(dirPath...)
if len(outPath) < 3 {
return "", fmt.Errorf("the path is short to be a folder: %s", outPath)
}
if _, err := os.Stat(outPath); os.IsNotExist(err) {
var dirMod uint64
if dirMod, err = strconv.ParseUint("0775", 8, 32); err == nil {
err = os.Mkdir(outPath, os.FileMode(dirMod))
}
if err != nil && !os.IsExist(err) {
slog.Error("error creating tmp dir", "err", err)
}
}
return outPath, nil
}
func WriteDataToTmpFile(content, fp string) (int, string, error) {
dir, err := EnsureDir(os.TempDir(), "mdb")
if err != nil {
slog.Error("EnsureDir", "err", err.Error())
return 0, dir, err
}
fp = filepath.Join(dir, fp)
f, err := os.Create(fp)
if err != nil {
slog.Error("CreateFile", "e", err)
return 0, fp, err
}
filesize, err := f.WriteString(content)
if err != nil {
slog.Error("WriteString", "e", err)
return 0, fp, err
}
err = f.Close()
if err != nil {
slog.Error("CloseFile", "e", err)
return 0, fp, err
}
return filesize, fp, nil
}
/*
REMOVED_FROM_MMT_DUE_TO_REDOING_OF_THE_EVENT_LOG
*/

8
helper/sugar/string.go Normal file
View File

@@ -0,0 +1,8 @@
package sugar
import "regexp"
// SqueezeLine remove extra spaces and line breaks from a string
func SqueezeLine(line string) string {
return regexp.MustCompile(`(?m)[\n\r\t\s]+`).ReplaceAllString(line, " ")
}