contacts

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 24, 2026 License: MIT Imports: 5 Imported by: 0

README

togo

togo-framework/contacts

marketplace pkg.go.dev MIT

Part of the togo framework.

Install

togo install togo-framework/contacts

contacts — togo contacts plugin

The contacts base plugin for togo. It defines a normalized Contact model and a ContactsProvider driver interface so you can import/sync contacts from anywhere — Google, a CRM, … — behind one API.

togo install togo-framework/contacts
togo install togo-framework/contacts-google   # a provider

Select the provider with CONTACTS_DRIVER (default null — no contacts):

CONTACTS_DRIVER=google

Use it

import "github.com/togo-framework/contacts"

svc, _ := contacts.FromKernel(k)
all, err := svc.Sync(ctx)        // pull every contact from the provider
c, err  := svc.Get(ctx, id)      // one contact by provider id

Write a provider

A provider is a tiny module that registers a driver in init():

func init() {
    contacts.RegisterDriver("mycrm", func(k *togo.Kernel) (contacts.ContactsProvider, error) {
        return &provider{/* read env */}, nil
    })
}

It implements List(ctx, pageToken) ([]Contact, next, err) and Get(ctx, id). contacts-google is the reference provider (Google People API); the same shape works for any CRM.

MIT


Premium sponsors

ID8 Media  ·  One Studio

Support togo — become a sponsor.

Documentation

Overview

Package contacts is the togo contacts base plugin. It defines a normalized Contact model + a ContactsProvider driver interface; provider plugins (e.g. contacts-google) call contacts.RegisterDriver and depend on this package.

Blank-import a provider and set CONTACTS_DRIVER to select it. The default "null" driver returns no contacts (safe for dev/tests).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RegisterDriver

func RegisterDriver(name string, f DriverFactory)

RegisterDriver registers a contacts driver by name (call from a plugin's init()).

Types

type Contact

type Contact struct {
	ID     string            `json:"id"`
	Name   string            `json:"name"`
	Emails []string          `json:"emails,omitempty"`
	Phones []string          `json:"phones,omitempty"`
	Photo  string            `json:"photo,omitempty"`
	Org    string            `json:"org,omitempty"`
	Source string            `json:"source,omitempty"`
	Extra  map[string]string `json:"extra,omitempty"`
}

Contact is a normalized contact record (provider-agnostic).

type ContactsProvider

type ContactsProvider interface {
	// List returns a page of contacts. pageToken "" starts at the beginning; the
	// returned next token is "" when there are no more pages.
	List(ctx context.Context, pageToken string) (contacts []Contact, next string, err error)
	// Get returns one contact by its provider id.
	Get(ctx context.Context, id string) (*Contact, error)
}

ContactsProvider imports contacts from an external source (Google, a CRM, …).

type DriverFactory

type DriverFactory func(k *togo.Kernel) (ContactsProvider, error)

DriverFactory builds a provider from the kernel (env/config).

type Service

type Service struct {
	// contains filtered or unexported fields
}

Service is the contacts runtime stored on the kernel (k.Get("contacts")).

func FromKernel

func FromKernel(k *togo.Kernel) (*Service, bool)

FromKernel fetches the contacts service from the kernel container.

func (*Service) Driver

func (s *Service) Driver() string

Driver returns the active driver name.

func (*Service) Get

func (s *Service) Get(ctx context.Context, id string) (*Contact, error)

Get returns one contact by provider id.

func (*Service) Provider

func (s *Service) Provider() ContactsProvider

Provider returns the active driver implementation.

func (*Service) Sync

func (s *Service) Sync(ctx context.Context) ([]Contact, error)

Sync pulls every contact from the provider, paging through all pages.

Jump to

Keyboard shortcuts

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