common

package
v0.0.0-...-f7fdad9 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2019 License: MIT Imports: 26 Imported by: 0

Documentation

Index

Constants

View Source
const (
	UPLOADED_STATE = `video.state == "uploaded" && video.userdata.hydra && video.userdata.hydra.job_state == "completed"`
	HAS_DASH       = `video.userdata.hydra.outputs.dash && video.userdata.hydra.outputs.dash.metadata`
	HAS_HLS        = `video.userdata.hydra.outputs.hls`
)
View Source
const (
	DEFAULT_DB_URL = "postgres://circleci:circleci@localhost:5432/db_test?sslmode=disable"
)
View Source
const ERIS_STAGING_URL = "https://4oiv2vbc7l.execute-api.eu-central-1.amazonaws.com/stage/eris"
View Source
const HEROKU_BASE_URL = "https://api.heroku.com/"

Variables

This section is empty.

Functions

func BytesVal

func BytesVal(bytes int64) (int64, string)

func CheckPid

func CheckPid(pidFile string) (int, error)

func ChunkAndHash

func ChunkAndHash(url string, size int64) string

func CleanCtype

func CleanCtype(ctype string) string

func ConvertArrayInterfaceToString

func ConvertArrayInterfaceToString(list []interface{}) (values []string)

func ConvertFromUUIDFormat

func ConvertFromUUIDFormat(uuid string) string

func ConvertToUUIDFormat

func ConvertToUUIDFormat(uuid string) string

return 32 bytes into 36 bytes xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx

func CopyDir

func CopyDir(srcDir string, dstDir string) (err error)

CopyDir will walk through each file in srcDir, and call CopyFile on that file into dstDir.

func CopyFile

func CopyFile(src string, dst string) (err error)

Copied and modified from https://stackoverflow.com/questions/21060945/simple-way-to-copy-a-file-in-golang CopyFile copies a file from src to dst. If src and dst files exist, and are the same, then return success. Copy the file contents from src to dst.

func CtypeToExt

func CtypeToExt(ctype string) string

func DownloadChunk

func DownloadChunk(url string, size int64) (body []byte, err error)

func DurFromLabel

func DurFromLabel(label string) time.Duration

func DurVal

func DurVal(dur time.Duration) (int, string)

func EmptyJson

func EmptyJson(val json.RawMessage) bool

func ExtToCtype

func ExtToCtype(ext string) string

func FindString

func FindString(list []string, find string) int

func GenerateMD5

func GenerateMD5(file io.Reader, fileSize, maxSize int64) (hash string, hashSize int64)

func GetAwsSignature

func GetAwsSignature(message, secret string) string

func GetDB

func GetDB(def_url ...string) string

func GetDir

func GetDir(u string) string

func GetExtByType

func GetExtByType(assetType string) string

func GetFileExtension

func GetFileExtension(ctype string) string

func GetMetadataStringVal

func GetMetadataStringVal(metadata json.RawMessage, field string) string

Parses the metadata and returns the value of the specified field

func GetMultipartSignature

func GetMultipartSignature(headers, awsSecret string) []byte

Multipart Upload

func GetOsEnv

func GetOsEnv(env string, mandatory bool, defaultValue ...string) (value string)

Get environment variable

func GetTypeByExt

func GetTypeByExt(ext string) string

func IsColor

func IsColor(str string) bool

checks if a string is a valid html color(but without the '#')

func IsNumber

func IsNumber(str string) bool

func IsSSL

func IsSSL(r *http.Request) bool

func Label

func Label(dur time.Duration) string

func LoadFromCache

func LoadFromCache(name string, c Cacheable, obj interface{}) bool

func NewError

func NewError(msg string, args ...interface{}) error

func ParseBool

func ParseBool(key string, urlMap url.Values, defaultValue ...bool) bool

func ParseColor

func ParseColor(key string, urlMap url.Values, defaultValue ...string) string

func ParseDatabaseUrl

func ParseDatabaseUrl(dbUrl string) string

this parses the database url and returns it in the format sqlx.DB expects

func ParseInt

func ParseInt(key string, urlMap url.Values, defaultValue ...int) int

func ParseString

func ParseString(key string, urlMap url.Values, defaultValue ...string) string

func ParseType

func ParseType(type_ string) string

func PurgeFromCache

func PurgeFromCache(name string, c Cacheable) bool

func SaveToCache

