twtr

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Mar 24, 2022 License: Unlicense Imports: 12 Imported by: 0

Documentation

Overview

Package twtr is the backend to the twtr twtxt client.

go get duriny.envs.sh/twtr/pkg

Note that this package imports under the name 'twtr' by default.

import twtr "duriny.envs.sh/twtr/pkg"

This serves as an API and backend for the command line client, but also allows custom frontends to be built around it. See the cmd package for the reference frontend.

Index

Examples

Constants

View Source
const Version = "v0.2.1"

Version of the twtr client.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	// Timeout for all network activity, defaults to no timeout.
	Timeout time.Duration

	// Feed to write tweets to, if unset, tweets will be discarded.
	Feed io.Writer

	// PreTweet is a Hook that is executed directly before a tweet is posted.
	PreTweet Hook

	// PostTweet is a Hook that is executed, directly after a tweet is posted.
	PostTweet Hook
}

Client is an instance of the twtr client.

Configure the client as desired.

func (*Client) Post

func (client *Client) Post(tweet string) error

Post a new tweet on this client, running the pre/post tweet hooks along the way, return any error that occurs.

Example
package main

import (
	"fmt"

	twtr "duriny.envs.sh/twtr/pkg"
)

func main() {
	// construct a client
	client := &twtr.Client{
		// What happens if you just post to STDOUT? Give it a try :)
		// Feed: os.Stdin,
	}

	// post tweet to the feed
	if err := client.Post("Hello World!"); err != nil {
		fmt.Println("err:", err)
	}
}
Output:

type Hook

type Hook func(*Client) error

Hook into an event of a client, a nil hook is treated as a noop.

Note, a hook may be called more than once, this should be taken into account if necessary.

func ShellHook

func ShellHook(command string) Hook

ShellHook creates a hook from a shell command, the command is executed against the system shell environment when the hook is called.

Example (Curl)
package main

import (
	twtr "duriny.envs.sh/twtr/pkg"
)

func main() {
	twtr.ShellHook("curl -sS https://envs.net/~duriny/twtxt.txt > ~/.local/share/twtr/twtxt.txt")
}
Output:

Example (Scp)
package main

import (
	twtr "duriny.envs.sh/twtr/pkg"
)

func main() {
	twtr.ShellHook("scp ~/.local/share/twtr/twtxt.txt duriny@envs.net:~/public_html/twtxt.txt")
}
Output:

Jump to

Keyboard shortcuts

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