bookmark

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Sep 4, 2017 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Bookmark

type Bookmark struct {
	ID          bson.ObjectId `json:"-" bson:"_id,omitempty"`
	Title       string        `json:"title"`
	URL         string        `json:"url"`
	Description string        `json:"description" bson:",omitempty"`
	Timestamp   time.Time     `json:"timestamp"`
	Tags        []string      `json:"tags"`
}

Bookmark represents a bookmark.

Example
timestamp := time.Date(2009, time.November, 10, 23, 0, 0, 0, time.UTC)
b := Bookmark{
	Title:       "The Title",
	URL:         "http://example.com",
	Description: "A Description.",
	Timestamp:   timestamp,
	Tags:        []string{"foo", "bar"},
}
if err := b.SetID("572135023cd994201b0bb61c"); err != nil {
	log.Fatal(err)
}
result, err := jsonapi.Marshal(b)
if err != nil {
	return
}
var out bytes.Buffer
if err := json.Indent(&out, result, "", "  "); err != nil {
	log.Fatal(err)
}
if _, err := out.WriteTo(os.Stdout); err != nil {
	log.Fatal(err)
}
Output:

{
  "data": {
    "type": "bookmarks",
    "id": "572135023cd994201b0bb61c",
    "attributes": {
      "title": "The Title",
      "url": "http://example.com",
      "description": "A Description.",
      "timestamp": "2009-11-10T23:00:00Z",
      "tags": [
        "foo",
        "bar"
      ]
    }
  }
}

func (Bookmark) GetID

func (b Bookmark) GetID() string

GetID to satisfy jsonapi.MarshalIdentifier interface

func (*Bookmark) SetID

func (b *Bookmark) SetID(id string) error

SetID to satisfy jsonapi.UnmarshalIdentifier interface

func (Bookmark) String

func (b Bookmark) String() string

type MemoryStorage

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

MemoryStorage stores all users

func NewMemoryStorage

func NewMemoryStorage() *MemoryStorage

NewMemoryStorage initializes the storage

func (MemoryStorage) Count

func (s MemoryStorage) Count(q Query) (int, error)

Count returns total number of bookmarks. WARNING: ignores query.

func (MemoryStorage) Delete

func (s MemoryStorage) Delete(id string) error

Delete one :(

func (MemoryStorage) GetAll

func (s MemoryStorage) GetAll(q Query) ([]Bookmark, error)

GetAll returns the user map. WARNING: ignores query.

func (MemoryStorage) GetOne

func (s MemoryStorage) GetOne(id string) (Bookmark, error)

GetOne user

func (MemoryStorage) GetPage

func (s MemoryStorage) GetPage(q Query, skip, limit int) ([]Bookmark, error)

GetPage returns a portion of bookmarks specified by query. WARNING: not implemented

func (MemoryStorage) Insert

func (s MemoryStorage) Insert(b *Bookmark) error

Insert a user

func (MemoryStorage) Update

func (s MemoryStorage) Update(b *Bookmark) error

Update a user

type MgoStorage

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

MgoStorage stores all users

func NewMgoStorage

func NewMgoStorage(uri string) (MgoStorage, error)

NewMgoStorage initializes the storage

func (MgoStorage) Close

func (s MgoStorage) Close()

Close will close the master session

func (MgoStorage) Count

func (s MgoStorage) Count(q Query) (int, error)

Count returns the total number of bookmarks specified by query.

func (MgoStorage) Delete

func (s MgoStorage) Delete(id string) error

Delete one :(

func (MgoStorage) GetAll

func (s MgoStorage) GetAll(q Query) ([]Bookmark, error)

GetAll returns the bookmarks specified by query.

func (MgoStorage) GetOne

func (s MgoStorage) GetOne(id string) (Bookmark, error)

GetOne user

func (MgoStorage) GetPage

func (s MgoStorage) GetPage(q Query, skip, limit int) ([]Bookmark, error)

GetPage returns a portion of bookmarks specified by query.

func (MgoStorage) Insert

func (s MgoStorage) Insert(b *Bookmark) error

Insert a user and set Timestamp to insert time if not already set.

func (MgoStorage) Update

func (s MgoStorage) Update(b *Bookmark) error

Update a user and updates Timestamp.

type Paginator

type Paginator struct {
	Skip, Limit int
}

Paginator handles page skip and limit calculations.

func NewPaginator

func NewPaginator(r api2go.Request) (*Paginator, error)

NewPaginator returns initialized Paginator. number and size: number starts at 1, size is page size. offset and limit: offset starts at 0, limit is page size.

type Query

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

A Query is used for filtering storage results.

func NewQuery

func NewQuery(r api2go.Request) Query

NewQuery parses the request query parameters into a filtering query.

func (Query) Mgo

func (q Query) Mgo() bson.M

Mgo provides the query for the Mgo driver

type Resource

type Resource struct {
	Storage Storage
}

The Resource struct implements api2go routes.

func (Resource) Create

func (s Resource) Create(obj interface{}, r api2go.Request) (api2go.Responder, error)

Create satisfies api2go.CRUD interface

func (Resource) Delete

func (s Resource) Delete(id string, r api2go.Request) (api2go.Responder, error)

Delete satisfies api2go.CRUD interface

func (Resource) FindAll

func (s Resource) FindAll(r api2go.Request) (api2go.Responder, error)

FindAll satisfies api2go.FindAll interface

func (Resource) FindOne

func (s Resource) FindOne(id string, r api2go.Request) (api2go.Responder, error)

FindOne satisfies api2go.CRUD interface

func (Resource) PaginatedFindAll

func (s Resource) PaginatedFindAll(r api2go.Request) (uint, api2go.Responder, error)

PaginatedFindAll satisfies the api2go.PaginatedFindAll interface

func (Resource) Update

func (s Resource) Update(obj interface{}, r api2go.Request) (api2go.Responder, error)

Update satisfies api2go.CRUD interface

type Response

type Response struct {
	Res  interface{}
	Code int
}

The Response struct implements api2go.Responder

func (Response) Metadata

func (r Response) Metadata() map[string]interface{}

Metadata returns additional meta data

func (Response) Result

func (r Response) Result() interface{}

Result returns the actual payload

func (Response) StatusCode

func (r Response) StatusCode() int

StatusCode sets the return status code

type Storage

type Storage interface {
	// GetAll returns bookmarks specified by query in decending date order.
	GetAll(q Query) ([]Bookmark, error)

	// GetPage returns a portion of bookmarks specified by query.
	GetPage(q Query, skip, limit int) ([]Bookmark, error)

	// Count returns the total number of bookmarks specified by query.
	Count(q Query) (int, error)

	// GetOne returns the bookmark with the specified id
	GetOne(id string) (Bookmark, error)

	// Insert adds a bookmark to the database
	Insert(b *Bookmark) error

	// Delete removes a bookmark from the database
	Delete(id string) error

	// Update modifies an existing bookmark
	Update(b *Bookmark) error
}

Storage abstracts database interactions.

Jump to

Keyboard shortcuts

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