exchange

package
v0.0.0-...-38b5e39 Latest Latest
Warning

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

Go to latest
Published: Mar 24, 2015 License: MIT Imports: 26 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CSVFile

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

func NewCSVFile

func NewCSVFile(r io.Reader) (f *CSVFile, err error)

func (*CSVFile) Line

func (f *CSVFile) Line(l int) []string

func (*CSVFile) TotalLines

func (f *CSVFile) TotalLines() (num int)

type ContentType

type ContentType string
const (
	ExcelContentType ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
	CSVContentType   ContentType = "text/csv"
)

type Exchange

type Exchange struct {
	Resource         *Resource
	StopOnError      bool
	JobThrottle      int
	StatusThrottle   int
	NormalizeHeaders func(f File) []string
	DataStartAt      int
}

func New

func New(res *Resource) *Exchange

func (*Exchange) Export

func (ex *Exchange) Export(records interface{}, w io.Writer, ctx *qor.Context) (err error)

Export will format data into csv string and write it into a writer, by the definitions of metas. Note: records must be a slice or Export will panic.

func (*Exchange) Import

func (ex *Exchange) Import(f File, log io.Writer, ctx *qor.Context) (err error)

type File

type File interface {
	TotalLines() (num int)
	Line(l int) (fields []string)
}

type GoogleDriveConverter

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

func NewGoogleDriveConverter

func NewGoogleDriveConverter(clientEmail, keyFilePath string) (gdc *GoogleDriveConverter, err error)

How to create a google api service account: https://developers.google.com/drive/web/service-accounts About google-api-go-client: https://code.google.com/p/google-api-go-client/wiki/GettingStarted

 The contents of your RSA private key or your PEM file
 that contains a private key.
 If you have a p12 file instead, you
 can use `openssl` to export the private key into a pem file.

    $ openssl pkcs12 -in key.p12 -out key.pem -nodes

 It only supports PEM containers with no passphrase.

More explanations, see: http://godoc.org/github.com/golang/oauth2

func NewGoogleDriveConverterByJSONKey

func NewGoogleDriveConverterByJSONKey(filename string) (gdc *GoogleDriveConverter, err error)

NewGoogleDriveConverterByJSONKey will accept a json key file downloaded from google project and return a GoogleDriveConverter. Built for convinence.

func (*GoogleDriveConverter) Convert

func (gdc *GoogleDriveConverter) Convert(path string, from, to ContentType) (r io.Reader, err error)

type ImportInfo

type ImportInfo struct {
	TotalLines int
	Done       chan bool
	Error      chan error
}

type ImportStatus

type ImportStatus struct {
	LineNum    int
	MetaValues *resource.MetaValues
	Errors     []error
}

type Meta

type Meta struct {
	Name string
	// Alias string
	Label string
	// Type          string
	Valuer   func(interface{}, *qor.Context) interface{}
	Setter   func(resource interface{}, metaValue *resource.MetaValue, context *qor.Context)
	Metas    []resource.Metaor
	Resource resource.Resourcer
	// Collection    interface{}
	// GetCollection func(interface{}, *qor.Context) [][]string
	Permission *roles.Permission

	Optional     bool
	AliasHeaders []string
	// contains filtered or unexported fields
}

func (*Meta) GetFieldName

func (meta *Meta) GetFieldName() string

func (*Meta) GetMetas

func (meta *Meta) GetMetas() []resource.Metaor

func (*Meta) GetName

func (meta *Meta) GetName() string

func (*Meta) GetResource

func (meta *Meta) GetResource() resource.Resourcer

func (*Meta) GetSetter

func (meta *Meta) GetSetter() func(resource interface{}, metaValue *resource.MetaValue, context *qor.Context)

func (*Meta) GetValuer

func (meta *Meta) GetValuer() func(interface{}, *qor.Context) interface{}

func (*Meta) HasPermission

func (meta *Meta) HasPermission(mode roles.PermissionMode, context *qor.Context) bool

func (*Meta) Set

func (m *Meta) Set(field string, val interface{}) *Meta

type Resource

type Resource struct {
	*resource.Resource
	Metas                map[string]*Meta // TODO: replace it with a slice
	AutoCreate           bool
	MultiDelimiter       string
	HasSequentialColumns bool
	HeadersInOrder       []string
}

func NewResource

func NewResource(val interface{}) *Resource

func (*Resource) CallFinder

func (res *Resource) CallFinder(result interface{}, metaValues *resource.MetaValues, ctx *qor.Context) (err error)

func (*Resource) Meta

func (res *Resource) Meta(meta *Meta) *Meta

type XLSXFile

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

XLSXFile only support xlsx format. It's a very weak feature. Recommend using GoogleDriveConverter to convert excel file instead.

func NewXLSXFile

func NewXLSXFile(filename string) (nxf *XLSXFile, err error)

func NewXLSXFileReader

func NewXLSXFileReader(r io.Reader) (nxf *XLSXFile, err error)

func NewXLSXFileZipReader

func NewXLSXFileZipReader(zr *zip.ReadCloser) (nxf *XLSXFile, err error)

func (*XLSXFile) Line

func (x *XLSXFile) Line(l int) (fields []string)

func (*XLSXFile) TotalLines

func (x *XLSXFile) TotalLines() (num int)

Jump to

Keyboard shortcuts

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