Skip to content

Commit

Permalink
Version 0.0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
kiljacken committed Mar 18, 2015
0 parents commit 9bf147f
Show file tree
Hide file tree
Showing 9 changed files with 1,683 additions and 0 deletions.
27 changes: 27 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# YACC
y.output

# Compiled Object files, Static and Dynamic libs (Shared Objects)
*.o
*.a
*.so

# Folders
_obj
_test

# Architecture specific extensions/prefixes
*.[568vq]
[568vq].out

*.cgo1.go
*.cgo2.c
_cgo_defun.c
_cgo_gotypes.go
_cgo_export.*

_testmain.go

*.exe
*.test
*.prof
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# tagger
98 changes: 98 additions & 0 deletions api.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
package tagger

import (
"code.google.com/p/go-uuid/uuid"
"errors"
"io"
)

type (
// StorageProvider specifies the interface that must be implemented by tag storage backends.
StorageProvider interface {
io.Closer

GetFile(u uuid.UUID) (File, error)
GetFileForPath(path string) (File, error)
GetAllFiles() ([]File, error)
GetMatchingFiles(f Filter) ([]File, error)

UpdateTag(f File, t Tag) error
RemoveTag(f File, t Tag) error
GetTags(f File) ([]Tag, error)
// GetAllTags() ([]Tag, error) // TODO: Reconsider this method. Maybe split into two? (tags, values)

UpdateFile(f File, t []Tag) error
RemoveFile(f File) error
}

// File is a structure that represents a file in the database
File struct {
uuid uuid.UUID
path string
}

// Tag is an interface representing the needed methods on a tag
Tag interface {
Name() string
HasValue() bool
Value() int
}

// NamedTag is a tag with just a name
NamedTag struct {
name string
}

// ValueTag is a tag with both a name and a value
ValueTag struct {
name string
value int
}
)

// NewFile creates a new file struct an populates it's fields
func NewFile(uuid_ uuid.UUID, path string) File {
return File{uuid: uuid_, path: path}
}

// NewNamedTag creates a new NamedTag struct an populates it's fields
func NewNamedTag(name string) *NamedTag {
return &NamedTag{name: name}
}

// NewValueTag creates a new ValueTag struct an populates it's fields
func NewValueTag(name string, value int) *ValueTag {
return &ValueTag{name: name, value: value}
}

// UUID returns the UUID of a file
func (f File) UUID() uuid.UUID { return f.uuid }

// Path returns the path of a file
func (f File) Path() string { return f.path }

// Name returns the name of a tag
func (t NamedTag) Name() string { return t.name }

// Name returns the name of a tag
func (t ValueTag) Name() string { return t.name }

// HasValue returns whether the tag has a value
func (t NamedTag) HasValue() bool { return false }

// HasValue returns whether the tag has a value
func (t ValueTag) HasValue() bool { return true }

// Value returns -1 on a named tag
func (t NamedTag) Value() int { return -1 }

// Value returns the value of a value tag
func (t ValueTag) Value() int { return t.value }

// Errors
var (
ErrNoFile = errors.New("tagger: No such file in storage")
ErrNoTag = errors.New("tagger: No such tag on file")
ErrNoMatches = errors.New("tagger: No matching files in storage")
ErrInvalidValue = errors.New("tagger: Invalid tag value")
)
Loading

0 comments on commit 9bf147f

Please sign in to comment.