Documentation
¶
Index ¶
- Constants
- Variables
- type Addr
- type Chunk
- type ChunkType
- type DirOption
- type Directory
- func (d *Directory) AllMessages(ctx context.Context, channelID string) ([]slack.Message, error)
- func (d *Directory) AllThreadMessages(_ context.Context, channelID, threadID string) ([]slack.Message, error)
- func (d *Directory) ChannelInfo(ctx context.Context, id string) (*slack.Channel, error)
- func (d *Directory) Channels(ctx context.Context) ([]slack.Channel, error)
- func (d *Directory) Close() error
- func (d *Directory) Create(fileID FileID) (io.WriteCloser, error)
- func (d *Directory) FastAllMessages(ctx context.Context, channelID string) ([]slack.Message, error)
- func (d *Directory) FastAllThreadMessages(channelID, threadID string) ([]slack.Message, error)
- func (d *Directory) File(id string, name string) (fs.File, error)
- func (d *Directory) Latest(ctx context.Context) (map[GroupID]time.Time, error)
- func (d *Directory) Name() string
- func (d *Directory) Open(id FileID) (*File, error)
- func (d *Directory) OpenRAW(filename string) (io.ReadSeekCloser, error)
- func (d *Directory) RemoveAll() error
- func (d *Directory) Sorted(ctx context.Context, channelID string, desc bool, ...) error
- func (d *Directory) Stat(id FileID) (fs.FileInfo, error)
- func (d *Directory) ToChunk(ctx context.Context, enc Encoder, _ int64) error
- func (d *Directory) Users() ([]slack.User, error)
- func (d *Directory) Walk(fn func(name string, f *File, err error) error) error
- func (d *Directory) WalkSync(fn func(name string, f *File, err error) error) error
- func (d *Directory) WorkspaceInfo() (*slack.AuthTestResponse, error)
- type Encoder
- type File
- func (p *File) AllChannelIDs() []string
- func (f *File) AllChannelInfos() ([]slack.Channel, error)
- func (p *File) AllChannels() ([]slack.Channel, error)
- func (f *File) AllMessages(_ context.Context, channelID string) ([]slack.Message, error)
- func (f *File) AllThreadMessages(channelID, threadTS string) ([]slack.Message, error)
- func (p *File) AllUsers() ([]slack.User, error)
- func (f *File) ChannelInfo(channelID string) (*slack.Channel, error)
- func (f *File) ChannelUsers(channelID string) ([]string, error)
- func (f *File) Close() error
- func (f *File) ForEach(fn func(ev *Chunk) error) error
- func (f *File) HasChannels() bool
- func (f *File) HasChunks(id GroupID) bool
- func (f *File) HasUsers() bool
- func (f *File) Latest(ctx context.Context) (map[GroupID]time.Time, error)
- func (f *File) Sorted(ctx context.Context, chanID string, desc bool, ...) error
- func (f *File) ThreadParent(channelID, threadTS string) (*slack.Message, error)
- func (f *File) WorkspaceInfo() (*slack.AuthTestResponse, error)
- type FileID
- type GroupID
- type NopTransformer
- type Option
- type Player
- func (p *Player) ChannelInfo(id string) (*slack.Channel, error)
- func (p *Player) ChannelUsers(channelID string) ([]string, error)
- func (p *Player) Channels() ([]slack.Channel, error)
- func (p *Player) Close() error
- func (p *Player) HasChannels() bool
- func (p *Player) HasMoreChannelUsers(channelID string) bool
- func (p *Player) HasMoreChannels() bool
- func (p *Player) HasMoreMessages(channelID string) bool
- func (p *Player) HasMoreThreads(channelID string, threadTS string) bool
- func (p *Player) HasUsers() bool
- func (p *Player) Messages(channelID string) ([]slack.Message, error)
- func (p *Player) Offset() int64
- func (p *Player) Reset() error
- func (p *Player) SetState(ptrs map[GroupID]int)
- func (p *Player) State() map[GroupID]int
- func (p *Player) Thread(channelID string, threadTS string) ([]slack.Message, error)
- func (p *Player) ThreadChannelInfo(id string) (*slack.Channel, error)
- func (p *Player) Users() ([]slack.User, error)
- func (p *Player) WorkspaceInfo() (*slack.AuthTestResponse, error)
- type Recorder
- func (rec *Recorder) ChannelInfo(ctx context.Context, channel *slack.Channel, threadTS string) error
- func (rec *Recorder) ChannelUsers(ctx context.Context, channelID string, threadTS string, users []string) error
- func (rec *Recorder) Channels(ctx context.Context, channels []slack.Channel) error
- func (rec *Recorder) Close() error
- func (rec *Recorder) Files(ctx context.Context, channel *slack.Channel, parent slack.Message, ...) error
- func (rec *Recorder) Messages(ctx context.Context, channelID string, numThreads int, isLast bool, ...) error
- func (rec *Recorder) SearchFiles(ctx context.Context, query string, sf []slack.File) error
- func (rec *Recorder) SearchMessages(ctx context.Context, query string, sm []slack.SearchMessage) error
- func (rec *Recorder) ThreadMessages(ctx context.Context, channelID string, parent slack.Message, ...) error
- func (rec *Recorder) Users(ctx context.Context, users []slack.User) error
- func (rec *Recorder) WorkspaceInfo(ctx context.Context, atr *slack.AuthTestResponse) error
- type Result
- type Transformer
Constants ¶
const ( UploadsDir = "__uploads" // for serving files AvatarsDir = "__avatars" )
const (
ChunkExt = ".json.gz"
)
file extensions
Variables ¶
var ( ErrNotFound = errors.New("not found") ErrNoData = errors.New("no data") ErrDataMisaligned = errors.New("internal error: index and file data misaligned") )
var ErrNoChannelUsers = errors.New("no channel users")
var ErrUnsupChunkType = fmt.Errorf("unsupported chunk type")
Functions ¶
This section is empty.
Types ¶
type Addr ¶
type Addr struct {
Offset int64 // offset within the chunk file
Index int16 // index of the message within the messages slice in the chunk
}
Addr is the address of a particular message within a chunk file.
type Chunk ¶
type Chunk struct {
// header
// Type is the type of the Chunk
Type ChunkType `json:"t"`
// Timestamp when the chunk was recorded.
Timestamp int64 `json:"ts"`
// ChannelID that this chunk relates to.
ChannelID string `json:"id,omitempty"`
// Count is the count of elements in the chunk, i.e. messages or files.
Count int32 `json:"n,omitempty"`
// NumThreads is the number of threads in the message chunk.
NumThreads int32 `json:"nt,omitempty"`
// ThreadTS is populated if the chunk contains thread related data. It
// is Slack's thread_ts.
ThreadTS string `json:"r,omitempty"`
IsLast bool `json:"l,omitempty"`
// ThreadOnly is set to true if the chunk was generated as a result
// of thread only scraping.
ThreadOnly bool `json:"to,omitempty"`
// Channel contains the channel information. Within the chunk file, it
// may not be immediately followed by messages from the channel due to
// concurrent nature of the calls.
//
// Populated by ChannelInfo and Files methods.
Channel *slack.Channel `json:"ci,omitempty"`
// ChannelUsers contains the user IDs of the users in the channel.
ChannelUsers []string `json:"cu,omitempty"` // Populated by ChannelUsers
// Parent is populated in case the chunk is a thread, or a file. Populated
// by ThreadMessages and Files methods.
Parent *slack.Message `json:"p,omitempty"`
// Messages contains a chunk of messages as returned by the API. Populated
// by Messages and ThreadMessages methods.
Messages []slack.Message `json:"m,omitempty"`
// Files contains a chunk of files as returned by the API. Populated by
// Files method.
Files []slack.File `json:"f,omitempty"`
// Users contains a chunk of users as returned by the API. Populated by
// Users method.
Users []slack.User `json:"u,omitempty"`
// Channels contains a chunk of channels as returned by the API. Populated
// by Channels method.
Channels []slack.Channel `json:"ch,omitempty"`
// WorkspaceInfo contains the workspace information as returned by the
// API. Populated by WorkspaceInfo.
WorkspaceInfo *slack.AuthTestResponse `json:"w,omitempty"`
// StarredItems contains the starred items.
StarredItems []slack.StarredItem `json:"st,omitempty"` // Populated by StarredItems
// Bookmarks contains the bookmarks.
Bookmarks []slack.Bookmark `json:"b,omitempty"` // Populated by Bookmarks
// SearchQuery contains the search query.
SearchQuery string `json:"sq,omitempty"` // Populated by SearchMessages and SearchFiles.
// SearchMessages contains the search results.
SearchMessages []slack.SearchMessage `json:"sm,omitempty"` // Populated by SearchMessages
// SearchFiles contains the search results.
SearchFiles []slack.File `json:"sf,omitempty"` // Populated by SearchFiles
}
Chunk is a representation of a single chunk of data retrieved from the API. A single API call always produces a single Chunk.
func (*Chunk) Timestamps ¶
Timestamps returns the timestamps of the messages in the chunk. For files and other types of chunks, it returns ErrUnsupChunkType.
type Directory ¶
type Directory struct {
// contains filtered or unexported fields
}
Directory is an abstraction over the directory with chunk files. It provides a way to write chunk files and read channels, users and messages across many the chunk files. All functions that require a name, except functions with suffix RAW, will append an extension to the name automatically (".json.gz"). *RAW functions expect the full name of the file with the extension. All files created by this package will be compressed with GZIP, unless stated otherwise.
func CreateDir ¶
CreateDir creates and opens a directory. It will create all parent directories if they don't exist.
func OpenDir ¶
OpenDir "opens" an existing directory for read and write operations. It expects the directory to exist and to be a directory, otherwise it will return an error.
func (*Directory) AllMessages ¶
func (*Directory) AllThreadMessages ¶
func (*Directory) ChannelInfo ¶
func (*Directory) Channels ¶
Channels collects all channels from the chunk directory. First, it attempts to find the channel.json.gz file, if it's not present, it will go through all conversation files and try to get "ChannelInfo" chunk from each file.
func (*Directory) Create ¶
func (d *Directory) Create(fileID FileID) (io.WriteCloser, error)
Create creates the chunk file with the given name. Extension is appended automatically.
Example:
cd, _ := chunk.OpenDirectory("chunks")
f, _ := cd.Create("channels") // creates channels.json.gz
It will NOT overwrite an existing file and will return an error if the file exists.
func (*Directory) FastAllMessages ¶
func (*Directory) FastAllThreadMessages ¶
func (*Directory) Latest ¶
Latest returns the latest timestamps for the channels and threads in the directory.
func (*Directory) Open ¶
Open opens a chunk file with the given name. Extension is appended automatically.
func (*Directory) OpenRAW ¶
func (d *Directory) OpenRAW(filename string) (io.ReadSeekCloser, error)
OpenRAW opens a compressed chunk file with filename within the directory, and returns a ReadSeekCloser. filename is the full name of the file with extension.
func (*Directory) RemoveAll ¶
RemoveAll deletes the directory and all its contents. Make sure all files are closed.
func (*Directory) Walk ¶
Walk iterates over all chunk files in the directory and calls the function for each file. If the function returns an error, the iteration stops. It does not close files after the callback is called, so it's a caller's responsibility to close it.
func (*Directory) WalkSync ¶
WalkSync is the same as Walk, but it closes the file after the callback is called.
func (*Directory) WorkspaceInfo ¶
func (d *Directory) WorkspaceInfo() (*slack.AuthTestResponse, error)
WorkspaceInfo returns the workspace info from the directory.
type File ¶
type File struct {
// contains filtered or unexported fields
}
File is the catalog of chunks in a file.
func FromReader ¶
func FromReader(rs io.ReadSeeker) (*File, error)
FromReader creates a new chunk File from the io.ReadSeeker.
func (*File) AllChannelIDs ¶
AllChannelIDs returns all the channels in the chunkfile.
func (*File) AllChannelInfos ¶
AllChannelInfos returns all the channel information collected by the channel info API.
func (*File) AllChannels ¶
AllChannels returns all channels collected by listing channels in the dump file.
func (*File) AllMessages ¶
AllMessages returns all the messages for the given channel posted to it (no thread). The messages are in the order as they appear in the file.
func (*File) AllThreadMessages ¶
AllThreadMessages returns all the messages for the given thread. It does not return the parent message in the result, use File.ThreadParent for that. The messages are in the order as they appear in the file.
func (*File) ChannelInfo ¶
ChannelInfo returns the information for the given channel.
func (*File) ForEach ¶
ForEach iterates over the chunks in the reader and calls the function for each chunk. It will lock the file until it finishes.
func (*File) HasChannels ¶
HasChannels returns true if there is at least one channel chunk in the file.
func (*File) Latest ¶
Latest returns the latest timestamps for the channels and threads in the file.
func (*File) Sorted ¶
func (f *File) Sorted(ctx context.Context, chanID string, desc bool, fn func(ts time.Time, m *slack.Message) error) error
Sorted iterates over all the messages in the chunkfile in chronological order for the requested chanID. If desc is true, the slice will be iterated in reverse order. It does not differentiate between the channel and thread messages. The function fn is called for each message in the slice. If the function returns an error, the iteration stops and the error is returned.
func (*File) ThreadParent ¶
ThreadParent returns the thread parent message for the given thread. It returns ErrNotFound if the thread is not found.
func (*File) WorkspaceInfo ¶
func (f *File) WorkspaceInfo() (*slack.AuthTestResponse, error)
WorkspaceInfo returns the workspace info from the chunkfile.
type FileID ¶
type FileID string
FileID is the ID of the file within the Directory (it's basically the file name without an extension).
const ( FChannels FileID = "channels" FUsers FileID = "users" FWorkspace FileID = "workspace" FSearch FileID = "search" )
common filenames
func LinkToFileID ¶
func LinkToFileID(sl structures.SlackLink, includeThread bool) FileID
LinkToFileID converts the SlackLink to file ID. If includeThread is true and the thread timestamp is not empty, the thread timestamp will be appended to the channel ID. Otherwise, only the channel ID will be returned.
func ToFileID ¶
ToFileID returns the file ID for the given channel and thread timestamp. If includeThread is true and threadTS is not empty, the thread timestamp will be appended to the channel ID. Otherwise, only the channel ID will be returned.
func (FileID) SlackLink ¶
func (id FileID) SlackLink() structures.SlackLink
SlackLink returns the SlackLink for the file ID. If the file ID doesn't contain the thread timestamp, the thread timestamp will be empty.
type GroupID ¶
type GroupID string
GroupID is a unique ID for a chunk group. It is used to group chunks of the same type together for indexing purposes. It may or may not be equal to the Slack ID of the entity.
func (GroupID) AsChannelID ¶
asChannelID returns the channel ID from the GroupID. If the GroupID is not a channel ID, it returns false.
func (GroupID) AsThreadID ¶
asThreadID returns the channelID and threadTS from the GroupID. If the GroupID is not a thread ID, it returns false.
func (GroupID) ExtractChannelID ¶
ExtractChannelID attempts to extract the channel ID from the GroupID if it is a channel or a thread ID. Otherwise, ok will be false.
type NopTransformer ¶
type NopTransformer struct{}
NopTransformer is a transformer that does nothing.
type Option ¶
type Option func(r *Recorder)
Option is a function that configures the Recorder.
func WithEncoder ¶
WithEncoder allows you to specify a custom encoder to use for the chunks. By default json.Encoder is used.
type Player ¶
type Player struct {
// contains filtered or unexported fields
}
Player replays the chunks from a file, it is able to emulate the API responses, if used in conjunction with the [proctest.Server]. Zero value is not usable.
func NewPlayerFromFile ¶
func (*Player) ChannelInfo ¶
ChannelInfo returns the channel information for the given channel. It returns an error if the channel is not found within the chunkfile.
func (*Player) HasChannels ¶
func (*Player) HasMoreChannelUsers ¶
func (*Player) HasMoreChannels ¶
func (*Player) HasMoreMessages ¶
HasMoreMessages returns true if there are more messages to be read for the channel.
func (*Player) HasMoreThreads ¶
func (*Player) ThreadChannelInfo ¶
func (*Player) WorkspaceInfo ¶
func (p *Player) WorkspaceInfo() (*slack.AuthTestResponse, error)
type Recorder ¶
type Recorder struct {
// contains filtered or unexported fields
}
Recorder records all the data it receives into a writer.
func NewCustomRecorder ¶
NewCustomRecorder creates a new recorder with a custom encoder.
func NewRecorder ¶
NewRecorder creates a new recorder to writer.
func (*Recorder) ChannelInfo ¶
func (rec *Recorder) ChannelInfo(ctx context.Context, channel *slack.Channel, threadTS string) error
ChannelInfo records a channel information. threadTS should be set to threadTS, if ChannelInfo is called while streaming a thread (user requested a thread).
func (*Recorder) ChannelUsers ¶
func (rec *Recorder) ChannelUsers(ctx context.Context, channelID string, threadTS string, users []string) error
ChannelUsers records the channel users
func (*Recorder) Files ¶
func (rec *Recorder) Files(ctx context.Context, channel *slack.Channel, parent slack.Message, f []slack.File) error
Files is called for each file chunk that is retrieved. The parent message is passed in as well.
func (*Recorder) Messages ¶
func (rec *Recorder) Messages(ctx context.Context, channelID string, numThreads int, isLast bool, m []slack.Message) error
Messages is called for each message chunk that is retrieved.
func (*Recorder) SearchFiles ¶
SearchMessages records the result of a file search.
func (*Recorder) SearchMessages ¶
func (rec *Recorder) SearchMessages(ctx context.Context, query string, sm []slack.SearchMessage) error
SearchMessages records the result of a message search.
func (*Recorder) ThreadMessages ¶
func (rec *Recorder) ThreadMessages(ctx context.Context, channelID string, parent slack.Message, threadOnly, isLast bool, tm []slack.Message) error
ThreadMessages is called for each of the thread messages that are retrieved. The parent message is passed in as well.
func (*Recorder) WorkspaceInfo ¶
WorkspaceInfo is called when workspace info is retrieved.
type Transformer ¶
type Transformer interface {
// Transform is the function that starts the transformation of the channel
// or thread with the given id. It is called when the reference count for
// the channel id becomes zero (meaning, that there are no more chunks to
// process). It should return [transform.ErrClosed] if the transformer is
// closed.
Transform(ctx context.Context, channelID, threadID string) error
}
Transformer is an interface that is called when the processor is finished processing a channel or thread.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
backend
|
|
|
dbase/repository/mock_repository
Package mock_repository is a generated GoMock package.
|
Package mock_repository is a generated GoMock package. |
|
directory
Package directory is a processor that writes the data into gzipped files in a directory.
|
Package directory is a processor that writes the data into gzipped files in a directory. |
|
Package chunktest provides a test server for testing the chunk package.
|
Package chunktest provides a test server for testing the chunk package. |
|
Package control holds the implementation of the Slack Stream controller.
|
Package control holds the implementation of the Slack Stream controller. |
|
mock_control
Package mock_control is a generated GoMock package.
|
Package mock_control is a generated GoMock package. |
|
Package mock_chunk is a generated GoMock package.
|
Package mock_chunk is a generated GoMock package. |
|
Package obfuscate obfuscates a slackdump chunk recording.
|
Package obfuscate obfuscates a slackdump chunk recording. |