Skip to content

Commit

Permalink
fix: linting errors
Browse files Browse the repository at this point in the history
  • Loading branch information
luissimas committed Jun 20, 2024
1 parent 0efff43 commit bfe303e
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 6 deletions.
5 changes: 5 additions & 0 deletions internal/collector/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ func (c *Collector) collectMetrics(root fs.FS) (metrics.Metrics, error) {
notes := make(map[string]metrics.NoteMetrics)

err := fs.WalkDir(root, ".", func(path string, dir fs.DirEntry, err error) error {
if err != nil {
slog.Error("Error on path. Will not enter it", slog.Any("error", err), slog.String("path", path))
return nil
}

// Skip ignored files or directories
if slices.Contains(c.config.IgnorePatterns, filepath.Base(path)) {
if dir.IsDir() {
Expand Down
5 changes: 4 additions & 1 deletion internal/collector/note.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func collectLinks(content []byte) map[string]int {
reader := text.NewReader(content)
root := md.Parser().Parse(reader)
links := make(map[string]int)
ast.Walk(root, func(n ast.Node, entering bool) (ast.WalkStatus, error) {
err := ast.Walk(root, func(n ast.Node, entering bool) (ast.WalkStatus, error) {
if entering && slices.Contains(linkKinds, n.Kind()) {
var target string
switch v := n.(type) {
Expand All @@ -55,6 +55,9 @@ func collectLinks(content []byte) map[string]int {
}
return ast.WalkContinue, nil
})
if err != nil {
slog.Error("Error walking note AST", slog.Any("error", err))
}
slog.Debug("Collected links", slog.Any("links", links))
return links
}
17 changes: 13 additions & 4 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (

type Config struct {
ZettelkastenDirectory string `koanf:"zettelkasten_directory" validate:"requiredWithout:ZettelkastenGitURL"`
ZettelkastenGitURL string `koanf:"zettelkasten_git_url" validate:"requiredWithout:ZettelkastenDirectory" validate:"url/isURL"`
ZettelkastenGitURL string `koanf:"zettelkasten_git_url" validate:"requiredWithout:ZettelkastenDirectory|url"`
ZettelkastenGitBranch string `koanf:"zettelkasten_git_branch"`
ZettelkastenGitToken string `koanf:"zettelkasten_git_token"`
LogLevel slog.Level `koanf:"log_level"`
Expand All @@ -32,16 +32,19 @@ func LoadConfig() (Config, error) {
k := koanf.New(".")

// Set default values
k.Load(structs.Provider(Config{
err := k.Load(structs.Provider(Config{
LogLevel: slog.LevelInfo,
IgnoreFiles: []string{".git", ".obsidian", ".trash", "README.md"},
ZettelkastenGitBranch: "main",
CollectionInterval: time.Minute * 5,
CollectHistoricalMetrics: true,
}, "koanf"), nil)
if err != nil {
return Config{}, fmt.Errorf("error loading default config values: %w", err)
}

// Load env variables
k.Load(env.ProviderWithValue("", ".", func(key, value string) (string, interface{}) {
err = k.Load(env.ProviderWithValue("", ".", func(key, value string) (string, interface{}) {
key = strings.ToLower(key)
if key == "collection_interval" {
parsedValue, err := parseCollectionInterval(value)
Expand All @@ -53,10 +56,16 @@ func LoadConfig() (Config, error) {
}
return key, value
}), nil)
if err != nil {
return Config{}, fmt.Errorf("error loading env variables: %w", err)
}

// Unmarshal into config struct
var cfg Config
k.Unmarshal("", &cfg)
err = k.Unmarshal("", &cfg)
if err != nil {
return Config{}, fmt.Errorf("error unmarshalling config: %w", err)
}

// Validate config
v := validate.Struct(cfg)
Expand Down
2 changes: 1 addition & 1 deletion internal/zettelkasten/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ func (g GitZettelkasten) WalkHistory(walkFunc WalkFunc) error {
return nil
})
err = w.Reset(&git.ResetOptions{
Commit: *&originalHash,
Commit: originalHash,
Mode: git.HardReset,
})
if err != nil {
Expand Down

0 comments on commit bfe303e

Please sign in to comment.