Documentation ¶
Index ¶
- type Bookmark
- type MemoryStorage
- func (s MemoryStorage) Count(q Query) (int, error)
- func (s MemoryStorage) Delete(id string) error
- func (s MemoryStorage) GetAll(q Query) ([]Bookmark, error)
- func (s MemoryStorage) GetOne(id string) (Bookmark, error)
- func (s MemoryStorage) GetPage(q Query, skip, limit int) ([]Bookmark, error)
- func (s MemoryStorage) Insert(b *Bookmark) error
- func (s MemoryStorage) Update(b *Bookmark) error
- type MgoStorage
- func (s MgoStorage) Close()
- func (s MgoStorage) Count(q Query) (int, error)
- func (s MgoStorage) Delete(id string) error
- func (s MgoStorage) GetAll(q Query) ([]Bookmark, error)
- func (s MgoStorage) GetOne(id string) (Bookmark, error)
- func (s MgoStorage) GetPage(q Query, skip, limit int) ([]Bookmark, error)
- func (s MgoStorage) Insert(b *Bookmark) error
- func (s MgoStorage) Update(b *Bookmark) error
- type Paginator
- type Query
- type Resource
- func (s Resource) Create(obj interface{}, r api2go.Request) (api2go.Responder, error)
- func (s Resource) Delete(id string, r api2go.Request) (api2go.Responder, error)
- func (s Resource) FindAll(r api2go.Request) (api2go.Responder, error)
- func (s Resource) FindOne(id string, r api2go.Request) (api2go.Responder, error)
- func (s Resource) PaginatedFindAll(r api2go.Request) (uint, api2go.Responder, error)
- func (s Resource) Update(obj interface{}, r api2go.Request) (api2go.Responder, error)
- type Response
- type Storage
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" ] } } }
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) 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
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) Count ¶
func (s MgoStorage) Count(q Query) (int, error)
Count returns the total number of bookmarks specified by query.
func (MgoStorage) GetAll ¶
func (s MgoStorage) GetAll(q Query) ([]Bookmark, error)
GetAll returns the bookmarks specified by query.
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.
type Query ¶
type Query struct {
// contains filtered or unexported fields
}
A Query is used for filtering storage results.
type Resource ¶
type Resource struct {
Storage Storage
}
The Resource struct implements api2go routes.
func (Resource) PaginatedFindAll ¶
PaginatedFindAll satisfies the api2go.PaginatedFindAll interface
type Response ¶
type Response struct { Res interface{} Code int }
The Response struct implements api2go.Responder
func (Response) StatusCode ¶
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.