mirror of
https://github.com/tailscale/tailscale.git
synced 2026-11-20 08:41:19 -08:00
The filestore was the only implemented store but we want to be able to add other stores depending on the platform. Make space for compiling on more stores, though keep the file store as the default option. Updates #22265 Signed-off-by: Claus Lensbøl <[email protected]>
30 lines
725 B
Go
30 lines
725 B
Go
// Copyright (c) Tailscale Inc & contributors
|
|
// SPDX-License-Identifier: BSD-3-Clause
|
|
|
|
package netmapcache
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"os"
|
|
)
|
|
|
|
// TODO(cmol): Add compiler flags when having more stores
|
|
|
|
// NewStore creates [Store] for backing the netmapcache. If the [Store] already
|
|
// exists, open the existing [Store].
|
|
func NewStore(_ context.Context, dir string) (Store, error) {
|
|
return FileStore(dir), nil
|
|
}
|
|
|
|
// OpenStore opens an existing [Store]. Returns nil, nil, if the store does not
|
|
// exist.
|
|
func OpenStore(_ context.Context, dir string) (Store, error) {
|
|
if _, err := os.Stat(dir); errors.Is(err, os.ErrNotExist) {
|
|
return nil, nil
|
|
} else if err != nil {
|
|
return nil, err
|
|
}
|
|
return FileStore(dir), nil
|
|
}
|