export

package
v0.0.0-...-d841f61 Latest Latest
Warning

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

Go to latest
Published: Jun 11, 2021 License: AGPL-3.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TaskStatusRunning = iota
	TaskStatusSucceeded
	TaskStatusFailed
)

Variables

This section is empty.

Functions

func ConvertToMap

func ConvertToMap(
	data interface{},
	fields []string,
	timeFormat string,
	location *time.Location,
) ([]map[string]string, error)

ConvertToMap converts array of structs to array of maps with flatten keys.

func ExportCsv

func ExportCsv(
	ctx context.Context,
	exportFields []string,
	separator rune,
	dataFetcher DataFetcher,
) (resFileName string, resErr error)

ExportCsv fetches data by page and saves it in csv file.

Types

type DataFetcher

type DataFetcher func(ctx context.Context, page, limit int64) ([]map[string]string, int64, error)

type Task

type Task struct {
	ExportFields []string
	Separator    rune
	DataFetcher  DataFetcher
}

type TaskExecutor

type TaskExecutor interface {
	// StartExecute creates new export task.
	StartExecute(ctx context.Context, t Task) (string, error)
	// Execute receives tasks from channel and save its result to storage.
	Execute(ctx context.Context)
	// GetStatus returns export task status.
	GetStatus(ctx context.Context, id string) (*TaskStatus, error)
}

TaskExecutor is used to implement export task executor.

func NewTaskExecutor

func NewTaskExecutor(
	client mongo.DbClient,
	logger zerolog.Logger,
) TaskExecutor

type TaskStatus

type TaskStatus struct {
	Status int    `bson:"status"`
	File   string `bson:"file"`
}

Jump to

Keyboard shortcuts

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