handlers

package
v0.0.0-...-e29e17f Latest Latest
Warning

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

Go to latest
Published: Mar 30, 2020 License: Apache-2.0, Apache-2.0 Imports: 29 Imported by: 0

Documentation

Index

Constants

View Source
const RootFolder = "starship_documents"

RootFolder represents the root folder that documents for starship are stored on object storage TODO - have this configurable in an environment variable

Variables

View Source
var MimeToDocType = map[string]int{
	"text/plain":      document.TypeMarkdown,
	"application/pdf": document.TypePDF,
}

MimeToDocType translates a tika mimeType to a document type

Functions

func AccessAuthorized

func AccessAuthorized(next httprouter.Handle, accessKey string) httprouter.Handle

AccessAuthorized checks to see if an accessKey was supplied at app start and ensures the connecting client has provided it in the proper header

func GetDocType

func GetDocType(s string) int

GetDocType gets the document type from a mimeType

func IndexAuthorized

func IndexAuthorized(next httprouter.Handle, indexKey string) httprouter.Handle

IndexAuthorized checks to see if an indexKey was supplied at app start and ensures the connecting client has provided it in the proper header

Types

type App

type App struct {
	DB                   *sqlx.DB
	HTTPClient           *http.Client
	ObjectStorageEnabled bool
	Cfg
	// contains filtered or unexported fields
}

App represents the application and configuration

func NewApp

func NewApp(cfg Cfg, db *sqlx.DB, client *http.Client) *App

NewApp returns a new instance of App with config and DB connections loaded

func (*App) CheckFileExistence

func (a *App) CheckFileExistence(ds *document.Service) func(http.ResponseWriter, *http.Request, httprouter.Params)

CheckFileExistence determines whether a file exists at the given path for an account

func (*App) DownloadFile

func (a *App) DownloadFile() func(http.ResponseWriter, *http.Request, httprouter.Params)

DownloadFile handles downloading a file from object storage

func (*App) Index

Index handles creating word embeddings from a multi-part/file upload and indexing it for search purposes

func (*App) Search

Search performs a search on all documents with the given text

func (*App) ServeHTTP

func (a *App) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP satisfies the http handler interface so App can perform as an http server

func (*App) TikaParse

func (a *App) TikaParse(file io.Reader, filename string) (*shared.TikaResponse, error)

TikaParse makes a request to the tikad endpoint to extract the text from a file

type Cfg

type Cfg struct {
	ModelURL            string
	ModelName           string
	ModelVectorDims     int
	TikaURL             string
	StoragePath         string
	IndexKey            string
	AccessKey           string
	ObjectStorageConfig ObjectStorageCfg
}

Cfg represents the app config ModelVectorDims represents how many dimensions a spotify/annoy index should be be (size of sentence embedding returned from ml model)

type ObjectStorageCfg

type ObjectStorageCfg struct {
	URL        string
	BucketName string
	Key        string
	Secret     string
}

ObjectStorageCfg represents configuration passed for connecting to object storage

func (*ObjectStorageCfg) Enabled

func (o *ObjectStorageCfg) Enabled() bool

Enabled checks if ObjectStorageCfg is configured properly

type SearchResponse

type SearchResponse struct {
	Distances []float32               `json:"distances"`
	Documents []document.SearchResult `json:"documents"`
}

SearchResponse is the response body from the search endpoint

Jump to

Keyboard shortcuts

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