diff options
author | Thomas Voss <mail@thomasvoss.com> | 2025-06-14 00:45:04 +0200 |
---|---|---|
committer | Thomas Voss <mail@thomasvoss.com> | 2025-06-14 00:45:04 +0200 |
commit | fe2bae01c6b14eef0e61cd4a6bd50e814de4bb58 (patch) | |
tree | 60fbda65d5fa3a9afc966bce51b6968e966baf4c /src | |
parent | 2d5ca3a6cd507ef29eb13b3a78232264a2817e81 (diff) |
Move some packages to pkg/
Diffstat (limited to 'src')
-rw-r--r-- | src/atexit/atexit.go | 13 | ||||
-rw-r--r-- | src/dbx/db.go | 5 | ||||
-rw-r--r-- | src/http.go | 3 | ||||
-rw-r--r-- | src/templates.go | 5 | ||||
-rw-r--r-- | src/try/try.go | 19 | ||||
-rw-r--r-- | src/watch/watch.go | 41 |
6 files changed, 7 insertions, 79 deletions
diff --git a/src/atexit/atexit.go b/src/atexit/atexit.go deleted file mode 100644 index ed35ccf..0000000 --- a/src/atexit/atexit.go +++ /dev/null @@ -1,13 +0,0 @@ -package atexit - -var hooks = []func(){} - -func Register(f func()) { - hooks = append(hooks, f) -} - -func Exec() { - for i := len(hooks)-1; i >= 0; i-- { - hooks[i]() - } -} diff --git a/src/dbx/db.go b/src/dbx/db.go index e97b9ea..fcb345e 100644 --- a/src/dbx/db.go +++ b/src/dbx/db.go @@ -9,10 +9,9 @@ import ( "sort" "strings" + "git.thomasvoss.com/euro-cash.eu/pkg/atexit" + . "git.thomasvoss.com/euro-cash.eu/pkg/try" "github.com/mattn/go-sqlite3" - - "git.thomasvoss.com/euro-cash.eu/src/atexit" - . "git.thomasvoss.com/euro-cash.eu/src/try" ) var ( diff --git a/src/http.go b/src/http.go index babf7f8..6feb865 100644 --- a/src/http.go +++ b/src/http.go @@ -12,9 +12,10 @@ import ( "strconv" "strings" + . "git.thomasvoss.com/euro-cash.eu/pkg/try" + "git.thomasvoss.com/euro-cash.eu/src/dbx" "git.thomasvoss.com/euro-cash.eu/src/email" - . "git.thomasvoss.com/euro-cash.eu/src/try" ) type middleware = func(http.Handler) http.Handler diff --git a/src/templates.go b/src/templates.go index de1f081..4deeb67 100644 --- a/src/templates.go +++ b/src/templates.go @@ -7,9 +7,10 @@ import ( "log" "strings" + . "git.thomasvoss.com/euro-cash.eu/pkg/try" + "git.thomasvoss.com/euro-cash.eu/pkg/watch" + "git.thomasvoss.com/euro-cash.eu/src/dbx" - . "git.thomasvoss.com/euro-cash.eu/src/try" - "git.thomasvoss.com/euro-cash.eu/src/watch" ) type templateData struct { diff --git a/src/try/try.go b/src/try/try.go deleted file mode 100644 index d2ea27e..0000000 --- a/src/try/try.go +++ /dev/null @@ -1,19 +0,0 @@ -package try - -import ( - "log" - - "git.thomasvoss.com/euro-cash.eu/src/atexit" -) - -func Try(e error) { - if e != nil { - atexit.Exec() - log.Fatalln(e) - } -} - -func Try2[T any](x T, e error) T { - Try(e) - return x -} diff --git a/src/watch/watch.go b/src/watch/watch.go deleted file mode 100644 index 84f9ed9..0000000 --- a/src/watch/watch.go +++ /dev/null @@ -1,41 +0,0 @@ -package watch - -import ( - "errors" - "io/fs" - "log" - "os" - "time" - - . "git.thomasvoss.com/euro-cash.eu/src/try" -) - -func File(path string, f func()) { - impl(path, os.Stat, f) -} - -func FileFS(dir fs.FS, path string, f func()) { - impl(path, func(path string) (os.FileInfo, error) { - return fs.Stat(dir, path) - }, f) -} - -func impl(path string, statfn func(string) (os.FileInfo, error), f func()) { - ostat := Try2(statfn(path)) - - for { - nstat, err := statfn(path) - switch { - case errors.Is(err, os.ErrNotExist): - return - case err != nil: - log.Println(err) - } - - if nstat.ModTime() != ostat.ModTime() { - f() - ostat = nstat - } - time.Sleep(1 * time.Second) - } -} |