migrator

package
v1.8.1 Latest Latest
Warning

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

Go to latest
Published: May 4, 2021 License: MIT Imports: 20 Imported by: 0

Documentation

Overview

Package migrator provides import/export functionality. It defines Importer and Exporter interfaces amd implements for disqus (importer only) and "native" remark (both importer and exporter). Also implements AutoBackup scheduler running exports as backups and saving them locally.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ImportComments

func ImportComments(p ImportParams) (int, error)

ImportComments imports from given provider format and saves to store

func WithMapper

func WithMapper(reader io.Reader, mapper Mapper) io.Reader

WithMapper wraps reader with url-mapper.

Types

type AutoBackup

type AutoBackup struct {
	Exporter       Exporter
	BackupLocation string
	SiteID         string
	KeepMax        int
	Duration       time.Duration
}

AutoBackup struct handles daily backups params for siteID

func (AutoBackup) Do

func (ab AutoBackup) Do(ctx context.Context)

Do runs daily export to local files, keeps up to keepMax backups for given siteID

type Disqus

type Disqus struct {
	DataStore Store
}

Disqus implements Importer from disqus xml

func (*Disqus) Import

func (d *Disqus) Import(r io.Reader, siteID string) (size int, err error)

Import from disqus and save to store

type Exporter

type Exporter interface {
	Export(w io.Writer, siteID string) (int, error)
}

Exporter defines interface to export comments from internal store

type ImportParams

type ImportParams struct {
	DataStore Store
	InputFile string
	Provider  string
	SiteID    string
}

ImportParams defines everything needed to run import

type Importer

type Importer interface {
	Import(r io.Reader, siteID string) (int, error)
}

Importer defines interface to convert posts from external sources

type Mapper

type Mapper interface {
	URL(url string) string
}

Mapper defines interface to convert data in import procedure

func NewURLMapper

func NewURLMapper(reader io.Reader) (Mapper, error)

NewURLMapper reads rules from given reader and returns initialized URLMapper if given rules are valid.

type MapperMaker

type MapperMaker func(reader io.Reader) (Mapper, error)

MapperMaker defines function that reads rules from reader and returns new Mapper with loaded rules. If rules are not valid it returns error.

type Native

type Native struct {
	DataStore  Store
	Concurrent int
}

Native implements exporter and importer for internal store format {"version": 1, comments:[{...}\n,{}], meta: {meta}} each comments starts from the new line

func (*Native) Export

func (n *Native) Export(w io.Writer, siteID string) (size int, err error)

Export all comments to writer as json strings. Each comment is one string, separated by "\n" The final file is a valid json

func (*Native) Import

func (n *Native) Import(reader io.Reader, siteID string) (size int, err error)

Import comments from json strings produced by Remark.Export

type Store

type Store interface {
	Create(comment store.Comment) (commentID string, err error)
	Find(locator store.Locator, sort string, user store.User) ([]store.Comment, error)
	List(siteID string, limit int, skip int) ([]store.PostInfo, error)
	DeleteAll(siteID string) error
	Metas(siteID string) (umetas []service.UserMetaData, pmetas []service.PostMetaData, err error)
	SetMetas(siteID string, umetas []service.UserMetaData, pmetas []service.PostMetaData) error
}

Store defines minimal interface needed to export and import comments

type URLMapper

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

URLMapper implements Mapper interface

func (*URLMapper) URL

func (u *URLMapper) URL(url string) string

URL maps given url to another url according loaded url-rules. If not matched returns given url.

type WordPress

type WordPress struct {
	DataStore Store
}

WordPress implements Importer from WP xml

func (*WordPress) Convert

func (w *WordPress) Convert(text string) string

Convert satisfies formatter.CommentConverter

func (*WordPress) Import

func (w *WordPress) Import(r io.Reader, siteID string) (size int, err error)

Import comments from WP and save to store

Jump to

Keyboard shortcuts

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