fse

package
v0.0.0-...-3f54671 Latest Latest
Warning

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

Go to latest
Published: Dec 12, 2022 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Examples

Constants

View Source
const (
	// Scheme - file system entry
	Scheme    = "fse"
	ErrorText = "error.txt"
	ErrText   = "err.txt"
)

Variables

This section is empty.

Functions

func ContextWithContent

func ContextWithContent(ctx context.Context, fs fs.FS, name string) context.Context

ContextWithContent - creates a new Context with content

func ParseBuffer

func ParseBuffer(buf []byte) (map[string]string, error)

func ParseLine

func ParseLine(line string) (string, string, error)

func ProcessContent

func ProcessContent[T any](ctx context.Context) (T, error)

ProcessContent - process content

Example
ctx := ContextWithContent(nil, fsys, "resource/error/test-name-eRr.txt")
_, err := ProcessContent[CustomerHistory](ctx)
fmt.Printf("Error : %v\n", err)

ctx = ContextWithContent(nil, fsys, "resource/json/event.json")
cust, err0 := ProcessContent[CustomerHistory](ctx)
fmt.Printf("Error : %v\n", err0)
fmt.Printf("Cust  : %v\n", cust)

ctx = ContextWithContent(nil, fsys, "resource/json/event-list.json")
list, err1 := ProcessContent[[]CustomerHistory](ctx)
fmt.Printf("Error : %v\n", err1)
fmt.Printf("List  : %v\n", list)
Output:

Error : This is example 1 of an error from test-name-eRr.txt
Error : <nil>
Cust  : {C1 [{ invoice created 2022-08-25 0001} { payment created 2022-08-26 0002}]}
Error : <nil>
List  : [{C1 [{ invoice created 2022-08-25 0001} { payment created 2022-08-26 0002}]} {C0002 [{ return created 2022-10-25 99990001} { credit created 2022-11-01 0002333}]}]

func ProcessEntry

func ProcessEntry[T any](fs *Entry) (T, error)

ProcessEntry - process content that is fs entry

func ReadDir

func ReadDir(fsys fs.FS, name string) ([]fs.DirEntry, error)

func ReadFile

func ReadFile(fsys fs.FS, name string) ([]byte, error)

func ReadMap

func ReadMap(fsys fs.FS, name string) (map[string]string, error)

Types

type Entry

type Entry struct {
	Name    string
	Content []byte
}

func ContextContent

func ContextContent(ctx context.Context) *Entry

ContextContent - return the content

func (*Entry) Error

func (e *Entry) Error() error

Jump to

Keyboard shortcuts

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