dondeestas

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Dec 21, 2016 License: MIT Imports: 11 Imported by: 0

README

¿Dónde Estás? Daemon Build Status Coverage Go Report GoDoc

The server side to the ¿Dónde Estás? android app

Example usage
Starting the servers
docker run -d --name couchdb couchdb:1.6
docker run -d -p 8080:8080 --link couchdb:db hokiegeek/donde-estas-daemon
Adding entries
curl localhost:8080/update --data \
'{
    "id" : "42",
    "name" : "foobar",
    "position": {
        "tov": "2009-11-10T23:00:00Z",
        "latitude": 0.1,
        "longitude": 0.2,
        "elevation": 0.3
    },
    "visible" : true,
    "whitelist" : ["99"],
    "following" : []
}'

curl localhost:8080/update --data \
'{
    "id" : "99",
    "name" : "raboof",
    "position": {
        "tov": "2009-11-10T22:00:00Z",
        "latitude": 0.4,
        "longitude": 0.5,
        "elevation": 0.6
    },
    "visible" : true,
    "whitelist" : ["42"],
    "following" : ["42"]
}'
Retrieving entries
curl localhost:8080/person --data '{"ids":["42","99"]}'

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func ListenAndServe added in v0.9.0

func ListenAndServe(log *log.Logger, port int, db *DbClient) error

ListenAndServe opens an HTTP server which listens for connections and provides data using the given DbClient.

The following routes are available:

/person
      This route returns data on the request people.
      It expects a JSON object with a single array of strings with the Person identifiers named 'ids'
      It returns a JSON with an array of Person objects named 'people'

/update
      This route expects a JSON body with a single Person object to update
Example
db, err := NewDbClient(DbClientParams{CouchDB, "example_db", "localhost", 5934})
if err != nil {
	panic(err)
}

logger := log.New(os.Stdout, "", 0)

logger.Fatal(ListenAndServe(logger, 8080, db))
Output:

Types

type DbClient added in v1.0.0

type DbClient interface {
	Init(dbname, hostname string, port int) error
	Create(p Person) error
	Exists(id string) bool
	Get(id string) (*Person, error)
	Update(p Person) error
	Remove(id string) error
}

DbClient is the interface used by all structs which provide access to a database

func NewDbClient

func NewDbClient(params DbClientParams) (*DbClient, error)

NewDbClient creates a database client of specified type at a specified URL

type DbClientParams

type DbClientParams struct {
	DbType           DbClientTypes
	DbName, Hostname string
	Port             int
}

DbClientParams encapsulates the options available for NewDbClient

type DbClientTypes

type DbClientTypes int

DbClientTypes is an enumeration of database types supported by this library

const (
	CouchDB DbClientTypes = 0 + iota // CouchDB client type
)

Enumeration which specifies which type of client to create when calling NewDbClient

type Person

type Person struct {
	ID       string `json:"id"`
	Name     string `json:"name"`
	Position struct {
		Tov       time.Time `json:"tov"`
		Latitude  float32   `json:"latitude"`
		Longitude float32   `json:"longitude"`
		Elevation float32   `json:"elevation"`
	} `json:"position"`
	Visible   bool     `json:"visible"`
	Whitelist []string `json:"whitelist"`
	Following []string `json:"following"`
}

Person encapsulates all of the data needed for tracking a user

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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