id

package module
v1.2.2 Latest Latest
Warning

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

Go to latest
Published: Aug 15, 2023 License: BSD-3-Clause Imports: 5 Imported by: 11

README

go-whosonfirst-id

Go package for generating valid Who's On First IDs.

Documentation

Go Reference

Example

Error handling omitted for the sake of brevity.

Simple
package main

import (
	"context"
	"fmt"
	"testing"
)

func main() {

	ctx := context.Background()
	pr, _ := NewProvider(ctx)

	id, _ := pr.NewID(ctx)
	fmt.Println(id)
}
Fancy

The default Provider does not pre-generate or cache IDs. To do so create a custom Provider that does, use the handy NewProviderWithURI method:

package main

import (
	_ "github.com/aaronland/go-uid-whosonfirst"
)

import (
	"context"
	"fmt"
	_ "github.com/aaronland/go-uid-proxy"	
)

func main() {

	ctx := context.Background()

	uri := "proxy:///?provider=whosonfirst://&minimum=5&pool=memory%3A%2F%2F"
	cl, _ := NewProviderWithURI(ctx, uri)

	id, _ := cl.NextInt(ctx)
	fmt.Println(id)
}

This expects a valid go-uid-proxy URI string.

See also

Documentation

Index

Constants

View Source
const EARTH int64 = 0

EARTH is the Who's On First identifier for the planet Earth.

View Source
const ITS_COMPLICATED = -2

ITS_COMPLICATED is the identifier used to indicate that the parentage of a place is complicated in a geopolitical way too nuanced and complex to express otherwise.

View Source
const MULTIPLE_COUNTIES int64 = -4

MULTIPLE_COUNTIES is the identifier used to indicate that a place is legitimately parented by multiple counties. For details consult https://github.com/whosonfirst/py-mapzen-whosonfirst-hierarchy/issues/1

View Source
const MULTIPLE_NEIGHBOURHOODS int64 = -3

MULTIPLE_NEIGHBOURHOODS is the identifier used to indicate that a place is legitimately parented by multiple neighbouhoods.

View Source
const MULTIPLE_PARENTS int64 = -4

MULTIPLE_PARENTS was a misnamed constant and is included for backward compatibility but should otherwise not be used.

View Source
const NULL_ISLAND int64 = 1

NULL_ISLAND is the Who's On First identifier for the Null Island.

View Source
const UNKNOWN int64 = -1

UNKNOWN is the identifier used to indicate that an otherwise valid identifier is unknown and needs to be resolved.

Variables

This section is empty.

Functions

This section is empty.

Types

type Provider added in v0.0.2

type Provider interface {
	// NewID returns a new unique 64-bit integers.
	NewID(context.Context) (int64, error)
}

type Provider is an interface for providing uniquer identifiers.

func NewProvider added in v0.0.2

func NewProvider(ctx context.Context) (Provider, error)

NweProvider returns a new `WOFProvider` instance configured with default settings.

func NewProviderWithURI added in v0.0.2

func NewProviderWithURI(ctx context.Context, uri string) (Provider, error)

NewProviderWithURI returns a new `WOFProvider` instance configured by 'uri' which is expected to be a valid `aaronland/go-uid-proxy` URI.

type WOFProvider added in v0.0.2

type WOFProvider struct {
	Provider
	// contains filtered or unexported fields
}

WOFProvider implements the Provider interface for generating unique Who's On First identifiers.

func (*WOFProvider) NewID added in v0.0.2

func (wof_pr *WOFProvider) NewID(ctx context.Context) (int64, error)

NewID returns a new Who's On First identifier.

Jump to

Keyboard shortcuts

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