addata: github.com/Lavos/addata Index | Files | Directories

package addata

import "github.com/Lavos/addata"

Ad Data is an application that creates a search index of all tables within a database, and allows a user to dump the contents of a table into a CSV-encoded file.

Building: “` bash $ go build -o addata command/command.go “`

Usage: “` bash $ ./addata -c [JSON config file] “`

Index

Package Files

api.go application.go doc.go index.go store.go

Variables

var (
    IndexCorrection = func(b []byte) [][]byte { return ferret.ErrorCorrect(b, ferret.LowercaseLetters) }
    IndexSorter     = func(s string, v interface{}, l int, i int) float64 { return -float64(l + i) }
    IndexConverter  = func(s string) []byte { return []byte(s) }
)

type API Uses

type API struct {
    Port   uint
    Server *web.Server
    Store  *Store
    Index  *Index
}

API creates and managers a pointer to a web.Server, and has methods for the HTTP API so we can easily expose the other required types.

func NewAPI Uses

func NewAPI(port uint, i *Index, s *Store) *API

NewAPI returns a pointer to a new API instance, creating all the required types for the API to function.

func (*API) ReturnTable Uses

func (a *API) ReturnTable(ctx *web.Context, tablename string)

ReturnTable returns a CSV-encoded download of a table's contents.

func (*API) Run Uses

func (a *API) Run()

Run starts the API instance, which in turn starts the web.Server.

func (*API) Search Uses

func (a *API) Search(ctx *web.Context) []byte

Search searches for a given table name against the Index, and returns a list of string tablenames.

type Application Uses

type Application struct {
    API   *API
    Store *Store
    Index *Index
}

Application represents a collection of the other types within this package. This is the only type that most implementations will have to create, usually via NewApplication.

func NewApplication Uses

func NewApplication(c *Configuration) *Application

NewApplication returns a pointer to a new Application. Most implemenations will only need to call this to create all the required other types.

func (*Application) Maintenance Uses

func (a *Application) Maintenance()

Maintenance creates a loop that refreshs the index on an interval.

func (*Application) Run Uses

func (a *Application) Run()

Run starts the Application, which then starts all the other required types within.

type Configuration Uses

type Configuration struct {
    Username, Password, Hostname, Database string
    DBPort, APIPort                        uint
}

Configuration maps directly to the passed JSON configuration file keys.

type Index Uses

type Index struct {
    InvertedSuffix *ferret.InvertedSuffix

    QueryChan   chan Query
    RebuildChan chan []string
}

Index stores the internal ferret.InvertedSuffix and required channels for concurrent access.

func NewIndex Uses

func NewIndex() *Index

NewIndex returns a pointer to a new Index.

func (*Index) Query Uses

func (i *Index) Query(term string) []string

Query checks a given string against the internal ferret.InvertedSuffix and return a slice of string matches.

func (*Index) RebuildWith Uses

func (i *Index) RebuildWith(names []string)

RebuildWith rebuilds the Index's internal ferret.InvertedSuffix with the supplied slice of strings.

func (*Index) Run Uses

func (i *Index) Run()

Run starts the Index running it's required goroutines.

type Query Uses

type Query struct {
    Term       string
    ReturnChan chan []string
}

Query gathers the required information to make a query together for ease of communication across channels.

type Store Uses

type Store struct {
    DSN string
    DB  *sql.DB
}

Type Store stores the DSN for the Database access, derived from the Application Configuration.

func NewStore Uses

func NewStore(dsn string) *Store

NewStore returns a pointer to a new Store

func (*Store) GetTableNames Uses

func (s *Store) GetTableNames() []string

GetTableNames returns a list of the string table names, gathered from the database.

func (*Store) ReturnTable Uses

func (s *Store) ReturnTable(tablename string) ([][]string, error)

ReturnTable returns the rows of a table in a format that's applicable for CSV encoding in the API.

Directories

PathSynopsis
command

Package addata imports 11 packages (graph) and is imported by 1 packages. Updated 2016-07-19. Refresh now. Tools for package owners.