Skip to content

Instantly share code, notes, and snippets.

@tleyden
Created January 17, 2015 19:46
Show Gist options
  • Save tleyden/cc5cc07dc4009003fa00 to your computer and use it in GitHub Desktop.
Save tleyden/cc5cc07dc4009003fa00 to your computer and use it in GitHub Desktop.
cluster-init
// Set the username and password for the cluster. The same as calling:
// $ couchbase-cli cluster-init ..
//
// Docs: http://docs.couchbase.com/admin/admin/REST/rest-node-set-username.html
func (c CouchbaseCluster) ClusterInit(ip, adminUsername, adminPass string) error {
client := &http.Client{}
endpointUrl := fmt.Sprintf("http://%v:%v/settings/web", ip, COUCHBASE_PORT)
data := url.Values{
"username": {adminUsername},
"password": {adminPass},
"port": {COUCHBASE_PORT},
}
req, err := http.NewRequest("POST", endpointUrl, strings.NewReader(data.Encode()))
if err != nil {
return err
}
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
req.SetBasicAuth(COUCHBASE_DEFAULT_ADMIN_USERNAME, COUCHBASE_DEFAULT_ADMIN_PASSWORD)
resp, err := client.Do(req)
if err != nil {
return err
}
resp.Body.Close()
if resp.StatusCode != 200 {
return fmt.Errorf("Failed to init cluster: %v", resp.StatusCode)
}
return nil
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment