Documentation
¶
Overview ¶
Package karto provides a Go interface to the GoGoCarto REST-ish API.
More informations on:
Index ¶
- type Address
- type Category
- type Client
- func (cli *Client) Add(ctx context.Context, e Element) error
- func (cli *Client) Element(ctx context.Context, id string) (el Element, err error)
- func (cli *Client) Elements(ctx context.Context) iter.Seq2[Element, error]
- func (cli *Client) Login(ctx context.Context, user, pass string) (usr User, err error)
- func (cli *Client) Taxonomies(ctx context.Context) ([]Taxonomy, error)
- func (cli *Client) Taxonomy(ctx context.Context, id int) (t Taxonomy, err error)
- func (cli *Client) TaxonomyMapping(ctx context.Context) (map[int]TaxonomyOption, error)
- type Config
- type Element
- type ElementStatus
- type Point
- type Taxonomy
- type TaxonomyOption
- type User
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Address ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is a karto/GoGoCarto client.
Example ¶
package main
import (
"context"
"fmt"
"log"
"codeberg.org/sbinet/karto"
)
func main() {
const (
user = "karto"
pass = "s3cr3t"
endpoint = "https://example.org"
)
cli, err := karto.New(endpoint, karto.WithUserAgent("karto/v0.0.1"))
if err != nil {
log.Fatalf("could not create karto client: %v", err)
}
var (
ctx = context.Background()
eid string
)
usr, err := cli.Login(ctx, user, pass)
if err != nil {
log.Fatalf("could not login: %v", err)
}
log.Printf("%s logged in (with roles: %q)", usr.Name, usr.Roles)
for elt, err := range cli.Elements(ctx) {
if err != nil {
log.Fatalf("could not iterate over elements: %v", err)
}
fmt.Printf("element: id=%s, title=%q", elt.ID, elt.Name)
eid = elt.ID
}
elt, err := cli.Element(ctx, eid)
if err != nil {
log.Fatalf("could not retrieve element %q from karto: %v", eid, err)
}
fmt.Printf("last element: id=%q\n", elt.ID)
}
Output:
func (*Client) Login ¶
Login authenticates with GoGoCarto, using the provided user and password values.
func (*Client) Taxonomies ¶
Taxonomies returns the hierarchical (DAG) list of taxonomies.
func (*Client) TaxonomyMapping ¶
TaxonomyMapping returns the map of all taxonomies, indexed by their ID.
type Config ¶
Config configures how a karto client should be created.
func WithUserAgent ¶
WithUserAgent modifies the default user agent for the karto client.
type Element ¶
type Element struct {
ID string `json:"id"`
Name string `json:"name"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
Status ElementStatus `json:"status"`
CatNames []string `json:"categories"`
Categories []Category `json:"categoriesFull"`
Coords Point `json:"geo"`
Address Address `json:"address"`
Beg time.Time `json:"date"`
End time.Time `json:"date_end"`
LocationName string `json:"nom_lieu"`
Descr string `json:"description"`
URL string `json:"lien_internet"`
Images []string `json:"images"`
Files []string `json:"files"`
Contact string `json:"nom_contact"`
Email string `json:"email"`
Phone string `json:"telephone"`
Subscribers []string `json:"subscriberEmails"`
}
Element is an event on GoGoCarto.
type ElementStatus ¶
type ElementStatus int
const ( ElemAggregated ElementStatus = -7 ElemDuplicate ElementStatus = -6 ElemModifiedPendingVersion ElementStatus = -5 ElemDeleted ElementStatus = -4 ElemCollaborativeRefused ElementStatus = -3 ElemAdminRefused ElementStatus = -2 ElemPendingModification ElementStatus = -1 ElemPendingAdd ElementStatus = 0 ElemAdminValidate ElementStatus = 1 ElemCollaborativeValidate ElementStatus = 2 ElemAddedByAdmin ElementStatus = 3 ElemModifiedByAdmin ElementStatus = 4 ElemModifiedByOwner ElementStatus = 5 ElemModifiedFromHash ElementStatus = 6 // in the emails we provide a link to edit the element with a hash validation ElemImported ElementStatus = 7 ElemAggregate ElementStatus = 8 ElemModifiedFromOtherProject ElementStatus = 9 )
func (ElementStatus) String ¶ added in v0.2.0
func (i ElementStatus) String() string
type Taxonomy ¶
type Taxonomy struct {
ID int `json:"id"`
Type string `json:"type"`
Name string `json:"name"`
Index int `json:"index"`
SingleOption bool `json:"singleOption"`
IsMandatory bool `json:"isMandatory"`
EnableDescr bool `json:"enableDescription"`
DescrLabel string `json:"descriptionLabel"`
IsRootCategory bool `json:"isRootCategory"`
Options []TaxonomyOption `json:"options"`
}
type TaxonomyOption ¶
type TaxonomyOption struct {
ID int `json:"id"`
Type string `json:"type"`
Name string `json:"name"`
PID int `json:"parentId"`
Index int `json:"index"`
FullName string `json:"nameWithParent"`
EnableDescr bool `json:"enableDescription"`
DescrLabel string `json:"descriptionLabel"`
OSMTags []string `json:"osmTags"`
Categories []any `json:"subcategories"` // FIXME(sbinet)
}
Click to show internal directories.
Click to hide internal directories.