edgeconfig

package module
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Jul 12, 2023 License: BSD-3-Clause-Clear Imports: 6 Imported by: 0

README

edgeconfig


Go library to interact with Vercel Edge Config.

Docs GitHub Workflow Status

Installation

go get -d github.com/thatmattlove/go-vercel-edge-config

Usage

Example Edge Config Store

{
  "key": "value"
}

Initialize the Client

options := &edgeconfig.ClientOptions{
    EdgeConfigToken: "your-edge-config-token",
    EdgeConfigID: "your-edge-config-id",
}
ec, err := edgeconfig.New(options)

// You can also initialize a client from a connection string:
ec, err := edgeconfig.NewFromConnectionString("https://edge-config.vercel.com/your_edge_config_id_here?token=your_edge_config_read_access_token_here")

Retrieve a Single Value by Key

ec.Item("key")
// value

Retrieve All Items as a Map

ec.Items()
// map[key:value]

Retrieve Edge Config Digest

ec.Digest()
// d53d0989fcf40382f6979a1cb069e70b477606a156cf8dc6c96a7154b6e79a29

Retrieve All Edge Configs

err := ec.API.Authenticate("your_vercel_api_token")
configs, err := ec.API.ListAllEdgeConfigs()
// returns a slice of edge configs

GitHub

Documentation

Index

Constants

View Source
const VERCEL_API_URL string = "https://api.vercel.com"
View Source
const VERCEL_EDGE_CONFIG_URL string = "https://edge-config.vercel.com"

Variables

This section is empty.

Functions

This section is empty.

Types

type ClientOptions

type ClientOptions struct {
	// Vercel Team ID, if applicable.
	TeamID string
	// Edge-Config Access Token.
	EdgeConfigToken string
	// Edge-Config ID. This can also be passed as an argument to client methods if the ID changes frequently.
	EdgeConfigID string
}

type EdgeConfig

type EdgeConfig struct {
	Slug        string    `json:"slug"`
	ItemCount   int       `json:"itemCount"`
	CreatedAt   Timestamp `json:"createdAt"`
	UpdatedAt   Timestamp `json:"updatedAt"`
	ID          string    `json:"id"`
	Digest      string    `json:"digest"`
	SizeInBytes int64     `json:"sizeInBytes"`
	OwnerID     string    `json:"ownerId"`
}

type EdgeConfigItems

type EdgeConfigItems map[string]string

type Timestamp

type Timestamp struct {
	time.Time
}

func (*Timestamp) UnmarshalJSON

func (p *Timestamp) UnmarshalJSON(bytes []byte) error

type VercelAPI

type VercelAPI struct {
	TeamID string
	// contains filtered or unexported fields
}

func (*VercelAPI) Authenticate

func (v *VercelAPI) Authenticate(token string) (err error)

func (*VercelAPI) ListAllEdgeConfigs

func (v *VercelAPI) ListAllEdgeConfigs() (edgeConfigs []*EdgeConfig, err error)

type VercelAPIError

type VercelAPIError struct {
	Error VercelAPIErrorDetail `json:"error"`
}

type VercelAPIErrorDetail

type VercelAPIErrorDetail struct {
	Code    string `json:"code"`
	Message string `json:"message"`
}

type VercelEdgeConfigClient

type VercelEdgeConfigClient struct {
	TeamID string

	API          *VercelAPI
	EdgeConfigID string
	// contains filtered or unexported fields
}

func New

func New(options *ClientOptions) (client *VercelEdgeConfigClient, err error)

New creates a new Vercel Edge Config client using options.

func NewFromConnectionString

func NewFromConnectionString(connectionString string) (client *VercelEdgeConfigClient, err error)

NewFromConnectionString creates a new Vercel Edge Config client from a connection string.

func (*VercelEdgeConfigClient) AllItems

func (ec *VercelEdgeConfigClient) AllItems(args ...string) (items EdgeConfigItems, err error)

AllItems retrieves all items from an edge config store and returns a map.

func (*VercelEdgeConfigClient) Digest

func (ec *VercelEdgeConfigClient) Digest(args ...string) (digest string, err error)

Digest retrieves the digest for an edge config store.

func (*VercelEdgeConfigClient) Item

func (ec *VercelEdgeConfigClient) Item(args ...string) (value string, err error)

Item retrieves a single item from an edge config store by key.

Jump to

Keyboard shortcuts

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