-
Notifications
You must be signed in to change notification settings - Fork 0
/
category.go
43 lines (37 loc) · 845 Bytes
/
category.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package models
import (
"cloud.google.com/go/datastore"
"golang.org/x/net/context"
"github.com/VoidArtanis/wallpaper/shared"
"fmt"
)
type Categories struct {
Data []Category
}
type Category struct {
Title string
Description string
Thumb string
}
func (this *Categories) Save() (err error) {
key := datastore.IncompleteKey(this.kind(), nil)
ctx := context.Background()
if _, err := shared.DatastoreClient.Put(ctx, key, this); err != nil {
fmt.Println(err)
return err
}
return nil
}
func (this *Categories) kind() (str string) {
return "category"
}
func GetAllCategories()(objs *Categories, err error){
q := datastore.NewQuery(objs.kind())
ctx := context.Background()
var data []Categories
_, er := shared.DatastoreClient.GetAll(ctx , q,&data )
if er != nil {
return nil, er
}
return &data[0], nil
}