cleaning up, early http server draft

This commit is contained in:
2026-01-24 09:39:27 +03:00
parent d52658ab5c
commit cc5c9c6d1a
23 changed files with 123 additions and 0 deletions

47
util/hex_test.go Normal file
View File

@@ -0,0 +1,47 @@
package imageutils
import (
"fmt"
"image/png"
"os"
"path/filepath"
"testing"
)
// Returns path of first occured file
// with png extension in user's home directory.
func firstPNG(root string) (filename string,
err error) {
var fn filepath.WalkFunc = func(path string,
info os.FileInfo,
fileErr error) error {
if fileErr != nil {
return fileErr
}
if !info.IsDir() &&
filepath.Ext(path) == ".png" {
filename = path
return nil
}
return nil
}
err = filepath.Walk(root, fn)
return
}
func TestColorToHex(t *testing.T) {
root := os.Getenv("HOME")
path, err := firstPNG(root)
if err != nil {
t.Fatal(err)
}
f, err := os.Open(path)
if err != nil {
t.Fatal(err)
}
img, err := png.Decode(f)
if err != nil {
t.Fatal(err)
}
fmt.Println(ColorToHex(img.At(0, 0)))
}