twtxt

package module
v0.0.0-...-c00e1f0 Latest Latest
Warning

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

Go to latest
Published: Jul 16, 2022 License: MIT Imports: 9 Imported by: 0

README

go-twtxt

Package twtxt implements encoding and decoding of the twtxt data format.

A twtxt file looks something like this:

2016-02-04T13:30:00+01:00	You can really go crazy here! ┐(゚∀゚)┌
2016-02-03T23:05:00+01:00	@<example http://example.org/twtxt.txt> welcome to twtxt!
2016-02-01T11:00:00+01:00	This is just another example.
2015-12-12T12:00:00+01:00	Fiat lux!

And this:

# | |___      _| |___  _| |_
# | __\ \ /\ / / __\ \/ / __|
# | |_ \ V  V /| |_ >  <| |_
#  \__| \_/\_/  \__/_/\_\\__|
#
# This is a comment.

2022-07-16T14:15:55-07:00	Dorud
2021-01-14T08:43:00+01:00	I can count! — ۰ ۱ ۲ ۳ ۴ ۵ ۶ ۷ ۸ ۹
2020-12-30T23:06:32+01:00	This is an example post 😈
2020-12-23T19:54:53+01:00	Hello world!

twtxt is a data format used for creating feeds.

twtxt feeds are used to form a decentralized micro-blogging social network.

twtxt is somewhat similar to the historic feed data formats: CDF, RSS, and Atom; in that all 4 are programmer-readable & machine-readable feed formats based on text.

All 4 are also similar to how the even older human-readable finger .plan files were used.

Documention

Online documentation, which includes examples, can be found at: http://godoc.org/github.com/reiver/go-twtxt

GoDoc

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Decoder

type Decoder struct {
	// contains filtered or unexported fields
}

Decoder reads and decodes twtxt values from an input stream.

For example:

var decoder twtxt.Decoder

err := decoder.SetReader(reader)
if nil != err {
	return err
}
defer decoder.Close()

for decoder.Next() {

	kind := decoder.Kind()

	switch kind {
	case twtxt.KindStatus:

		var when time.Time
		var content string

		err := decoder.Decode(&when, &content)
		if nil != err {
			return err
		}

		//@TODO

	case twtxt.KindComment:

		var comment string

		err := decoder.Decode(&comment)
		if nil != err {
			return err
		}

		//@TODO

	case twtxt.KindInvalid:

		var invalid string

		err := decoder.Decode(&invalid)
		if nil != err {
			return err
		}

		//@TODO

	default:
		//@TODO
	}
}
if err := decoder.Err(); nil != err {
	return err
}

func (*Decoder) Close

func (receiver *Decoder) Close() error

Close closes the decoder.

func (*Decoder) Decode

func (receiver *Decoder) Decode(dst ...any) error

Decode decodes the next twtxt line.

You should call Kind() before calling Decode() to know what type and how many parameters to pass it.

func (*Decoder) Err

func (receiver *Decoder) Err() error

Err returns an errors that happened.

func (*Decoder) Kind

func (receiver *Decoder) Kind() Kind

Kind returns the kind of the next twtxt line.

func (*Decoder) Next

func (receiver *Decoder) Next() bool

Next returns whether there is a next twtxt line or not.

func (*Decoder) SetReader

func (receiver *Decoder) SetReader(reader io.Reader) error

SetReader provides the twtxt.Decoder with the io.Reader it will get input from.

A twtxt.Decoder cannot have its reader reset to a new io.Reader. It will return an error if it is successfully called.

type Kind

type Kind uint
const (
	KindUndefined Kind = iota
	KindInvalid
	KindStatus
	KindComment
)

func (Kind) String

func (receiver Kind) String() string

Jump to

Keyboard shortcuts

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