drbdconf

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

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

Go to latest
Published: Aug 21, 2025 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Format description:

Index

Constants

View Source
const TokenMaxLen = 255

Variables

This section is empty.

Functions

func EnsureEnum

func EnsureEnum[T ~string](knownValues map[T]struct{}, value string) error

func EnsureLen

func EnsureLen(words []Word, lenAtLeast int) error

func Marshal

func Marshal[T any, TP Ptr[T]](src TP, dst *Section) error

Mapping of Parameter Types

All primitive types' zero values should semantically correspond to a missing DRBD section parameter (even for required parameters).

Tags

  • `drbd:"parametername"` to select the name of the parameter. There can be one parameterless tag: `drbd:""`, which selects key of the section byitself
  • SectionKeyworder and slices of such types SHOULD NOT be tagged, their name is always taken from SectionKeyworder
  • subsections should always be represented with struct pointers
  • `drbd:"parname1,parname2"` tag value form allows specifying alternative parameter names, which will be tried during unmarshaling. Marshaling will always use the first name.

Primitive Types Support

To add marshaling/unmarshaling support for another primitive type, consider the following options:

  • implement ParameterTypeCodec and register it with RegisterParameterTypeCodec. It will be used for every usage of that type, with highest priority. It will even take precendence over built-in slice support. This method is useful for fields of "marker" interface types.
  • implement ParameterCodec. This marshaling method is last-effort method, it is used when there's no ParameterTypeCodec for a type

func ReadEnum

func ReadEnum[T ~string](
	dst *T,
	knownValues map[T]struct{},
	value string,
) error

func ReadEnumAt

func ReadEnumAt[T ~string](
	dst *T,
	knownValues map[T]struct{},
	p []Word,
	idx int,
) error

func RegisterParameterTypeCodec

func RegisterParameterTypeCodec[T any](codec ParameterTypeCodec)

func SectionKeyword

func SectionKeyword[T any, TP SectionPtr[T]]() string

func Unmarshal

func Unmarshal[T any, PT Ptr[T]](src *Section, dst PT) error

Unmarshals low-level src into a dst struct. Also see docs for Marshal.

Types

type Include

type Include struct {
	Glob  string
	Files []*Root
}

type Location

type Location struct {
	// for error reporting only, zero-based
	LineIndex, ColIndex int
	Filename            string
}

func (Location) NextCol

func (l Location) NextCol() Location

func (Location) NextLine

func (l Location) NextLine() Location

func (Location) String

func (l Location) String() string

type Parameter

type Parameter struct {
	Key []Word
}

func (*Parameter) Location

func (p *Parameter) Location() Location

type ParameterCodec

type ParameterCodec interface {
	ParameterMarshaler
	ParameterUnmarshaler
}

type ParameterMarshaler

type ParameterMarshaler interface {
	MarshalParameter() ([]string, error)
}

type ParameterTypeCodec

type ParameterTypeCodec interface {
	MarshalParameter(v any) ([]string, error)
	UnmarshalParameter(p []Word) (any, error)
}

type ParameterUnmarshaler

type ParameterUnmarshaler interface {
	UnmarshalParameter(p []Word) error
}

type Ptr

type Ptr[T any] interface {
	*T
}

type Root

type Root struct {
	Filename string
	Elements []RootElement
}

func Parse

func Parse(fsys fs.FS, name string) (*Root, error)

func (*Root) AsSection

func (root *Root) AsSection() *Section

func (*Root) TopLevelSections

func (root *Root) TopLevelSections() iter.Seq2[*Root, *Section]

func (*Root) WalkConfigs

func (r *Root) WalkConfigs(accept func(conf *Root) error) error

func (*Root) WriteTo

func (r *Root) WriteTo(w io.Writer) (n int64, err error)

type RootElement

type RootElement interface {
	// contains filtered or unexported methods
}

Section or Include

type Section

type Section struct {
	Key      []Word
	Elements []SectionElement
}

func (*Section) Location

func (s *Section) Location() Location

func (*Section) Parameters

func (s *Section) Parameters() iter.Seq[*Parameter]

func (*Section) ParametersByKey

func (s *Section) ParametersByKey(name string) iter.Seq[*Parameter]

func (*Section) Sections

func (s *Section) Sections() iter.Seq[*Section]

func (*Section) SectionsByKey

func (s *Section) SectionsByKey(name string) iter.Seq[*Section]

type SectionElement

type SectionElement interface {
	// contains filtered or unexported methods
}

Section or Parameter

type SectionKeyworder

type SectionKeyworder interface {
	SectionKeyword() string
}

type SectionPtr

type SectionPtr[T any] interface {
	*T
	SectionKeyworder
}

type Word

type Word struct {
	// means that token is definetely not a keyword, but a value
	IsQuoted bool
	// Unquoted value
	Value    string
	Location Location
}

func NewWord

func NewWord(word string) Word

func NewWords

func NewWords(wordStrs []string) []Word

func (*Word) LocationEnd

func (w *Word) LocationEnd() Location

Directories

Path Synopsis
Missing sections:
Missing sections:

Jump to

Keyboard shortcuts

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