consulapi

package module
v0.0.0-...-dd2ee09 Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2018 License: MPL-2.0 Imports: 13 Imported by: 0

README

consulapi GoDoc


consulapi is a simplified implementation of the http api intended to support Consul Connect Native while at the same time minimizing dependencies.

This repo is under heavy construction.

Server
import (
  "net"
	
  "github.com/savaki/consulapi"
  "github.com/savaki/consulapi/connect"
)

func main() {
  port := 8080

  // bind listener to port
  listener, err := net.Listen("tcp", fmt.Sprintf(":%d", port))
  if err != nil {
    log.Fatalln(err)
  }
  defer listener.Close()
	
  // register as connect native service
  agent := consulapi.NewAgent()
  service, err := connect.NewService(agent, "my-service", port)
  if err != nil {
  	log.Fatalln(err)
  }
  defer service.Close()
  
  // accept
  go acceptLoop(listener)
}
Client
import (
  "github.com/savaki/consulapi"
  "github.com/savaki/consulapi/connect"
  "google.golang.org/grpc"
  "google.golang.org/grpc/connectivity"
)

func main() {
  client := consulapi.NewHealth()
  resolver := connect.NewResolver(client, "my-service")
  conn, err := grpc.Dial("",
    grpc.WithBalancer(grpc.RoundRobin(resolver)),
    grpc.WithInsecure(),
  )
  if err != nil {
    log.Fatalln(err)
  }
  defer conn.Close()
  
  // create grpc client
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Agent

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

func NewAgent

func NewAgent(opts ...Option) *Agent

func (*Agent) ConnectCALeaf

func (a *Agent) ConnectCALeaf(ctx context.Context, service string) (AgentConnectCALeaf, error)

func (*Agent) ConnectCARoots

func (a *Agent) ConnectCARoots(ctx context.Context) (AgentConnectCARoots, error)

func (*Agent) ServiceDeregister

func (a *Agent) ServiceDeregister(ctx context.Context, serviceID string) error

func (*Agent) ServiceRegister

func (a *Agent) ServiceRegister(ctx context.Context, registration AgentServiceRegistration) error

func (*Agent) UpdateTTL

func (a *Agent) UpdateTTL(ctx context.Context, status Status, checkID, output string) error

type AgentConnectAuthorizeRequest

type AgentConnectAuthorizeRequest struct {
	Target           string
	ClientCertURI    string
	ClientCertSerial string
}

type AgentConnectAuthorizeResponse

type AgentConnectAuthorizeResponse struct {
	Authorized bool
	Reason     string
}

type AgentConnectCALeaf

type AgentConnectCALeaf struct {
	SerialNumber  string
	CertPEM       string
	PrivateKeyPEM string
	Service       string
	ServiceURI    string
	ValidAfter    time.Time
	ValidBefore   time.Time
	CreateIndex   int64
	ModifyIndex   int64
}

type AgentConnectCARoot

type AgentConnectCARoot struct {
	ID                string
	Name              string
	SerialNumber      int
	SigningKeyID      string
	NotBefore         time.Time
	NotAfter          time.Time
	RootCert          string
	IntermediateCerts []string
	Active            bool
	CreateIndex       int64
	ModifyIndex       int64
}

type AgentConnectCARoots

type AgentConnectCARoots struct {
	ActiveRootID string
	TrustDomain  string
	Roots        []AgentConnectCARoot
}

type AgentServiceCheck

type AgentServiceCheck struct {
	CheckID                        string `json:",omitempty"`
	TTL                            string `json:",omitempty"`
	DeregisterCriticalServiceAfter string `json:",omitempty"`
}

type AgentServiceConnect

type AgentServiceConnect struct {
	Native bool
}

type AgentServiceProxy

type AgentServiceProxy struct {
	DestinationServiceName string
	DestinationServiceID   string `json:",omitempty"`
	LocalServiceAddress    string `json:",omitempty"`
	LocalServicePort       int    `json:",omitempty"`
}

AgentServiceConnectProxyConfig is the proxy configuration in a connect-proxy ServiceDefinition or response.

type AgentServiceRegistration

type AgentServiceRegistration struct {
	Kind             ServiceKind          `json:",omitempty"`
	ID               string               `json:",omitempty"`
	Name             string               `json:",omitempty"`
	Tags             []string             `json:",omitempty"`
	Port             int                  `json:",omitempty"`
	Address          string               `json:",omitempty"`
	Check            *AgentServiceCheck   `json:",omitempty"`
	Connect          *AgentServiceConnect `json:",omitempty"`
	ProxyDestination string               `json:",omitempty"`
	Proxy            *AgentServiceProxy   `json:",omitempty"`
}

type Health

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

func NewHealth

func NewHealth(opts ...Option) *Health

func (*Health) Connect

func (h *Health) Connect(ctx context.Context, service string, passing bool) ([]HealthServiceEntry, error)

type HealthService

type HealthService struct {
	ID      string
	Service string
	Address string
	Port    int
}

type HealthServiceEntry

type HealthServiceEntry struct {
	Service HealthService
}

type Option

type Option func(*Options)

func WithConsulAddr

func WithConsulAddr(addr string) Option

type Options

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

type ServiceKind

type ServiceKind string

ServiceKind is the kind of service being registered.

const (
	// ServiceKindTypical is a typical, classic Consul service. This is
	// represented by the absence of a value. This was chosen for ease of
	// backwards compatibility: existing services in the catalog would
	// default to the typical service.
	ServiceKindTypical ServiceKind = ""

	// ServiceKindConnectProxy is a proxy for the Connect feature. This
	// service proxies another service within Consul and speaks the connect
	// protocol.
	ServiceKindConnectProxy ServiceKind = "connect-proxy"
)

type Status

type Status string
const (
	StatusPass Status = "passing"
	StatusWarn Status = "warning"
	StatusFail Status = "critical"
)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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