philippgille and i0rek Remove wrong space character (#4910)
There should be no space before a comma
Latest commit 2de7fef Nov 6, 2018
Permalink
Type Name Latest commit message Commit time
..
Failed to load latest commit information.
README.md Copy-and-paste Go client example (#4448) Jul 30, 2018
acl.go Adds documentation for the new ACL APIs (#4851) Oct 31, 2018
acl_test.go New ACL API Tests (#4848) Oct 25, 2018
agent.go New command: consul debug (#4754) Oct 19, 2018
agent_test.go New command: consul debug (#4754) Oct 19, 2018
api.go Remove wrong space character (#4910) Nov 6, 2018
api_test.go New ACLs (#4791) Oct 19, 2018
catalog.go Add support for multiple checks in Consul Client (#4849) Oct 29, 2018
catalog_test.go Add support for multiple checks in Consul Client (#4849) Oct 29, 2018
connect.go api: fix up some comments and rename IssuedCert to LeafCert Jun 14, 2018
connect_ca.go connect/ca: add configurable leaf cert TTL Jul 16, 2018
connect_ca_test.go Merge pull request #4400 from hashicorp/leaf-cert-ttl Jul 26, 2018
connect_intention.go agent: 400 error on invalid UUID format, api handles errors properly Jun 27, 2018
connect_intention_test.go agent: 400 error on invalid UUID format, api handles errors properly Jun 27, 2018
coordinate.go Merge branch 'coordinate-node-endpoint' of github.com:hashicorp/consu… Oct 27, 2017
coordinate_test.go Move check definition to a sub-struct Nov 1, 2017
debug.go New command: consul debug (#4754) Oct 19, 2018
debug_test.go New command: consul debug (#4754) Oct 19, 2018
event.go Revert "fixed: body not closed for non HTTP 200 responses" Jan 19, 2015
event_test.go api: refactor: unify naming of API tests Jul 7, 2017
health.go Support multiple tags for health and catalog http api endpoints (#4717) Oct 11, 2018
health_test.go Support multiple tags for health and catalog http api endpoints (#4717) Oct 11, 2018
kv.go Simplify string(buf.Bytes()) to buf.String() (#3590) Oct 18, 2017
kv_test.go api: refactor: unify naming of API tests Jul 7, 2017
lock.go Fix lock and semaphore timeouts Jul 6, 2018
lock_test.go Improve resilience of api pkg tests (#4676) Sep 18, 2018
operator.go Moves operator sub-functions into their own files. Mar 30, 2017
operator_area.go Remove operator_area note from godoc overview (#4603) Aug 28, 2018
operator_autopilot.go Simplify string(buf.Bytes()) to buf.String() (#3590) Oct 18, 2017
operator_autopilot_test.go BUGFIX: Unit test relying on WaitForLeader() did not work due to wron… Aug 6, 2018
operator_keyring.go Shows the segment name in the keyring API and command output. Sep 7, 2017
operator_keyring_test.go New config parser, HCL support, multiple bind addrs (#3480) Sep 25, 2017
operator_raft.go Move Raft protocol version for list peers end point to server side, f… Sep 26, 2017
operator_raft_test.go api: refactor: unify naming of API tests Jul 7, 2017
operator_segment.go Change segment list endpoint in docs/client api Sep 1, 2017
prepared_query.go api: change Connect to a query option Jun 25, 2018
prepared_query_test.go Allow ignoring checks by ID when defining a PreparedQuery. Fixes #3727. Apr 10, 2018
raw.go api: Refactoring into shared write logic Feb 18, 2015
semaphore.go Fix lock and semaphore timeouts Jul 6, 2018
semaphore_test.go Improve resilience of api pkg tests (#4676) Sep 18, 2018
session.go Expands and rework context support in the API client. (#3273) Jul 15, 2017
session_test.go Improve resilience of api pkg tests (#4676) Sep 18, 2018
snapshot.go Adds support for snapshots and restores. (#2396) Oct 26, 2016
snapshot_test.go api: refactor: prefix all API tests with API_ Jul 7, 2017
status.go Revert "fixed: body not closed for non HTTP 200 responses" Jan 19, 2015
status_test.go api: refactor: prefix all API tests with API_ Jul 7, 2017

README.md

Consul API client

This package provides the api package which attempts to provide programmatic access to the full Consul API.

Currently, all of the Consul APIs included in version 0.6.0 are supported.

Documentation

The full documentation is available on Godoc

Usage

Below is an example of using the Consul client:

package main

import "github.com/hashicorp/consul/api"
import "fmt"

func main() {
	// Get a new client
	client, err := api.NewClient(api.DefaultConfig())
	if err != nil {
		panic(err)
	}

	// Get a handle to the KV API
	kv := client.KV()

	// PUT a new KV pair
	p := &api.KVPair{Key: "REDIS_MAXCLIENTS", Value: []byte("1000")}
	_, err = kv.Put(p, nil)
	if err != nil {
		panic(err)
	}

	// Lookup the pair
	pair, _, err := kv.Get("REDIS_MAXCLIENTS", nil)
	if err != nil {
		panic(err)
	}
	fmt.Printf("KV: %v %s\n", pair.Key, pair.Value)
}

To run this example, start a Consul server:

consul agent -dev

Copy the code above into a file such as main.go.

Install and run. You'll see a key (REDIS_MAXCLIENTS) and value (1000) printed.

$ go get
$ go run main.go
KV: REDIS_MAXCLIENTS 1000

After running the code, you can also view the values in the Consul UI on your local machine at http://localhost:8500/ui/dc1/kv