Documentation
¶
Index ¶
- Variables
- type COption
- type Converter
- type Coordinator
- type DumpConverter
- func (dw *DumpConverter) Channels(_ context.Context, cc []slack.Channel) error
- func (s *DumpConverter) Convert(ctx context.Context, channelID, threadID string) error
- func (dw *DumpConverter) Users(_ context.Context, uu []slack.User) error
- func (dw *DumpConverter) WorkspaceInfo(_ context.Context, wi *slack.AuthTestResponse) error
- type DumpOption
- type ExpConverter
- type ExpCvtOption
- type ExpOption
- type ExportCoordinator
- type Templater
- type UserConverter
Constants ¶
This section is empty.
Variables ¶
var ErrClosed = errors.New("transformer is closed")
Functions ¶
This section is empty.
Types ¶
type COption ¶
type COption func(*Coordinator)
type Converter ¶
type Converter interface {
// Convert should convert the chunk to the Converters' output format.
Convert(ctx context.Context, channelID string, threadID string) error
}
Converter is the interface that defines a set of methods for transforming chunks to some output format.
type Coordinator ¶
type Coordinator struct {
// contains filtered or unexported fields
}
Coordinator coordinates the conversion of chunk files to the desired format. It is used to convert files in parallel.
func NewCoordinator ¶
func NewCoordinator(ctx context.Context, cvt Converter, opts ...COption) *Coordinator
NewCoordinator creates a new Coordinator.
func (*Coordinator) StartWithUsers ¶
type DumpConverter ¶
type DumpConverter struct {
// contains filtered or unexported fields
}
DumpConverter is a converter of chunk files into the Slackdump format.
func NewDump ¶
func NewDump(fsa fsadapter.FS, src source.Sourcer, opts ...DumpOption) (*DumpConverter, error)
NewDump creates a new standard dump converter.
func (*DumpConverter) Convert ¶
func (s *DumpConverter) Convert(ctx context.Context, channelID, threadID string) error
Convert converts the chunk file to Slackdump json format.
func (*DumpConverter) WorkspaceInfo ¶
func (dw *DumpConverter) WorkspaceInfo(_ context.Context, wi *slack.AuthTestResponse) error
WorkspaceInfo writes the workspace info to the filesystem.
type DumpOption ¶
type DumpOption func(*DumpConverter)
func DumpWithLogger ¶
func DumpWithLogger(log *slog.Logger) DumpOption
func DumpWithPipeline ¶
func DumpWithPipeline(f ...func(channelID string, threadTS string, mm []slack.Message) error) DumpOption
DumpWithPipeline adds a pipeline function to the transformer, that will be called for each message slice, before it is written to the filesystem.
func DumpWithTemplate ¶
func DumpWithTemplate(tmpl Templater) DumpOption
type ExpConverter ¶
type ExpConverter struct {
// contains filtered or unexported fields
}
func NewExpConverter ¶
func NewExpConverter(src source.Sourcer, fsa fsadapter.FS, opt ...ExpCvtOption) *ExpConverter
func (*ExpConverter) Convert ¶
func (e *ExpConverter) Convert(ctx context.Context, channelID, _ string) error
Convert is the chunk file export converter. It transforms the chunk file for the channel with ID into a slack export format. It expects the chunk file to be in the <srcdir>/<id>.json.gz file, and the attachments to be in the <srcdir>/<id> directory.
func (*ExpConverter) HasUsers ¶
func (e *ExpConverter) HasUsers() bool
HasUsers returns true if the converter has users.
func (*ExpConverter) SetUsers ¶
func (e *ExpConverter) SetUsers(users []slack.User)
func (*ExpConverter) WriteIndex ¶
func (e *ExpConverter) WriteIndex(ctx context.Context) error
WriteIndex generates and writes the export index files. It must be called once all transformations are done, because it might require to read channel files.
type ExpCvtOption ¶
type ExpCvtOption func(*ExpConverter)
func ExpWithMsgUpdateFunc ¶
func ExpWithUsers ¶
func ExpWithUsers(users []slack.User) ExpCvtOption
type ExpOption ¶
type ExpOption func(*ExportCoordinator)
ExpOption is a function that configures the Export instance.
func WithBufferSize ¶
WithBufferSize sets the size of the channel IDs buffer. This is the number of channel IDs that will be queued without blocking before the transform.Export is started.
type ExportCoordinator ¶
type ExportCoordinator struct {
// contains filtered or unexported fields
}
ExportCoordinator is a takes the chunks produced by the processor and transforms them into a Slack Export format. It is suitable for async processing, in which case, OnFinalise function is passed to the processor, the finalisation requests will be queued (up to a [bufferSz]) and will be processed once Start or StartWithUsers is called.
Please note, that transform requires users to be passed either through options or through StartWithUsers. If users are not passed, the ExportCoordinator.Start will return an error.
The asynchronous pattern to run the transform is as follows:
- Create the transform instance.
- Defer its Close method.
- In goroutine: Start user processing, and in the same goroutine, after all users are fetched, call ExportCoordinator.StartWithUsers, passing the fetched users slice.
- In another goroutine, start the ExportCoordinator Conversation processor, passing the transformer's OnFinalise function as the Finaliser option. It will be called by export processor for each channel that was completed.
func NewExportCoordinator ¶
func NewExportCoordinator(ctx context.Context, cvt UserConverter, tfopt ...ExpOption) *ExportCoordinator
NewExportCoordinator creates a new ExportCoordinator instance.
func (*ExportCoordinator) Close ¶
func (t *ExportCoordinator) Close() (err error)
Close closes the coordinator. It must be called once it is guaranteed that [Transform] will not be called anymore, otherwise the call to Transform will panic with "send on the closed channel". If the coordinator is already closed, it will return nil.
func (*ExportCoordinator) Start ¶
func (t *ExportCoordinator) Start(ctx context.Context) error
Start starts the coordinator, the users must have been initialised with the WithUsers option. Otherwise, use ExportCoordinator.StartWithUsers method. The function doesn't check if coordinator was already started or not.
func (*ExportCoordinator) StartWithUsers ¶
StartWithUsers starts the Transform processor with the provided list of users. Users are used to populate each message with the user profile, as per Slack original export format.
func (*ExportCoordinator) Transform ¶
func (t *ExportCoordinator) Transform(ctx context.Context, channelID, threadTS string) error
Transform is the function that should be passed to the Channel processor. It will not block if the internal buffer is full. Buffer size can be set with the WithBufferSize option. The caller is allowed to call OnFinalise even if the processor is not started, in which case the channel ID will be queued for processing once the processor is started. If the export worker is closed, it will return ErrClosed.
type Templater ¶
type Templater interface {
Execute(c *types.Conversation) string
}