1
0
mirror of https://github.com/osmarks/mycorrhiza.git synced 2024-12-14 06:10:26 +00:00
mycorrhiza/hyphae/deprecated.go
2022-06-06 17:41:33 +03:00

37 lines
783 B
Go

package hyphae
import (
"errors"
"os"
)
// 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 FetchMycomarkupFile(h Hypha) (string, error) {
switch h := h.(type) {
case *EmptyHypha:
return "", errors.New("empty hyphae have no text")
case *MediaHypha:
if !h.HasTextFile() {
return "", nil
}
text, err := os.ReadFile(h.TextFilePath())
if os.IsNotExist(err) {
return "", nil
} else if err != nil {
return "", err
}
return string(text), nil
case *TextualHypha:
text, err := os.ReadFile(h.TextFilePath())
if os.IsNotExist(err) {
return "", nil
} else if err != nil {
return "", err
}
return string(text), nil
}
panic("unreachable")
}