crate

package
v0.0.0-...-8f60130 Latest Latest
Warning

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

Go to latest
Published: Jan 26, 2015 License: Apache-2.0 Imports: 26 Imported by: 0

Documentation

Index

Constants

View Source
const (
	UnknownHost = "unknown"
	JSONLayout  = "2006-01-02T15:04:05-07:00"
)
View Source
const Anonymous = "anonymous"
View Source
const (
	ExifTimeLayout = "2006:01:02 15:04:05" // Time layout for EXIF data type
)

Variables

View Source
var (
	GPSTimePattern = regexp.MustCompile("\"(\\d+)/\\d+\"")
)
View Source
var (
	Magic *magicmime.Magic
)

Functions

func CloseDatabase

func CloseDatabase() error

Close the database -- useful for defering close

func CloseLoggers

func CloseLoggers() error

Close the loggers (and the open file handle) useful for defering close

func FetchKeys

func FetchKeys(limit int) []string

Return a slice of keys limited by the argument

func Ftoa

func Ftoa(num float64) string

Convert a Float to a string

func Hash

func Hash(data []byte) string

Compute the Base64 encoded SHA1 hash of the data

func Hostname

func Hostname() string

Return the hostname of the machine

func InitMagic

func InitMagic() error

func InitializeConsole

func InitializeConsole() error

func InitializeDatabase

func InitializeDatabase() error

Initialize the database in the config location

func InitializeLoggers

func InitializeLoggers(level LogLevel) error

Initialize the Logger objects for logging to config location

func JSONStamp

func JSONStamp(t time.Time) string

Convert a time.Time to a JSON timestamp

func Log

func Log(msg string, level LogLevel, args ...interface{})

Write a log message to the eventLogger at a certain log level

func MimeType

func MimeType(path string) (string, error)

Use libmagic to determine the MimeType of the file

func PathExists

func PathExists(path string) (bool, error)

Check if a string pathname exists (prerequsite to NewPath)

Types

type Console

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

Handles the writing to the console

func (*Console) Err

func (console *Console) Err(str string, err error, args ...interface{})

Writes error messages out to the default logger

func (*Console) Fatal

func (console *Console) Fatal(str string, args ...interface{})

Fatal, writes error message out and quits

func (*Console) Info

func (console *Console) Info(str string, args ...interface{})

Logs to the default logger if debug is set to true

func (*Console) Init

func (console *Console) Init(debug bool)

Initializes a new Console object

func (*Console) Log

func (console *Console) Log(str string, args ...interface{})

Writes a format string and arguments as a newline to stdout

type CrateService

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

func (*CrateService) Backup

func (service *CrateService) Backup(dirPath string)

Runs the backup utility service on a specified directory

func (*CrateService) Init

func (service *CrateService) Init()

Initialize all the various services, remember to also defer close!

type Dir

type Dir struct {
	Node
	Name     string    // The base name of the directory
	Modified time.Time // The modified time of the directory
	// contains filtered or unexported fields
}

func (*Dir) Byte

func (dir *Dir) Byte() []byte

func (*Dir) Join

func (dir *Dir) Join(elem ...string) string

func (*Dir) List

func (dir *Dir) List() ([]Path, error)

func (*Dir) Populate

func (dir *Dir) Populate()

func (*Dir) Walk

func (dir *Dir) Walk(walkFn WalkFunc) error

Implements a recrusive walk of a directory

type DirPath

type DirPath interface {
	Join(elem ...string) string // Join path elements to the current path
	List() ([]Path, error)      // Return a list of the Paths in the directory
	Walk(walkFn WalkFunc) error // Walk a directory with the walk function
	Populate()                  // Populates the info on the dir path (does a lot of work)
}

type ExifHandler

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

Implements the Walker interface to retrieve all tags

func (*ExifHandler) Coordinates

func (ew *ExifHandler) Coordinates() (float64, float64, error)

Helper function for the GPS Coordinates

func (*ExifHandler) DateTaken

func (ew *ExifHandler) DateTaken() (time.Time, error)

Helper function for the date taken - overloads the exif library DateTime

func (*ExifHandler) GPSDateTime

func (ew *ExifHandler) GPSDateTime() (time.Time, error)

Helper function to fetch the GPS date and time

func (*ExifHandler) Get

func (ew *ExifHandler) Get(tag exif.FieldName) string

Retrieves a tag from the exif data in the handler

func (*ExifHandler) Walk

func (ew *ExifHandler) Walk(name exif.FieldName, tag *tiff.Tag) error

Implements the Walk function to be a Walker

type FileMeta

type FileMeta struct {
	Node
	MimeType  string    // The mimetype of the file
	Name      string    // The base name of the file
	Size      int64     // The size of the file in bytes
	Modified  time.Time // The last modified time
	LastSeen  time.Time // The last time that Crate saw the file
	Signature string    // Base64 encoded SHA1 hash of the file
	Host      string    // The hostname of the computer
	Author    string    // The User or username of the file creator
	// contains filtered or unexported fields
}

func (*FileMeta) Base

func (fm *FileMeta) Base() string

Returns the basename of the file (including extension)

func (*FileMeta) Byte

func (fm *FileMeta) Byte() []byte

