group

package
v0.14.0 Latest Latest
Warning

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

Go to latest
Published: Dec 15, 2023 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package group synchronises email addresses with a Google Group.

Requirements

In order to synchronise with Google, you'll need to credentials with the Admin SDK enabled on your account, and credentials with the following scopes:

Examples

See [New] and Init.

Index

Examples

Constants

View Source
const DeliverySettings gosync.ConfigKey = "delivery_settings"

DeliverySettings sets the delivery settings.

Acceptable values:

  • ALL_MAIL
  • DAILY
  • DIGEST
  • DISABLED
  • NONE

See `delivery_settings` field in reference for more information.

View Source
const Name gosync.ConfigKey = "name"

Name is the name of your Google group.

View Source
const Role gosync.ConfigKey = "role"

Role sets the role for new users being added to a group.

Acceptable values:

  • MANAGER
  • MEMBER
  • OWNER

See `role` field in reference for more information.

Variables

This section is empty.

Functions

func WithAdminService added in v0.14.0

func WithAdminService(adminService *admin.Service) gosync.ConfigFn[*Group]

WithAdminService passes a custom Google Admin Service to the adapter.

Example
package main

import (
	"context"
	"log"

	admin "google.golang.org/api/admin/directory/v1"
	"google.golang.org/api/option"

	gosync "github.com/ovotech/go-sync"
	"github.com/ovotech/go-sync/adapters/google/group"
)

func main() {
	ctx := context.Background()

	client, err := admin.NewService(
		ctx,
		option.WithScopes(admin.AdminDirectoryGroupMemberScope),
		option.WithAPIKey("my-api-key"),
	)
	if err != nil {
		log.Fatal(err)
	}

	adapter, err := group.Init(ctx, map[gosync.ConfigKey]string{
		group.Name: "my-group",
	}, group.WithAdminService(client))
	if err != nil {
		log.Fatal(err)
	}

	gosync.New(adapter)
}
Output:

func WithLogger

func WithLogger(logger *log.Logger) gosync.ConfigFn[*Group]

WithLogger passes a custom logger to the adapter.

Example
package main

import (
	"context"
	"log"
	"os"

	gosync "github.com/ovotech/go-sync"
	"github.com/ovotech/go-sync/adapters/google/group"
)

func main() {
	ctx := context.Background()

	logger := log.New(os.Stdout, "", log.LstdFlags)

	adapter, err := group.Init(ctx, map[gosync.ConfigKey]string{
		group.Name: "my-group",
	}, group.WithLogger(logger))
	if err != nil {
		log.Fatal(err)
	}

	gosync.New(adapter)
}
Output:

Types

type Group

type Group struct {
	Logger *log.Logger

	DeliverySettings string // See [group.DeliverySettings].
	Role             string // See [group.Role].
	// contains filtered or unexported fields
}

func Init added in v0.7.0

func Init(
	ctx context.Context,
	config map[gosync.ConfigKey]string,
	configFns ...gosync.ConfigFn[*Group],
) (*Group, error)

Init a new Google Group gosync.Adapter.

Required config:

Example
package main

import (
	"context"
	"log"

	gosync "github.com/ovotech/go-sync"
	"github.com/ovotech/go-sync/adapters/google/group"
)

func main() {
	ctx := context.Background()

	adapter, err := group.Init(ctx, map[gosync.ConfigKey]string{
		group.Name: "my-group",
	})
	if err != nil {
		log.Fatal(err)
	}

	gosync.New(adapter)
}
Output:

func (*Group) Add

func (g *Group) Add(ctx context.Context, emails []string) error

Add email addresses to a Google Group.

func (*Group) Get

func (g *Group) Get(ctx context.Context) ([]string, error)

Get email addresses in a Google Group.

func (*Group) Remove

func (g *Group) Remove(ctx context.Context, emails []string) error

Remove email addresses from a Google Group.

Jump to

Keyboard shortcuts

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