resource

package
v0.0.0-...-04ccfb0 Latest Latest
Warning

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

Go to latest
Published: May 3, 2024 License: Apache-2.0 Imports: 9 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultRegistry = &Registry{}
View Source
var ErrResourceNotFound = apierrors.NotFound.WithReason("ResourceNotFound").
	New("specified resource is not configured")

Functions

func ReadLocation

func ReadLocation(location Location) ([]byte, error)

Types

type AppFile

type AppFile struct {
	Path string
}

func (AppFile) AppFilePath

func (v AppFile) AppFilePath() string

type AppFileView

type AppFileView interface {
	View
	AppFilePath() string
}

AppFileView is an view on the resources at specific path in the App FS. Since the path is specific, so the view is single-locale.

type DescriptedPath

type DescriptedPath struct {
	Descriptor Descriptor
	Path       string
}

type Descriptor

type Descriptor interface {
	MatchResource(path string) (*Match, bool)
	FindResources(fs Fs) ([]Location, error)
	ViewResources(resources []ResourceFile, view View) (interface{}, error)
	UpdateResource(ctx context.Context, resourcesInAllFss []ResourceFile, resourceInTargetFs *ResourceFile, data []byte) (*ResourceFile, error)
}

func RegisterResource

func RegisterResource(desc Descriptor) Descriptor

type EffectiveFile

type EffectiveFile struct {
	Path string
}

func (EffectiveFile) EffectiveFilePath

func (v EffectiveFile) EffectiveFilePath() string

type EffectiveFileView

type EffectiveFileView interface {
	View
	EffectiveFilePath() string
}

EffectiveFileView is an view on the resources at specific path in all FSs. Since the path is specific, so the view is single-locale.

type EffectiveResource

type EffectiveResource struct {
	SupportedTags []string
	DefaultTag    string
	PreferredTags []string
}

func (EffectiveResource) DefaultLanguageTag

func (v EffectiveResource) DefaultLanguageTag() string

func (EffectiveResource) PreferredLanguageTags

func (v EffectiveResource) PreferredLanguageTags() []string

func (EffectiveResource) SupportedLanguageTags

func (v EffectiveResource) SupportedLanguageTags() []string

type EffectiveResourceView

type EffectiveResourceView interface {
	View
	SupportedLanguageTags() []string
	DefaultLanguageTag() string
	PreferredLanguageTags() []string
}

EffectiveResourceView is an view on the resources in all FSs. Since there is no path, the view is locale-resolved.

type File

type File interface {
	io.Closer
	io.Reader
	io.ReaderAt
	io.Seeker

	Name() string
	Stat() (os.FileInfo, error)
	// Readdir does not follow symlinks, use Readdirnames instead to avoid surprises.
	Readdir(count int) ([]os.FileInfo, error)
	Readdirnames(n int) ([]string, error)
}

type Fs

type Fs interface {
	Open(name string) (File, error)
	Stat(name string) (os.FileInfo, error)
	GetFsLevel() FsLevel
}

type FsLevel

type FsLevel int
const (
	FsLevelBuiltin FsLevel = iota + 1
	FsLevelCustom
	FsLevelApp
)

type LeveledAferoFs

type LeveledAferoFs struct {
	Fs      afero.Fs
	FsLevel FsLevel
}

func (LeveledAferoFs) GetFsLevel

func (f LeveledAferoFs) GetFsLevel() FsLevel

func (LeveledAferoFs) Open

func (f LeveledAferoFs) Open(name string) (File, error)

func (LeveledAferoFs) Stat

func (f LeveledAferoFs) Stat(name string) (os.FileInfo, error)

type Location

type Location struct {
	Fs   Fs
	Path string
}

func EnumerateAllLocations

func EnumerateAllLocations(fs Fs) ([]Location, error)

type Manager

type Manager struct {
	Registry *Registry
	Fs       []Fs
}

func NewManager

func NewManager(registry *Registry, fs []Fs) *Manager

func NewManagerWithDir

func NewManagerWithDir(registry *Registry, builtinResourceDir string, customResourceDir string) *Manager

func (*Manager) Filesystems

func (m *Manager) Filesystems() []Fs

func (*Manager) Overlay

func (m *Manager) Overlay(fs Fs) *Manager

func (*Manager) Read

func (m *Manager) Read(desc Descriptor, view View) (interface{}, error)

func (*Manager) Resolve

func (m *Manager) Resolve(path string) (Descriptor, bool)

type Match

type Match struct {
	LanguageTag string
}

type NewlineJoinedDescriptor

type NewlineJoinedDescriptor struct {
	Path  string
	Parse func([]byte) (interface{}, error)
}

func (NewlineJoinedDescriptor) FindResources

func (d NewlineJoinedDescriptor) FindResources(fs Fs) ([]Location, error)

func (NewlineJoinedDescriptor) MatchResource

func (d NewlineJoinedDescriptor) MatchResource(path string) (*Match, bool)

func (NewlineJoinedDescriptor) UpdateResource

func (d NewlineJoinedDescriptor) UpdateResource(_ context.Context, _ []ResourceFile, resource *ResourceFile, data []byte) (*ResourceFile, error)

func (NewlineJoinedDescriptor) ViewResources

func (d NewlineJoinedDescriptor) ViewResources(resources []ResourceFile, rawView View) (interface{}, error)

type Registry

type Registry struct {
	Descriptors []Descriptor
}

func (*Registry) Clone

func (r *Registry) Clone() *Registry

func (*Registry) Register

func (r *Registry) Register(desc Descriptor) Descriptor

type ResourceFile

type ResourceFile struct {
	Location Location
	Data     []byte
}

nolint: golint

type SimpleDescriptor

type SimpleDescriptor struct {
	Path string
}

SimpleDescriptor does not support view.

func (SimpleDescriptor) FindResources

func (d SimpleDescriptor) FindResources(fs Fs) ([]Location, error)

func (SimpleDescriptor) MatchResource

func (d SimpleDescriptor) MatchResource(path string) (*Match, bool)

func (SimpleDescriptor) UpdateResource

func (d SimpleDescriptor) UpdateResource(_ context.Context, _ []ResourceFile, resource *ResourceFile, data []byte) (*ResourceFile, error)

func (SimpleDescriptor) ViewResources

func (d SimpleDescriptor) ViewResources(resources []ResourceFile, rawView View) (interface{}, error)

type ValidateResource

type ValidateResource struct{}

type ValidateResourceView

type ValidateResourceView interface {
	View
	// contains filtered or unexported methods
}

ValidateResourceView validates the resource itself.

type View

type View interface {
	// contains filtered or unexported methods
}

View is an specific view on the resources described by an Descriptor.

Views are defined within this package only, while descriptor is meant to be defined outside this package. Therefore, when a new descriptor is being introduced, the author has to think about what views the descriptor supports.

Most descriptors only support a subset of all defined views.

Some resources has language tag in their path.

View |- AppFileView |- EffectiveFileView |- EffectiveResourceView |- ValidateResourceView

Jump to

Keyboard shortcuts

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