Skip to content
/ strum Public

A string unmarshaler to decode line-oriented text into simple Go types.

License

Notifications You must be signed in to change notification settings

xdg-go/strum

Repository files navigation

strum – String Unmarshaler

Go Reference Go Report Card Github Actions codecov License

The strum package provides line-oriented text decoding into simple Go variables, slices, and structs.

  • Splits on whitespace, a delimiter, a regular expression, or a custom tokenizer.
  • Supports basic primitive types: strings, booleans, ints, uints, floats.
  • Supports decoding time.Time using the dateparse library.
  • Supports decoding time.Duration.
  • Supports encoding.TextUnmarshaler types.
  • Decodes a line into a single variable, a slice, or a struct.
  • Decodes all lines into a slice of the above.

Synopsis

	d := strum.NewDecoder(os.Stdin)

	// Decode a line to a single int
	var x int
	err = d.Decode(&x)

	// Decode a line to a slice of int
	var xs []int
	err = d.Decode(&xs)

	// Decode a line to a struct
	type person struct {
		Name string
		Age  int
	}
	var p person
	err = d.Decode(&p)

	// Decode all lines to a slice of struct
	var people []person
	err = d.DecodeAll(&people)

Copyright and License

Copyright 2021 by David A. Golden. All rights reserved.

Licensed under the Apache License, Version 2.0 (the "License"). You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0

About

A string unmarshaler to decode line-oriented text into simple Go types.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages