common

package
v0.0.0-...-1871c23 Latest Latest
Warning

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

Go to latest
Published: May 24, 2017 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ES_HOST = "127.0.0.1"
	ES_PORT = "9200"
)
View Source
const (
	// Api key and log type regex
	ApiKeyFormat = `^([a-z0-9]{8}-[a-z0-9]{4}-[1-5][a-z0-9]{3}-[a-z0-9]{4}-[a-z0-9]{12})@([a-z0-9\_]{1,20})`
)

Variables

View Source
var (
	ErrSendingElasticSearchRequest = errors.New("Error sending request to ES.")
	ErrCreatingHttpRequest         = errors.New("Could not create http.NewRequest")
	ErrReadResponse                = errors.New("Could not read ES response")
	ErrDecodingJson                = errors.New("Error decoding ES response")
)
View Source
var (
	ErrExtractingKey = errors.New("Error extracting key and type")
)

Functions

func AppPath

func AppPath(elem ...string) string

Builds full path to application based on $GOPATH

func CompareHashAndPassword

func CompareHashAndPassword(hash, password string) error

func CountTypeDocs

func CountTypeDocs(index string, logType string) float64

Count documents in collection

func DeleteType

func DeleteType(index string, logType string)

func ExtractApiKey

func ExtractApiKey(message string) (string, string, error)

Extracts api key and log type from string

func GetConnection

func GetConnection() *goes.Connection

func GetTypes

func GetTypes(index string) ([]string, error)

Retuns list of types available in search index

func HashPassword

func HashPassword(password string) (string, error)

func RemoveApiKey

func RemoveApiKey(message string) string

Removes api key and log type from string

func SendToElastic

func SendToElastic(url string, method string, b []byte) (string, error)

Send raw bytes to elastic search server TODO: Bulk processing

Types

type EnableValidation

type EnableValidation struct {
	Valid validation.Validation
}

func (*EnableValidation) GetError

func (this *EnableValidation) GetError(key string) string

type IndexMapping

type IndexMapping map[string]map[string]map[string]interface{}

type LogRecord

type LogRecord struct {
	Datetime time.Time `json:"datetime"`
	Message  string    `json:"message"`
}

type Project

type Project struct {
	Id          string   `json:"id"`
	Name        string   `json:"name"`
	Description string   `json:"description"`
	Types       []string `json:"types"`
}

Project represent group of log types. Each log type can be in various groups at the same time.

type User

type User struct {
	Id        string     `json:"id"`
	Email     string     `json:"email"`
	FirstName string     `json:"firstName"`
	LastName  string     `json:"lastName"`
	Password  string     `json:"password"`
	ApiKey    string     `json:"apiKey"`
	Projects  []*Project `json:"projects"`
}

func FindCachedUser

func FindCachedUser(email string) (*User, error)

Search user and store record in memory

func FindUserBy

func FindUserBy(key string, value string) (*User, error)

Find user by any param. Returns err if ES can't perform/accept query, and nil if user not found.

func FindUserByApiKey

func FindUserByApiKey(apiKey string) (*User, error)

func FindUserByEmail

func FindUserByEmail(email string) (*User, error)

func (*User) AddProject

func (u *User) AddProject(p *Project) *User

func (*User) DeleteProject

func (u *User) DeleteProject(id string)

func (*User) GetIndexName

func (u *User) GetIndexName() string

Returns index name to use in Elastic

func (*User) GetLogTypes

func (u *User) GetLogTypes() []string

Returns elastic search types

func (*User) GetProject

func (u *User) GetProject(id string) (*Project, error)

func (*User) Save

func (this *User) Save()

func (*User) UpdateProject

func (u *User) UpdateProject(p *Project)

Jump to

Keyboard shortcuts

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