func SaveToCache(name string, c Cacheable, obj interface{}) bool

func Timestamp

func Timestamp(t time.Time) string

Timestamp formats a time.Time object in the ISO-8601 format keen expects

func UpdateHerokuVar

func UpdateHerokuVar(authKey, appName string, config interface{}) error

func ValidUUID

func ValidUUID(uuid string) bool

func ValidV2Token

func ValidV2Token(token string) bool

Check if v2 token is expired or not

Types

type Browser

type Browser struct {
	UserAgent string `json:"useragent"`
}

type CDNEvent

type CDNEvent struct {
	CdnName       string `json:"cdn"`
	CreatedAt     string `json:"created_at"`
	HTTPMethod    string `json:"method"`
	ServerIP      string `json:"server_ip"`
	Protocol      string `json:"protocol"`
	Referrer      string `json:"referrer"`
	Filesize      int64  `json:"filesize"`
	BytesRequest  int64  `json:"bytes_request"`
	BytesResponse int64  `json:"bytes_response"`
	Duration      string `json:"duration"`
	StatusCode    string `json:"status"`
	URI           string `json:"url"`
	ProjectId     string `json:"project_uuid"`
	VideoId       string `json:"video_uuid"`
}

type Cacheable

type Cacheable interface {
	GetCacheFile(string) string
	GetCacheAge() time.Duration
}

type Cli

type Cli struct {
	Command  string
	Timeout  time.Duration
	Sleep    time.Duration
	Simulate bool
	Limit    int
	CacheDir string
	CacheAge time.Duration
	Flag     *flag.FlagSet
	Args     map[string]interface{}
}

func NewCli

func NewCli() Cli

func (*Cli) DefaultSetup

func (c *Cli) DefaultSetup(msg, def string)

func (*Cli) GetBool

func (c *Cli) GetBool(name string) bool

func (Cli) GetCacheAge

func (c Cli) GetCacheAge() time.Duration

func (Cli) GetCacheFile

func (c Cli) GetCacheFile(name string) string

func (*Cli) GetFilter

func (c *Cli) GetFilter(fta ...string) (filter string, filterType string)

func (*Cli) GetInt

func (c *Cli) GetInt(name string) int

func (*Cli) GetSeconds

func (c *Cli) GetSeconds(name string) time.Duration

func (*Cli) GetSleep

func (c *Cli) GetSleep() time.Duration

func (*Cli) GetString

func (c *Cli) GetString(name string) string

func (*Cli) GetTime

func (c *Cli) GetTime(name string, dur time.Duration) time.Duration

func (*Cli) Int

func (c *Cli) Int(name string, def int, desc string)

func (*Cli) Parse

func (c *Cli) Parse(args ...[]string)

func (Cli) Printf

func (c Cli) Printf(msg string, args ...interface{})

func (Cli) Println

func (c Cli) Println(msg string)

func (*Cli) String

func (c *Cli) String(name, def, desc string)

type Email

type Email struct {
	EmailUrl string
	Request  EmailRequest
	Response EmailResponse
}

func NewEmail

func NewEmail(emailUrl ...string) Email

func (*Email) Send

func (e *Email) Send() error

func (*Email) SetMsgAndSend

func (e *Email) SetMsgAndSend(message string) error

func (Email) Validate

func (e Email) Validate() error

type EmailRequest

type EmailRequest struct {
	Service   string                 `json:"service"`
	EmailType string                 `json:"email_type"` // ERROR, INFO, or if template, use template ID
	Message   string                 `json:"message"`    // required for ERROR or INFO
	Body      map[string]interface{} `json:"body"`       // required except for ERROR and INFO
}

type EmailResponse

type EmailResponse struct {
	StatusCode int                 `json:"statusCode"`
	Message    string              `json:"message"`
	Errors     map[string][]string `json:"error"`
}

type ExecObj

type ExecObj struct {
	Cmd *exec.Cmd

	ReadOut []byte
	ReadErr []byte
	RunErr  error
	Err     SynqError
	// contains filtered or unexported fields
}

func NewExec

func NewExec(command string, args ...string) ExecObj

func (*ExecObj) Close

func (e *ExecObj) Close()

func (*ExecObj) ErrorMsg

func (e *ExecObj) ErrorMsg() string

func (*ExecObj) Exec

func (e *ExecObj) Exec(fn func(io.WriteCloser))

func (*ExecObj) MarshalError

