groupfile

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Jan 10, 2026 License: GPL-3.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Write

func Write[K GroupName, T any](w io.Writer, ents []Entry[K, T], format func(T) string) error

Write writes the memberships to the writer, such that they can be parsed by Parse.

Types

type Entry

type Entry[K GroupName, T any] struct {
	// FileData is the full contents of the file that contain this entry
	FileData []byte
	Beg, End uint32

	// MStmt is statement about membership
	MStmt *MStmt[K, T]
	// Comment is a line that starts with #
	Comment *string
	// Include is a line that starts with !include
	// The rest of the line is interpretted as a paths to include
	Include *string
}

Entry is a single line in a GroupFile K is the name for a group

func Parse

func Parse[K GroupName, T any](data []byte, parseK func([]byte) (K, error), parseV func([]byte) (T, error)) (ret []Entry[K, T], _ error)

Parse parses a groupfile from data, which should be the entire contents of a group file.

func (*Entry[K, T]) Memberships

func (ent *Entry[K, T]) Memberships() (ret []Membership[K, T])

Memberships returns all Memberships contained in the entry.

func (*Entry[K, T]) Validate

func (ent *Entry[K, T]) Validate() error

func (*Entry[K, T]) WriteTo

func (ent *Entry[K, T]) WriteTo(w io.Writer, fmtV func(T) string) (int, error)

type ErrParsing

type ErrParsing struct {
	FileData []byte
	Beg, End uint32
	Err      error
}

func (ErrParsing) Error

func (e ErrParsing) Error() string

type GroupFile

type GroupFile[K GroupName, T any] = []Entry[K, T]

type GroupName

type GroupName interface {
	comparable
	String() string
}

GroupName is implemented by all types that can be the name of a group. GroupNames must be comparable and implement the String method

type MStmt

type MStmt[K GroupName, T any] struct {
	Group   K
	Members []Member[K, T]
}

MStmt is a statement about group membership

type Member

type Member[K GroupName, T any] struct {
	// Unit references a single element
	Unit *T
	// GroupRef references another group by name.
	GroupRef *K
	// Empty is used to create empty groups.
	Empty *struct{}
}

Member is a member of a group. Members can either refer to another group by name, or to a single element of type T.

func GroupRef

func GroupRef[K GroupName, T any](subGroup K) Member[K, T]

GroupRef creates a group member that references a group by name.

func Unit

func Unit[K GroupName, T any](unit T) Member[K, T]

Unit creates a group member that references a single element.

func (Member[K, T]) Format

func (m Member[K, T]) Format(format func(T) string) string

type Membership

type Membership[K GroupName, T any] struct {
	Group  K
	Member Member[K, T]
}

Membership says that a group contains a member.

Jump to

Keyboard shortcuts

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