hyphae

package
v1.14.0 Latest Latest
Warning

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

Go to latest
Published: Apr 7, 2023 License: AGPL-3.0 Imports: 10 Imported by: 0

Documentation

Overview

Package hyphae manages hypha storage and hypha types.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AreFreeNames

func AreFreeNames(hyphaNames ...string) (firstFailure string, ok bool)

AreFreeNames checks if all given `hyphaNames` are not taken. If they are not taken, `ok` is true. If not, `firstFailure` is the name of the first met hypha that is not free.

func Count

func Count() int

Count how many hyphae there are. This is a O(1), the number of hyphae is stored in memory.

func DeleteHypha added in v1.8.2

func DeleteHypha(h ExistingHypha)

DeleteHypha deletes the hypha from the storage.

func FetchMycomarkupFile added in v1.11.0

func FetchMycomarkupFile(h Hypha) (string, error)

FetchMycomarkupFile tries to read text file of the given hypha. If there is no file, empty string is returned.

TODO: Get rid of this function.

func FilterHyphaeWithText added in v1.8.0

func FilterHyphaeWithText(src chan ExistingHypha) chan ExistingHypha

FilterHyphaeWithText filters the source channel and yields only those hyphae than have text parts.

func Index

func Index(path string)

Index finds all hypha files in the full `path` and saves them to the hypha storage.

func Insert added in v1.8.2

func Insert(h ExistingHypha) (madeNewRecord bool)

Insert inserts the hypha into the storage, possibly overwriting the previous hypha with the same name. Count incrementation is done if needed. You cannot insert an empty hypha.

func IsValidName added in v1.6.0

func IsValidName(hyphaName string) bool

IsValidName checks for invalid characters and path traversals.

func PathographicSort added in v1.5.0

func PathographicSort(src chan string) <-chan string

PathographicSort sorts paths inside the source channel, preserving the path tree structure

func RenameHyphaTo added in v1.8.2

func RenameHyphaTo(h ExistingHypha, newName string, replaceName func(string) string)

RenameHyphaTo renames a hypha and renames stored filepaths as needed. The actual files are not moved, move them yourself.

func ResetCount

func ResetCount()

ResetCount sets the value of hyphae count to zero. Use when reloading hyphae.

func WriteToMycoFile added in v1.9.0

func WriteToMycoFile(h ExistingHypha, data []byte) error

func YieldExistingHyphae

func YieldExistingHyphae() chan ExistingHypha

YieldExistingHyphae iterates over all hyphae and yields all existing ones.

Types

type EmptyHypha

type EmptyHypha struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

EmptyHypha is a hypha that does not exist and is not stored anywhere. You get one when querying for a hypha that was not created before.

func (*EmptyHypha) CanonicalName added in v1.8.2

func (e *EmptyHypha) CanonicalName() string

type ExistingHypha added in v1.8.2

type ExistingHypha interface {
	Hypha

	HasTextFile() bool
	TextFilePath() string
}

ExistingHypha is not EmptyHypha. *MediaHypha and *TextualHypha implement this interface.

func Subhyphae added in v1.8.2

func Subhyphae(h Hypha) []ExistingHypha

Subhyphae returns slice of subhyphae.

type Hypha

type Hypha interface {
	sync.Locker

	// CanonicalName returns the canonical name of the hypha.
	//
	//     util.CanonicalName(h.CanonicalName()) == h.CanonicalName()
	CanonicalName() string
}

Hypha is the hypha you know and love.

func ByName

func ByName(hyphaName string) (h Hypha)

ByName returns a hypha by name. It returns an *EmptyHypha if there is no such hypha. This function is the only source of empty hyphae.

type MediaHypha added in v1.8.2

type MediaHypha struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func ExtendEmptyToMedia added in v1.8.2

func ExtendEmptyToMedia(e *EmptyHypha, mediaFilePath string) *MediaHypha

ExtendEmptyToMedia returns a new media hypha with the same name as the given empty hypha. The created hypha is not stored yet.

func ExtendTextualToMedia added in v1.8.2

func ExtendTextualToMedia(t *TextualHypha, mediaFilePath string) *MediaHypha

ExtendTextualToMedia returns a new media hypha with the same name and text file as the given textual hypha. The new hypha is not stored yet.

func (*MediaHypha) CanonicalName added in v1.8.2

func (m *MediaHypha) CanonicalName() string

func (*MediaHypha) HasTextFile added in v1.8.2

func (m *MediaHypha) HasTextFile() bool

func (*MediaHypha) MediaFilePath added in v1.8.2

func (m *MediaHypha) MediaFilePath() string

func (*MediaHypha) SetMediaFilePath added in v1.8.2

func (m *MediaHypha) SetMediaFilePath(newPath string)

func (*MediaHypha) TextFilePath added in v1.8.2

func (m *MediaHypha) TextFilePath() string

type TextualHypha added in v1.8.2

type TextualHypha struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

TextualHypha is a hypha with text, and nothing else. An article, a note, a poem, whatnot.

func ExtendEmptyToTextual added in v1.8.2

func ExtendEmptyToTextual(e *EmptyHypha, mycoFilePath string) *TextualHypha

ExtendEmptyToTextual returns a new textual hypha with the same name as the given empty hypha. The created hypha is not stored yet.

func ShrinkMediaToTextual added in v1.8.2

func ShrinkMediaToTextual(m *MediaHypha) *TextualHypha

func (*TextualHypha) CanonicalName added in v1.8.2

func (t *TextualHypha) CanonicalName() string

func (*TextualHypha) HasTextFile added in v1.8.2

func (t *TextualHypha) HasTextFile() bool

func (*TextualHypha) TextFilePath added in v1.8.2

func (t *TextualHypha) TextFilePath() string

Jump to

Keyboard shortcuts

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