format

package
v4.1.0 Latest Latest
Warning

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

Go to latest
Published: Feb 26, 2026 License: AGPL-3.0 Imports: 18 Imported by: 0

Documentation

Overview

Package format provides formatting functions for different output format types.

Index

Constants

This section is empty.

Variables

View Source
var Descriptions = map[Type]string{
	CText: "Plain text format",
	CCSV:  "CSV format",
	CJSON: "JSON format",
}

Functions

func NVL

func NVL(s string, rest ...string) string

Types

type CSV

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

func (*CSV) Channels

func (c *CSV) Channels(ctx context.Context, w io.Writer, u []slack.User, chans []slack.Channel) error

func (*CSV) Conversation

func (c *CSV) Conversation(ctx context.Context, w io.Writer, u []slack.User, conv *types.Conversation) error

func (CSV) Extension

func (c CSV) Extension() string

Extension returns the file extension for the formatter.

func (*CSV) Users

func (c *CSV) Users(ctx context.Context, w io.Writer, users []slack.User) error

type Formatter

type Formatter interface {
	// Conversation writes the conversation to the writer.
	Conversation(ctx context.Context, w io.Writer, u []slack.User, conv *types.Conversation) error
	// Channels writes the channel list to the writer.
	Channels(ctx context.Context, w io.Writer, u []slack.User, chans []slack.Channel) error
	// Users writes the user list to the writer.
	Users(ctx context.Context, w io.Writer, u []slack.User) error
	// Extension returns the file extension for the formatter.
	Extension() string
}

Formatter is a converter interface that each formatter must implement.

func NewCSV

func NewCSV(opts ...Option) Formatter

func NewJSON

func NewJSON(opts ...Option) Formatter

func NewText

func NewText(opts ...Option) Formatter

type JSON

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

JSON is the json formatter.

func (JSON) Channels

func (j JSON) Channels(ctx context.Context, w io.Writer, u []slack.User, chans []slack.Channel) error

func (JSON) Conversation

func (j JSON) Conversation(ctx context.Context, w io.Writer, u []slack.User, conv *types.Conversation) error

func (JSON) Extension

func (j JSON) Extension() string

Extension returns the file extension for the formatter.

func (JSON) Users

func (j JSON) Users(ctx context.Context, w io.Writer, u []slack.User) error

type Option

type Option func(*options)

Option is the converter option.

func JSONIndent

func JSONIndent(indent string) Option

func JSONPrefix

func JSONPrefix(prefix string) Option

func TextNewMessageThreshold

func TextNewMessageThreshold(d time.Duration) Option

func WithBareFormat

func WithBareFormat(b bool) Option

WithBareFormat allows to set the bare output format for the formatter that supports it.

type Text

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

func (*Text) Channels

func (txt *Text) Channels(ctx context.Context, w io.Writer, u []slack.User, cc []slack.Channel) error

func (*Text) Conversation

func (txt *Text) Conversation(ctx context.Context, w io.Writer, u []slack.User, conv *types.Conversation) error

func (Text) Extension

func (txt Text) Extension() string

Extension returns the file extension for the formatter.

func (*Text) Users

func (txt *Text) Users(ctx context.Context, w io.Writer, u []slack.User) error

type Type

type Type int

Type is the converter type.

const (
	CUnknown Type = iota // Unknown converter type
	CText                // CText is the plain text converter
	CCSV                 // CCSV is the CSV converter
	CJSON                // CJSON is JSON format converter
)

func (*Type) FormatFunc

func (e *Type) FormatFunc() (func(opts ...Option) Formatter, bool)

func (*Type) Set

func (e *Type) Set(v string) error

func (Type) String

func (i Type) String() string

type Types

type Types []Type

Types is a list of converter types.

func All

func All() Types

func (Types) String

func (tt Types) String() string

Jump to

Keyboard shortcuts

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