horsefeather

package module
v1.2.3 Latest Latest
Warning

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

Go to latest
Published: Apr 4, 2016 License: Apache-2.0 Imports: 18 Imported by: 0

README

horsefeather

GoDoc
Build Status
Coverage Status
License

horsefeather is a Google Appengine Engine extension that adds functionality through tags to handle saving and loading datastore models differently. horsefeather as of v1.1 contains helper functions for basic manipulation of datastore operations. It operates like NDB from Python Appengine.

Installation

The import path for the package is gopkg.in/SeanDolphin/horsefeather.v1.

To install it, run:

go get gopkg.in/SeanDolphin/horsefeather.v1

Usage

Tags
package somepackage

import (
	"gopkg.in/SeanDolphin/horsefeather.v1"
	"google.golang.org/appengine/datastore"

	"time"
)

type Person struct{
	Key    		*datastore.Key
	Name 		FullName 		`datastore:"-" hf:"opaque"`			//saves this property as a json string
	Address    	*Address  		`datastore:"-" hf:"compress,crc"`	//compresses this property and calculates and crc
	AddressCRC	string			`datastore:",noindex"`				//set by horsefeather crc above
	Updated 	time.TIme 		`hf:"timestamp"`					//updated on save with current timestamp
}

func (person *Content) Load(input []datastore.Property) error {
	return horsefeather.LoadStruct(person, input)
}

func (person *Content) Save() ([]datastore.Property, error) {
	return horsefeather.SaveStruct(person)
}

type FullName struct{
	First	string
	Last 	string
}

type Address struct {
	Street  string
	City    string
	State   string
	Zipcode string
}
Helpers

Setting up is as simple as calling hfae on the context you are using.

	ctx = hfae.Set(ctx) 

The calls then work as normal calls would work except it works with memcache, datastore and a local cache in unison.

package somepackage

type Person struct{
	Key    		*datastore.Key
	Name 		FullName 						
	Updated 	time.TIme 		
}

func DoSometask(ctx context.Context){
	var person Person
	err := hs.Get(ctx, key, &person)
}

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrEntityToLarge = errors.New("entity to large to save")
View Source
var ErrIncompleteKey = errors.New("Key imcomplete but used a complete key.")
View Source
var ErrInvalidEntityType = errors.New("invalid entity type")

ErrInvalidEntityType is returned when functions like Get or Next are passed a dst or src argument of invalid type.

View Source
var ErrInvalidKey = errors.New("invalid key")

ErrInvalidKey is returned when an invalid key is presented.

View Source
var ErrNoContext = errors.New("context does not exist")
View Source
var ErrNoSuchEntity = errors.New("no such entity")

ErrNoSuchEntity is returned when no entity was found for a given key.

Functions

func AddDatastore

func AddDatastore(ctx context.Context, ds Datastore) context.Context

func AddMemcache

func AddMemcache(ctx context.Context, mc Memcache) context.Context

func Delete

func Delete(ctx context.Context, key *datastore.Key) error

func DeleteMulti

func DeleteMulti(ctx context.Context, keys []*datastore.Key) error

func Get

func Get(ctx context.Context, key *datastore.Key, dst interface{}) error

func GetMulti

func GetMulti(ctx context.Context, keys []*datastore.Key, dst interface{}) error

func IsDatastoreAllowed added in v1.2.0

func IsDatastoreAllowed(ctx context.Context) bool

func IsMemcacheAllowed added in v1.2.0

func IsMemcacheAllowed(ctx context.Context) bool

func LoadStruct

func LoadStruct(dst interface{}, input []datastore.Property) error

LoadStruct helps load a struct from a datastore.Property channel

func OnlyDatastore added in v1.2.0

func OnlyDatastore(ctx context.Context, flag bool) context.Context

func OnlyMemcache added in v1.2.0

func OnlyMemcache(ctx context.Context, flag bool) context.Context

func Prefetch

func Prefetch(ctx context.Context, keys []*datastore.Key, dst interface{}) context.Context

func Put

func Put(ctx context.Context, key *datastore.Key, src interface{}) (*datastore.Key, error)

func PutMulti

func PutMulti(ctx context.Context, keys []*datastore.Key, src interface{}) ([]*datastore.Key, error)

func SaveStruct

func SaveStruct(src interface{}) ([]datastore.Property, error)

SaveStruct outputs a struct to an datastore.Property channel

Types

type Datastore

type Datastore interface {
	Delete(context.Context, *datastore.Key) error
	DeleteMulti(context.Context, []*datastore.Key) error
	Get(context.Context, *datastore.Key, interface{}) error
	GetMulti(context.Context, []*datastore.Key, interface{}) error
	Put(context.Context, *datastore.Key, interface{}) (*datastore.Key, error)
	PutMulti(context.Context, []*datastore.Key, interface{}) ([]*datastore.Key, error)
}

type ErrMulti

type ErrMulti []error

func (ErrMulti) Error

func (m ErrMulti) Error() string

type Memcache

type Memcache interface {
	Delete(context.Context, *datastore.Key) error
	DeleteMulti(context.Context, []*datastore.Key) error
	Get(context.Context, *datastore.Key, interface{}) error
	Set(context.Context, *datastore.Key, interface{}) error
	SetMulti(context.Context, []*datastore.Key, interface{}) error
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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