Skip to content
Snippets Groups Projects
Verified Commit 0fce6c8c authored by Volker Schukai's avatar Volker Schukai :alien:
Browse files

chore: setup project

parent c6db6cac
No related branches found
No related tags found
No related merge requests found
# Default ignored files
/shelf/
/workspace.xml
# Editor-based HTTP Client requests
/httpRequests/
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="accountSettings">
<option name="activeProfile" value="profile:default" />
<option name="activeRegion" value="eu-west-1" />
<option name="recentlyUsedProfiles">
<list>
<option value="profile:default" />
</list>
</option>
<option name="recentlyUsedRegions">
<list>
<option value="eu-west-1" />
</list>
</option>
</component>
</project>
\ No newline at end of file
<component name="libraryTable">
<library name="fs">
<CLASSES>
<root url="jar://$PROJECT_DIR$/.devenv/profile/share/go/src/html/template/testdata/fs.zip!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</component>
\ No newline at end of file
<component name="libraryTable">
<library name="testdata">
<CLASSES>
<root url="jar://$PROJECT_DIR$/.devenv/profile/share/go/src/archive/zip/testdata/time-22738.zip!/" />
<root url="jar://$PROJECT_DIR$/.devenv/profile/share/go/src/archive/zip/testdata/crc32-not-streamed.zip!/" />
<root url="jar://$PROJECT_DIR$/.devenv/profile/share/go/src/archive/zip/testdata/time-win7.zip!/" />
<root url="jar://$PROJECT_DIR$/.devenv/profile/share/go/src/archive/zip/testdata/test-trailing-junk.zip!/" />
<root url="jar://$PROJECT_DIR$/.devenv/profile/share/go/src/archive/zip/testdata/readme.zip!/" />
<root url="jar://$PROJECT_DIR$/.devenv/profile/share/go/src/archive/zip/testdata/zip64.zip!/" />
<root url="jar://$PROJECT_DIR$/.devenv/profile/share/go/src/archive/zip/testdata/utf8-winzip.zip!/" />
<root url="jar://$PROJECT_DIR$/.devenv/profile/share/go/src/archive/zip/testdata/time-7zip.zip!/" />
<root url="jar://$PROJECT_DIR$/.devenv/profile/share/go/src/archive/zip/testdata/winxp.zip!/" />
<root url="jar://$PROJECT_DIR$/.devenv/profile/share/go/src/archive/zip/testdata/utf8-infozip.zip!/" />
<root url="jar://$PROJECT_DIR$/.devenv/profile/share/go/src/archive/zip/testdata/time-osx.zip!/" />
<root url="jar://$PROJECT_DIR$/.devenv/profile/share/go/src/archive/zip/testdata/test.zip!/" />
<root url="jar://$PROJECT_DIR$/.devenv/profile/share/go/src/archive/zip/testdata/time-infozip.zip!/" />
<root url="jar://$PROJECT_DIR$/.devenv/profile/share/go/src/archive/zip/testdata/time-go.zip!/" />
<root url="jar://$PROJECT_DIR$/.devenv/profile/share/go/src/archive/zip/testdata/utf8-osx.zip!/" />
<root url="jar://$PROJECT_DIR$/.devenv/profile/share/go/src/archive/zip/testdata/zip64-2.zip!/" />
<root url="jar://$PROJECT_DIR$/.devenv/profile/share/go/src/archive/zip/testdata/test-prefix.zip!/" />
<root url="jar://$PROJECT_DIR$/.devenv/profile/share/go/src/archive/zip/testdata/dupdir.zip!/" />
<root url="jar://$PROJECT_DIR$/.devenv/profile/share/go/src/archive/zip/testdata/go-with-datadesc-sig.zip!/" />
<root url="jar://$PROJECT_DIR$/.devenv/profile/share/go/src/archive/zip/testdata/unix.zip!/" />
<root url="jar://$PROJECT_DIR$/.devenv/profile/share/go/src/archive/zip/testdata/utf8-winrar.zip!/" />
<root url="jar://$PROJECT_DIR$/.devenv/profile/share/go/src/archive/zip/testdata/utf8-7zip.zip!/" />
<root url="jar://$PROJECT_DIR$/.devenv/profile/share/go/src/archive/zip/testdata/dd.zip!/" />
<root url="jar://$PROJECT_DIR$/.devenv/profile/share/go/src/archive/zip/testdata/symlink.zip!/" />
<root url="jar://$PROJECT_DIR$/.devenv/profile/share/go/src/archive/zip/testdata/time-winzip.zip!/" />
<root url="jar://$PROJECT_DIR$/.devenv/profile/share/go/src/archive/zip/testdata/time-winrar.zip!/" />
<root url="jar://$PROJECT_DIR$/.devenv/profile/share/go/src/archive/zip/testdata/subdir.zip!/" />
<root url="jar://$PROJECT_DIR$/.devenv/profile/share/go/src/archive/zip/testdata/test-baddirsz.zip!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</component>
\ No newline at end of file
<component name="libraryTable">
<library name="zoneinfo">
<CLASSES>
<root url="jar://$PROJECT_DIR$/.devenv/profile/share/go/lib/time/zoneinfo.zip!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</component>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="MarkdownSettings">
<enabledExtensions>
<entry key="MermaidLanguageExtension" value="false" />
<entry key="PlantUMLLanguageExtension" value="true" />
</enabledExtensions>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/watch.iml" filepath="$PROJECT_DIR$/.idea/watch.iml" />
</modules>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="" vcs="Git" />
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="Go" enabled="true" />
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
\ No newline at end of file
module gitlab.schukai.com/oss/libraries/go/utilities/watch
go 1.20
require (
golang.org/x/sys v0.12.0 // indirect
gopkg.in/fsnotify.v1 v1.6.0
)
watch.go 0 → 100644
package watch
import (
"gopkg.in/fsnotify.v1"
"sync"
)
type WatchEvent int
const (
FileChanged WatchEvent = iota
FileAdded
FileDeleted
FileRemoved
)
type EventHandler func(string, WatchEvent)
type Watch struct {
watcher *fsnotify.Watcher
handlers map[string]EventHandler
queue chan string
mu sync.Mutex
}
func NewWatch() (*Watch, error) {
w, err := fsnotify.NewWatcher()
if err != nil {
return nil, err
}
return &Watch{
watcher: w,
handlers: make(map[string]EventHandler),
queue: make(chan string, 100),
}, nil
}
func (w *Watch) Add(path string, handler EventHandler) error {
w.mu.Lock()
defer w.mu.Unlock()
w.handlers[path] = handler
return w.watcher.Add(path)
}
func (w *Watch) Remove(path string) error {
w.mu.Lock()
defer w.mu.Unlock()
delete(w.handlers, path)
return w.watcher.Remove(path)
}
func (w *Watch) startWorker(concurrency int) {
for i := 0; i < concurrency; i++ {
go func() {
for path := range w.queue {
if handler, exists := w.handlers[path]; exists {
handler(path, FileChanged)
}
}
}()
}
}
func (w *Watch) Watch(concurrency int) {
w.startWorker(concurrency)
for {
select {
case event := <-w.watcher.Events:
if handler, exists := w.handlers[event.Name]; exists {
we := FileChanged // Map fsnotify events to WatchEvent here
w.queue <- event.Name
handler(event.Name, we)
}
case err := <-w.watcher.Errors:
// Handle errors
println("Error:", err)
}
}
}
func (w *Watch) Stop() {
close(w.queue)
w.watcher.Close()
}
package watch
import (
"io/ioutil"
"os"
"testing"
"time"
)
func TestWatch(t *testing.T) {
w, err := NewWatch()
if err != nil {
t.Fatal(err)
}
tmpFile, err := ioutil.TempFile("", "watch_test")
if err != nil {
t.Fatal(err)
}
defer os.Remove(tmpFile.Name())
called := make(chan bool)
handler := func(path string, event WatchEvent) {
if path == tmpFile.Name() && event == FileChanged {
called <- true
}
}
if err := w.Add(tmpFile.Name(), handler); err != nil {
t.Fatal(err)
}
go w.Watch(1)
defer w.Stop()
_, err = tmpFile.WriteString("test")
if err != nil {
t.Fatal(err)
}
select {
case <-called:
// Success
case <-time.After(time.Second * 2):
t.Fatal("Event handler not called")
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment