Documentation ¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ListenAndServe ¶ added in v0.9.0
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
Click to show internal directories.
Click to hide internal directories.