filepath

package
v0.2.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 3, 2021 License: Apache-2.0 Imports: 25 Imported by: 0

Documentation

Overview

Package filepath provides filepath storage related utilities.

Index

Constants

This section is empty.

Variables

View Source
var ErrFileNotExists = fmt.Errorf("file doesn't exist")

ErrFileNotExists means the file doesn't actually exist.

View Source
var ErrNamespaceNotExists = errors.New("namespace does not exist")

ErrNamespaceNotExists means the directory for the namespace doesn't actually exist.

Functions

func NewFilepathREST

func NewFilepathREST(
	fs FS,
	strategy Strategy,
	groupResource schema.GroupResource,
	codec runtime.Codec,
	rootpath string,
	newFunc func() runtime.Object,
	newListFunc func() runtime.Object,
) rest.Storage

NewFilepathREST instantiates a new REST storage.

func NewJSONFilepathStorageProvider

func NewJSONFilepathStorageProvider(obj resource.Object, rootPath string, fs FS, strategy Strategy) builderrest.ResourceHandlerProvider

NewJSONFilepathStorageProvider use local host path as persistent layer storage:

  • For namespaced-scoped resources: the resource will be written under the root-path in the following structure:

    -- (root-path) --- /namespace1/ --- resource1 | | | --- resource2 | --- /namespace2/ --- resource3

  • For cluster-scoped resources, there will be no mid-layer folders for namespaces:

    -- (root-path) --- resource1 | --- resource2 | --- resource3

An example of storing example resource to local filepath will be:

builder.APIServer.
  WithResourceAndHandler(&v1alpha1.ExampleResource{},
        jsonfile.NewJsonFileStorageProvider(&v1alpha1.ExampleResource{}, /*the root file-path*/ "data")).
  Build()

Types

type FS

type FS interface {
	Remove(filepath string) error
	Exists(filepath string) bool
	EnsureDir(dirname string) error
	Write(encoder runtime.Encoder, filepath string, obj runtime.Object) error
	Read(decoder runtime.Decoder, path string, newFunc func() runtime.Object) (runtime.Object, error)
	VisitDir(dirname string, newFunc func() runtime.Object, codec runtime.Decoder, visitFunc func(string, runtime.Object)) error
}

A filesystem interface so we can sub out filesystem-based storage with memory-based storage.

type MemoryFS

type MemoryFS struct {
	// contains filtered or unexported fields
}

An in-memory structure that pretends to be a filesystem, and supports all the storage interfaces that RealFS needs.

func NewMemoryFS

func NewMemoryFS() *MemoryFS

func (*MemoryFS) EnsureDir

func (fs *MemoryFS) EnsureDir(dirname string) error

Create the directory if it does not exist.

func (*MemoryFS) Exists

func (fs *MemoryFS) Exists(p string) bool

Check if the filepath exists.

func (*MemoryFS) Read

func (fs *MemoryFS) Read(decoder runtime.Decoder, p string, newFunc func() runtime.Object) (runtime.Object, error)

Read a copy of the object from our in-memory filesystem.

func (*MemoryFS) Remove

func (fs *MemoryFS) Remove(p string) error

Remove the filepath.

func (*MemoryFS) VisitDir

func (fs *MemoryFS) VisitDir(dirname string, newFunc func() runtime.Object, codec runtime.Decoder, visitFunc func(string, runtime.Object)) error

Walk the directory, reading all objects in it.

func (*MemoryFS) Write

func (fs *MemoryFS) Write(encoder runtime.Encoder, p string, obj runtime.Object) error

Write a copy of the object to our in-memory filesystem.

type RealFS

type RealFS struct {
}

func (RealFS) EnsureDir

func (fs RealFS) EnsureDir(dirname string) error

func (RealFS) Exists

func (fs RealFS) Exists(filepath string) bool

func (RealFS) Read

func (fs RealFS) Read(decoder runtime.Decoder, path string, newFunc func() runtime.Object) (runtime.Object, error)

func (RealFS) Remove

func (fs RealFS) Remove(filepath string) error

func (RealFS) VisitDir

func (fs RealFS) VisitDir(dirname string, newFunc func() runtime.Object, codec runtime.Decoder, visitFunc func(string, runtime.Object)) error

func (RealFS) Write

func (fs RealFS) Write(encoder runtime.Encoder, filepath string, obj runtime.Object) error

type Strategy added in v0.2.1

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL