karto

package module
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Jun 10, 2026 License: BSD-3-Clause Imports: 19 Imported by: 0

README

karto

go.dev reference Go Report Card License

karto is a simple (and incomplete) Go client for GoGoCarto.

Installation

$> go install codeberg.org/sbinet/karto@latest

Example

func ExampleClient() {
	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)
}

Documentation

Overview

Package karto provides a Go interface to the GoGoCarto REST-ish API.

More informations on:

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Address

type Address struct {
	PostalCode   string `json:"postalCode"`
	Locality     string `json:"addressLocality"`
	StreetName   string `json:"streetAddress"`
	StreetNumber string `json:"streetNumber"`
	Country      string `json:"addressCountry"`
	CustomAddr   string `json:"customFormatedAddress"`
}

func (Address) String added in v0.2.0

func (addr Address) String() string

type Category

type Category struct {
	ID          int    `json:"id"`
	Name        string `json:"name"`
	Description string `json:"description"`
	Index       int    `json:"index"`
}

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)
}

func New

func New(ep string, opts ...Config) (*Client, error)

New creates a new karto client, with the provided ep endpoint.

func (*Client) Add

func (cli *Client) Add(ctx context.Context, e Element) error

Add adds the provided element to the GoGoCarto server.

func (*Client) Element

func (cli *Client) Element(ctx context.Context, id string) (el Element, err error)

Element returns the element from the GoGoCarto server, if any.

func (*Client) Elements

func (cli *Client) Elements(ctx context.Context) iter.Seq2[Element, error]

Elements iterates over all the elements from the GoGoCarto server.

func (*Client) Login

func (cli *Client) Login(ctx context.Context, user, pass string) (usr User, err error)

Login authenticates with GoGoCarto, using the provided user and password values.

func (*Client) Taxonomies

func (cli *Client) Taxonomies(ctx context.Context) ([]Taxonomy, error)

Taxonomies returns the hierarchical (DAG) list of taxonomies.

func (*Client) Taxonomy

func (cli *Client) Taxonomy(ctx context.Context, id int) (t Taxonomy, err error)

Taxonomy returns the taxonomy with identity id, if any.

func (*Client) TaxonomyMapping

func (cli *Client) TaxonomyMapping(ctx context.Context) (map[int]TaxonomyOption, error)

TaxonomyMapping returns the map of all taxonomies, indexed by their ID.

type Config

type Config func(c *Client) error

Config configures how a karto client should be created.

func WithHTTP

func WithHTTP(c *http.Client) Config

WithHTTP specifies an HTTP client to use with karto requests.

func WithUserAgent

func WithUserAgent(ua string) Config

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 Point

type Point struct {
	Lat float64 `json:"latitude"`
	Lon float64 `json:"longitude"`
}

Point holds lat/lon coordinates.

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)
}

type User

type User struct {
	Name   string   `json:"username"`
	Email  string   `json:"email"`
	Roles  []string `json:"roles"`
	Groups []string `json:"groups"`
}

User represents a GoGoCarto user.

Directories

Path Synopsis
cmd
karto-ls command
Command karto-ls interacts with a (set of) GoGoCarto server(s).
Command karto-ls interacts with a (set of) GoGoCarto server(s).

Jump to

Keyboard shortcuts

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