Returns the byte serialization of the file meta for storage

func (*FileMeta) Ext

func (fm *FileMeta) Ext() string

Returns the extension of the file

func (*FileMeta) Hash

func (fm *FileMeta) Hash() (string, error)

Computes the SHA1 hash of the file by using IO copy for memory safety

func (*FileMeta) Info

func (fm *FileMeta) Info() string

Prints out the info as a JSON indented pretty string

func (*FileMeta) IsImage

func (fm *FileMeta) IsImage() bool

Checks if a FileMeta is an image

func (*FileMeta) Populate

func (fm *FileMeta) Populate()

Populates the fields on the FileMeta

func (*FileMeta) Store

func (fm *FileMeta) Store() error

Writes the FileMeta to the database, where the key is the SHA1 hash

type FilePath

type FilePath interface {
	IsImage() bool // The File is an image
	Ext() string   // The extension (if a file, empty string if not)
	Base() string  // The base name of the path
	Populate()     // Populates the info on the file path (does a lot of work)
	Info() string  // Returns a JSON serialized print of the file info
	Store() error  // Store the meta data to a database
}

func Fetch

func Fetch(key string) (FilePath, error)

Fetch the FileMeta or ImageMeta from the specified hash

type ImageMeta

type ImageMeta struct {
	FileMeta
	Width  int               // Width of the image
	Height int               // Height of the image
	Tags   map[string]string // Image tags from the Exif data
}

func ConvertImageMeta

func ConvertImageMeta(fm *FileMeta) (*ImageMeta, bool)

Converts a FileMeta into an ImageMeta

func (*ImageMeta) Byte

func (img *ImageMeta) Byte() []byte

Returns the byte serialization of the file meta for storage

func (*ImageMeta) Dimensions

func (img *ImageMeta) Dimensions() (int, int, error)

Returns the width, hight of the image

func (*ImageMeta) GetExif

func (img *ImageMeta) GetExif() (*ExifHandler, bool)

Get the EXIF Data from the JPEG

func (*ImageMeta) Info

func (img *ImageMeta) Info() string

Prints out the info as a JSON indented pretty string

func (*ImageMeta) IsJPEG

func (img *ImageMeta) IsJPEG() bool

Checks if an Image is a JPEG file

func (*ImageMeta) Populate

func (img *ImageMeta) Populate()

Popluates the fields on the ImageMeta

func (*ImageMeta) Store

func (img *ImageMeta) Store() error

Writes the ImageMeta to the database, where the key is the SHA1 hash

type LogLevel

type LogLevel int

LogLevel types

const (
	LevelDebug LogLevel = 1 + iota
	LevelInfo
	LevelWarn
	LevelError
	LevelFatal
)

func LevelFromString

func LevelFromString(level string) LogLevel

func (LogLevel) String

func (level LogLevel) String() string

type Logger

type Logger struct {
	Level LogLevel // The minimum log level to log at
	// contains filtered or unexported fields
}

Wraps the log.Logger to provide custom log handling

func (*Logger) Close

func (logger *Logger) Close() error

Close the open handle to the log file and stop logging

func (*Logger) Debug

func (logger *Logger) Debug(msg string, args ...interface{})

Helper function to log at debug level

func (*Logger) Error

func (logger *Logger) Error(msg string, args ...interface{})

Helper function to log at debug level

func (*Logger) Fatal

func (logger *Logger) Fatal(msg string, args ...interface{})

Helper function to log at debug level

func (*Logger) Info

func (logger *Logger) Info(msg string, args ...interface{})

Helper function to log at info level

func (*Logger) Log

func (logger *Logger) Log(layout string, level LogLevel, args ...interface{})

Write a log message to the logger with a certain log level

func (*Logger) SetOutputPath

func (logger *Logger) SetOutputPath(path string) error

Set a new log output location on the Logger

func (*Logger) Warn

func (logger *Logger) Warn(msg string, args ...interface{})

Helper function to log at debug level

type Node

type Node struct {
	Path string // Current path of the node
}

A file system entity

func (*Node) Byte

func (node *Node) Byte() []byte

func (*Node) Dir

func (node *Node) Dir() *Dir

func (*Node) IsDir

func (node *Node) IsDir() bool

func (*Node) IsFile

func (node *Node) IsFile() bool

func (*Node) IsHidden

func (node *Node) IsHidden() bool

func (*Node) Stat

func (node *Node) Stat() (os.FileInfo, error)

func (*Node) String

func (node *Node) String() string

func (*Node) User

func (node *Node) User() (*user.User, error)

type Path

type Path interface {
	IsDir() bool                // Path is a directory
	IsFile() bool               // Path is a file
	IsHidden() bool             // Path is a hidden file or directory
	Dir() *Dir                  // The parent directory of the path
	Stat() (os.FileInfo, error) // Returns the attributes of the path
	User() (*user.User, error)  // Returns the User object for the path
	String() string             // The string representation of the file
	Byte() []byte               // The byte representation of the JSON
}

func NewPath

func NewPath(path string) (Path, error)

Create either a FileMeta or a Dir from a pathname

type WalkFunc

type WalkFunc func(path Path, err error) error

Type of the Walk Function for DirPath.Walk

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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