hyphae

package
v1.15.1 Latest Latest
Warning

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

Go to latest
Published: Oct 5, 2024 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

func DeleteHypha(h ExistingHypha)

DeleteHypha deletes the hypha from the storage.

func FetchMycomarkupFile

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

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

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

func IsValidName(hyphaName string) bool

IsValidName checks for invalid characters and path traversals.

func PathographicSort

func PathographicSort(src chan string) <-chan string

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

func RenameHyphaTo

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

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

func (e *EmptyHypha) CanonicalName() string

type ExistingHypha

type ExistingHypha interface {
	Hypha

	HasTextFile() bool
	TextFilePath() string
}

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

func Subhyphae

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

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

func ExtendEmptyToMedia

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

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

func (m *MediaHypha) CanonicalName() string

func (*MediaHypha) HasTextFile

func (m *MediaHypha) HasTextFile() bool

func (*MediaHypha) MediaFilePath

func (m *MediaHypha) MediaFilePath() string

func (*MediaHypha) SetMediaFilePath

func (m *MediaHypha) SetMediaFilePath(newPath string)

func (*MediaHypha) TextFilePath

func (m *MediaHypha) TextFilePath() string

type TextualHypha

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

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

func ShrinkMediaToTextual(m *MediaHypha) *TextualHypha

func (*TextualHypha) CanonicalName

func (t *TextualHypha) CanonicalName() string

func (*TextualHypha) HasTextFile

func (t *TextualHypha) HasTextFile() bool

func (*TextualHypha) TextFilePath

func (t *TextualHypha) TextFilePath() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
JackTT - Gopher 🇻🇳