slackcat

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

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

Go to latest
Published: Feb 11, 2022 License: BSD-3-Clause Imports: 2 Imported by: 2

README

go-writer-slackcat

A Go package for sending messages to a Slack channel using a standard io.Writer interface

Important

This package has been superseded by sfomuseum/go-slack/writer and is no longer being maintained.

Usage

Simple
package main

import (
	"flag"
	"github.com/whosonfirst/go-writer"
	"strings"
)

func main() {

	var config = flag.String("config", "", "The path to your Slackcat config file")

	flag.Parse()
	args := flag.Args()

	w, err := slackcat.NewWriter(*config)

	if err != nil {
		panic(err)
	}

	msg := strings.Join(args, " ")

	b := []byte("Write " + msg)

	_, err = w.Write(b)

	if err != nil {
		panic(err)
	}

	// WriteString is provided as a convenience if you don't
	// feel like []byte("-ing") all the things per the default
	// io.Writer interface spec

	_, err = w.WriteString("WriteString " + msg)

	if err != nil {
		panic(err)
	}
}
Fancy
package main

import (
	"flag"
	"github.com/whosonfirst/go-writer-slackcat"
	"io"
	"log"
	"os"
	"strings"
)

func main() {

	var config = flag.String("config", "", "The path to your Slackcat config file")

	flag.Parse()
	args := flag.Args()

	msg := strings.Join(args, " ")

	slack, _ := slackcat.NewWriter(*config)

	writer := io.MultiWriter(os.Stdout, slack)

	logger := log.New(writer, "[example] ", log.Ldate|log.Ltime|log.Lshortfile)
	logger.Println(msg)
}

See also

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Writer

type Writer struct {
	Config *slack.Config
}

func NewWriter

func NewWriter(path string) (*Writer, error)

func (Writer) Close

func (w Writer) Close() error

func (Writer) Write

func (w Writer) Write(p []byte) (int, error)

func (Writer) WriteString

func (w Writer) WriteString(s string) (n int64, err error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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