func (e *ExecObj) MarshalError() (body []byte)

func (*ExecObj) Open

func (e *ExecObj) Open() error

func (*ExecObj) Read

func (e *ExecObj) Read() error

func (*ExecObj) StatusBody

func (e *ExecObj) StatusBody() []byte

func (*ExecObj) StatusCode

func (e *ExecObj) StatusCode() int

type GeoInfo

type GeoInfo struct {
	City        string    `json:"city"`
	State       string    `json:"state"`
	Country     string    `json:"country"`
	Continent   string    `json:"continent"`
	Coordinates [2]string `json:"coordinates"` // [longitude, latitude]
}

type GeoLocation

type GeoLocation struct {
	GeoInfo   GeoInfo `json:"info"`
	IpAddress string  `json:"ip_address"`
}

type HerokuResponse

type HerokuResponse struct {
	Id      string `json:"id"`
	Message string `json:"message"`
}

type KeenClient

type KeenClient struct {
	WriteKey   string
	ReadKey    string
	ProjectId  string
	Collection string
	Url        string
	HttpClient http.Client
	Events     map[string][]KeenEvent
}

func (*KeenClient) AddEvent

func (c *KeenClient) AddEvent(event KeenEvent) ([]byte, error)

func (*KeenClient) AddEvents

func (c *KeenClient) AddEvents(events map[string][]KeenEvent) ([]byte, error)

func (*KeenClient) Request

func (c *KeenClient) Request(method, path string, payload interface{}) (*http.Response, error)

func (*KeenClient) Response

func (c *KeenClient) Response(resp *http.Response) ([]byte, error)

type KeenEvent

type KeenEvent struct {
	Keen        KeenProperties `json:"keen"`
	CDNEvent    CDNEvent       `json:"cdn_event"`
	GeoLocation GeoLocation    `json:"geo"`
	Browser     Browser        `json:"browser"`
}

type KeenProperties

type KeenProperties struct {
	Timestamp string `json:"timestamp"`
}

type Ret

type Ret struct {
	Label    string
	CountMap map[string]int
	Error    error
	Start    time.Time
	DurMap   map[string]time.Duration
	BytesMap map[string]int64
	IdMap    map[string][]string
}

func NewRet

func NewRet(label string) Ret

func (*Ret) Add

func (r *Ret) Add(type_ string)

func (*Ret) AddBytes

func (r *Ret) AddBytes(bytes int64)

func (*Ret) AddBytesFor

func (r *Ret) AddBytesFor(key string, bytes int64)

func (*Ret) AddDurFor

func (r *Ret) AddDurFor(key string, dur time.Duration)

func (*Ret) AddError

func (r *Ret) AddError(err error) bool

func (*Ret) AddFor

func (r *Ret) AddFor(type_ string, ct int)

func (*Ret) AddForSave

func (r *Ret) AddForSave(key string, id string)

func (*Ret) Bytes

func (r *Ret) Bytes(type_ string) int64

func (*Ret) Duration

func (r *Ret) Duration(type_ string) time.Duration

func (*Ret) Eq

func (r *Ret) Eq(type_ string, ct int) bool

func (*Ret) GetErrorString

func (r *Ret) GetErrorString() string

func (*Ret) Gt

func (r *Ret) Gt(type_ string, ct int) bool

func (*Ret) Gte

func (r *Ret) Gte(type_ string, ct int) bool

func (*Ret) IsErrored

func (r *Ret) IsErrored() bool

func (*Ret) LimitReached

func (r *Ret) LimitReached(limit int) bool

func (*Ret) Lt

func (r *Ret) Lt(type_ string, ct int) bool

func (*Ret) Lte

func (r *Ret) Lte(type_ string, ct int) bool

func (*Ret) Print

func (r *Ret) Print()

func (*Ret) Save

func (r *Ret) Save(dir string) error

This will save any id entries to disk

func (*Ret) Speed

func (r *Ret) Speed() string

func (*Ret) String

func (r *Ret) String() string

func (*Ret) Taken

func (r *Ret) Taken(tDur ...time.Duration) (int, string)

This will determine the right value to use

func (*Ret) Value

func (r *Ret) Value(type_ string) int

type SynqError

type SynqError struct {
	Name    string           `json:"name"`
	Message string           `json:"message"`
	Url     string           `json:"url"`
	Details *json.RawMessage `json:"details"`
}

Jump to

Keyboard shortcuts

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