Ejemplo n.º 1
0
// Save will put this AccessToken into Datastore using the given key.
func (x AccessToken) Save(ctx context.Context, key ...*datastore.Key) (*datastore.Key, error) {
	if len(key) > 1 {
		panic("zero or one key expected")
	}

	if len(key) == 1 && key[0] != nil {
		return datastore.Put(ctx, key[0], &x)
	}

	return datastore.Put(ctx, datastore.NewIncompleteKey(ctx, AccessTokenKind, nil), &x)
}
Ejemplo n.º 2
0
// LogBuildStart sends info to the datastore, informing that a new build
// started
func LogBuildStart(challenge string, commit string, user string) (*datastore.Key, *BuildData) {
	key := datastore.NewIncompleteKey(ctx, buildKind, nil)
	build := &BuildData{challenge, user, commit, "started", time.Now(), time.Unix(0, 0)}

	key, err := datastore.Put(ctx, key, build)
	if err != nil {
		fmt.Fprintf(os.Stderr, "LogBuildStart: %v", err)
	}
	return key, build
}
Ejemplo n.º 3
0
Archivo: akc.go Proyecto: coduno/tools
func putAuthorizedKey(ak *AuthorizedKey, username string) (err error) {
	ctx, err := connect()
	if err != nil {
		return
	}

	var coder Coder
	it := datastore.NewQuery(coderKind).Filter("Nickname =", username).Limit(1).Run(ctx)
	ck, err := it.Next(&coder)
	if err != nil {
		return
	}

	ak.Coder = ck

	dk := datastore.NewIncompleteKey(ctx, keyKind, nil)
	_, err = datastore.Put(ctx, dk, ak)

	return
}
Ejemplo n.º 4
0
func ExamplePut() {
	ctx := Example_auth()

	type Article struct {
		Title       string
		Description string
		Body        string `datastore:",noindex"`
		Author      *datastore.Key
		PublishedAt time.Time
	}
	newKey := datastore.NewIncompleteKey(ctx, "Article", nil)
	_, err := datastore.Put(ctx, newKey, &Article{
		Title:       "The title of the article",
		Description: "The description of the article...",
		Body:        "...",
		Author:      datastore.NewKey(ctx, "Author", "jbd", 0, nil),
		PublishedAt: time.Now(),
	})
	if err != nil {
		log.Fatal(err)
	}
}
Ejemplo n.º 5
0
// SaveWithParent can be used to save this AccessToken as child of another
// entity.
// This will error if parent == nil.
func (x AccessToken) SaveWithParent(ctx context.Context, parent *datastore.Key) (*datastore.Key, error) {
	if parent == nil {
		return nil, errors.New("parent key is nil, expected a valid key")
	}
	return datastore.Put(ctx, datastore.NewIncompleteKey(ctx, AccessTokenKind, parent), &x)
}