Skip to content

Commit

Permalink
all: imp code
Browse files Browse the repository at this point in the history
  • Loading branch information
schzhn committed Dec 27, 2024
1 parent d16be8a commit 64cc591
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 19 deletions.
8 changes: 0 additions & 8 deletions internal/cmd/paths_darwin.go

This file was deleted.

8 changes: 0 additions & 8 deletions internal/cmd/paths_others.go

This file was deleted.

2 changes: 1 addition & 1 deletion internal/cmd/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,7 @@ func (conf *configuration) hostsFiles(ctx context.Context, l *slog.Logger) (path
return conf.HostsFiles, nil
}

paths, err = DefaultHostsPaths()
paths, err = proxynetutil.DefaultHostsPaths()
if err != nil {
return nil, fmt.Errorf("getting default hosts files: %w", err)
}
Expand Down
5 changes: 4 additions & 1 deletion internal/cmd/paths.go → internal/netutil/paths.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package cmd
package netutil

// DefaultHostsPaths returns the slice of default paths to system hosts files.
//
// TODO(s.chzhen): Since [fs.FS] is no longer needed, update the
// [hostsfile.DefaultHostsPaths] from golibs.
func DefaultHostsPaths() (paths []string, err error) {
return defaultHostsPaths()
}
21 changes: 21 additions & 0 deletions internal/netutil/paths_unix.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//go:build unix

package netutil

import "github.com/AdguardTeam/golibs/hostsfile"

// defaultHostsPaths returns default paths to hosts files for UNIX.
func defaultHostsPaths() (paths []string, err error) {
paths, err = hostsfile.DefaultHostsPaths()
if err != nil {
// Should not happen because error is always nil.
panic(err)
}

res := make([]string, 0, len(paths))
for _, p := range paths {
res = append(res, "/"+p)
}

return res, nil
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//go:build windows

package cmd
package netutil

import (
"fmt"
Expand Down

0 comments on commit 64cc591

Please sign in to comment.