🎉first commit

This commit is contained in:
2024-05-25 20:26:20 +04:00
commit 7a2558b25a
15 changed files with 1183 additions and 0 deletions

60
utils/print.go Normal file
View File

@ -0,0 +1,60 @@
package utils
import (
"fmt"
"os"
)
type colors struct {
reset string
Red string
Green string
Yellow string
Orange string
Blue string
Magenta string
Cyan string
Gray string
White string
}
var Colors = colors{
reset: "\033[0m",
Red: "\033[31m",
Green: "\033[32m",
Yellow: "\033[33m",
Orange: "\033[38;5;208m",
Blue: "\033[34m",
Magenta: "\033[35m",
Cyan: "\033[36m",
Gray: "\033[37m",
White: "\033[97m",
}
func Colored(color string, a ...any) string {
return color + fmt.Sprint(a...) + Colors.reset
}
func PrintfC(color string, format string, a ...any) {
fmt.Printf(Colored(color, format), a...)
}
func PrintlnC(color string, a ...any) {
fmt.Println(Colored(color, a...))
}
func PrintErr(err error) {
PrintlnC(Colors.Red, err.Error())
}
func PrintErrAndExit(err error) {
if err != nil {
PrintErr(err)
os.Exit(0)
}
}
func PrintAndExit(message string) {
fmt.Println(message)
os.Exit(0)
}

18
utils/slice.go Normal file
View File

@ -0,0 +1,18 @@
package utils
func Flatten[T any](nested [][]T) []T {
flattened := make([]T, 0)
for _, n := range nested {
flattened = append(flattened, n...)
}
return flattened
}
func Contains[T comparable](slice []T, item T) bool {
for _, i := range slice {
if i == item {
return true
}
}
return false
}