-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11 from oolong-sh/patrick-dev
refactor/feat: better config handling
- Loading branch information
Showing
8 changed files
with
126 additions
and
87 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package config | ||
|
||
// Sync, editor, plugin configs can use default type values | ||
func defaultConfig() OolongConfig { | ||
return OolongConfig{ | ||
NotesDirPaths: []string{}, | ||
AllowedExtensions: []string{}, | ||
IgnoreDirectories: []string{}, | ||
OpenCommand: []string{}, | ||
LinkerConfig: defaultLinkerConfig(), | ||
GraphConfig: defaultGraphConfig(), | ||
SyncConfig: OolongSyncConfig{}, | ||
PluginsConfig: OolongPluginConfig{}, | ||
} | ||
} | ||
|
||
func defaultLinkerConfig() OolongLinkerConfig { | ||
return OolongLinkerConfig{ | ||
NGramRange: []int{1, 2, 3}, | ||
StopWords: []string{}, | ||
} | ||
} | ||
|
||
func defaultGraphConfig() OolongGraphConfig { | ||
// TEST: these values with new users (setting these dynamically would likely be ideal using some sort of percentages) | ||
return OolongGraphConfig{ | ||
MinNodeWeight: 2.0, | ||
MaxNodeWeight: 10.0, | ||
MinLinkWeight: 0.1, | ||
DefaultMode: "2d", | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package config | ||
|
||
import ( | ||
"errors" | ||
"log" | ||
"path/filepath" | ||
"strings" | ||
"time" | ||
|
||
"github.com/fsnotify/fsnotify" | ||
) | ||
|
||
func initWatcher(configPath string) error { | ||
watcher, err := fsnotify.NewWatcher() | ||
if err != nil { | ||
return err | ||
} | ||
defer watcher.Close() | ||
|
||
if err := watcher.Add(filepath.Dir(configPath)); err != nil { | ||
return err | ||
} | ||
|
||
for { | ||
select { | ||
case event, ok := <-watcher.Events: | ||
if !ok { | ||
log.Println("Watcher event channel returned bad result.") | ||
return errors.New("Invalid watcher errors channel value.") | ||
} | ||
|
||
if !strings.Contains(event.Name, configPath) { | ||
time.Sleep(500) | ||
continue | ||
} else if !event.Has(fsnotify.Write) { | ||
time.Sleep(500) | ||
continue | ||
} | ||
|
||
// write event is sent on write start, wait 500ms for write to finish | ||
time.Sleep(500) | ||
readConfig(configPath) | ||
case err, ok := <-watcher.Errors: | ||
if !ok { | ||
return errors.New("Invalid watcher errors channel value.") | ||
} | ||
log.Println("error:", err) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters