X-Git-Url: https://git.giacomolli.uk/onechat/blobdiff_plain/723f6e18adc6482ed913e1618c8a76e981720c2b..c781f79f3c8cb9a7577ee1574d196988da2719b3:/routes.go?ds=sidebyside diff --git a/routes.go b/routes.go index 7dce691..6d72898 100644 --- a/routes.go +++ b/routes.go @@ -13,6 +13,16 @@ import ( "go.mau.fi/whatsmeow/types" ) +// Routes owns the root's source map. Writes replace the private file before +// changing the map in memory. The mutex protects reads and writes from tools +// and status commands. Logs omit source IDs, which can hold phone numbers. +type Routes struct { + mutex sync.Mutex + path string + logger *slog.Logger + targets map[string]string +} + // openRoutes reads the source-to-child map. A missing file has no routes. func openRoutes(path string, logger *slog.Logger) (*Routes, error) { r := &Routes{ @@ -20,6 +30,7 @@ func openRoutes(path string, logger *slog.Logger) (*Routes, error) { logger: logger, targets: make(map[string]string), } + data, err := os.ReadFile(path) if errors.Is(err, os.ErrNotExist) { return r, nil @@ -52,16 +63,6 @@ func openRoutes(path string, logger *slog.Logger) (*Routes, error) { return r, nil } -// Routes owns the root's source map. Writes replace the private file before -// changing the map in memory. The mutex protects reads and writes from tools -// and status commands. Logs omit source IDs, which can hold phone numbers. -type Routes struct { - mutex sync.Mutex - path string - logger *slog.Logger - targets map[string]string -} - // Set maps source to a child name, or removes it when target is empty. The // caller checks that a nonempty target is a child of the root. func (r *Routes) Set(source, target string) error {