Documentation ¶
Overview ¶
Package nerdstorage provides a programmatic API for interacting with the New Relic One NerdStorage document store. It can be used to write NerdStorage documents into collections and to delete documents and collections.
More information about the NerdStorage document store can be found in the online documentation:
https://developer.newrelic.com/build-tools/new-relic-one-applications/nerdstorage
Authentication ¶
You will need a valid Personal API key to communicate with the backend New Relic API that provides this functionality. See the API key documentation below for more information on how to locate this key:
https://docs.newrelic.com/docs/apis/get-started/intro-apis/types-new-relic-api-keys
Code generated by tutone: DO NOT EDIT
Example (AccountScope) ¶
package main import ( "encoding/json" "fmt" "log" "os" "strconv" "github.com/mitchellh/mapstructure" "github.com/newrelic/newrelic-client-go/pkg/config" ) type AccountScopedDoc struct { MyField string } func main() { // Initialize the client configuration. A Personal API key is required to // communicate with the backend API. cfg := config.New() cfg.PersonalAPIKey = os.Getenv("NEW_RELIC_API_KEY") // Initialize the client. client := New(cfg) accountID, err := strconv.Atoi(os.Getenv("NEW_RELIC_ACCOUNT_ID")) if err != nil { log.Fatal("error parsing account ID", err) } packageID := "ecaeb28c-7b3f-4932-9e33-7385980efa1c" // Write a NerdStorage document with account scope. writeDocumentInput := WriteDocumentInput{ PackageID: packageID, Collection: "myCol", DocumentID: "myDoc", Document: AccountScopedDoc{ MyField: "myValue", }, } _, err = client.WriteDocumentWithAccountScope(accountID, writeDocumentInput) if err != nil { log.Fatal("error writing NerdStorage document:", err) } // Write a second NerdStorage document to the same collection with account scope. writeAlternateDocumentInput := writeDocumentInput writeAlternateDocumentInput.DocumentID = "myOtherDoc" _, err = client.WriteDocumentWithAccountScope(accountID, writeAlternateDocumentInput) if err != nil { log.Fatal("error writing NerdStorage document:", err) } // Get a NerdStorage collection with account scope. getCollectionInput := GetCollectionInput{ PackageID: packageID, Collection: "myCol", } collection, err := client.GetCollectionWithAccountScope(accountID, getCollectionInput) if err != nil { log.Fatal("error retrieving NerdStorage collection:", err) } fmt.Printf("Collection length: %v\n", len(collection)) // Get a NerdStorage document with account scope. getDocumentInput := GetDocumentInput{ PackageID: packageID, Collection: "myCol", DocumentID: "myDoc", } rawDoc, err := client.GetDocumentWithAccountScope(accountID, getDocumentInput) if err != nil { log.Fatal("error retrieving NerdStorage document:", err) } // Convert the document to a struct. var myDoc AccountScopedDoc // Method 1: marshalled, err := json.Marshal(rawDoc) if err != nil { log.Fatal("error marshalling NerdStorage document to json:", err) } err = json.Unmarshal(marshalled, &myDoc) if err != nil { log.Fatal("error unmarshalling NerdStorage document to struct:", err) } fmt.Printf("Document: %v\n", myDoc) // Method 2: err = mapstructure.Decode(rawDoc, &myDoc) if err != nil { log.Fatal("error converting NerdStorage document to struct:", err) } fmt.Printf("Document: %v\n", myDoc) // Delete a NerdStorage document with account scope. deleteDocumentInput := DeleteDocumentInput{ PackageID: packageID, Collection: "myCol", DocumentID: "myDoc", } ok, err := client.DeleteDocumentWithAccountScope(accountID, deleteDocumentInput) if !ok || err != nil { log.Fatal("error deleting NerdStorage document:", err) } // Delete a NerdStorage collection with account scope. deleteCollectionInput := DeleteCollectionInput{ PackageID: packageID, Collection: "myCol", } deleted, err := client.DeleteCollectionWithAccountScope(accountID, deleteCollectionInput) if err != nil { log.Fatal("error deleting NerdStorage collection:", err) } if !deleted { // NerdStorage collections are auto-deleted when their last remaining document is deleted. log.Println("deletion was not necessary, collection might have already been deleted", err) } }
Output:
Example (EntityScope) ¶
package main import ( "encoding/json" "fmt" "log" "os" "github.com/mitchellh/mapstructure" "github.com/newrelic/newrelic-client-go/pkg/config" ) type EntityScopedDoc struct { MyField string } func main() { // Initialize the client configuration. A Personal API key is required to // communicate with the backend API. cfg := config.New() cfg.PersonalAPIKey = os.Getenv("NEW_RELIC_API_KEY") // Initialize the client. client := New(cfg) entityID := "MjUyMDUyOHxFUE18QVBQTElDQVRJT058MjE1MDM3Nzk1" packageID := "ecaeb28c-7b3f-4932-9e33-7385980efa1c" // Write a NerdStorage document with account scope. writeDocumentInput := WriteDocumentInput{ PackageID: packageID, Collection: "myCol", DocumentID: "myDoc", Document: AccountScopedDoc{ MyField: "myValue", }, } _, err := client.WriteDocumentWithEntityScope(entityID, writeDocumentInput) if err != nil { log.Fatal("error writing NerdStorage document:", err) } // Write a second NerdStorage document to the same collection with account scope. writeAlternateDocumentInput := writeDocumentInput writeAlternateDocumentInput.DocumentID = "myOtherDoc" _, err = client.WriteDocumentWithEntityScope(entityID, writeAlternateDocumentInput) if err != nil { log.Fatal("error writing NerdStorage document:", err) } // Get a NerdStorage collection with account scope. getCollectionInput := GetCollectionInput{ PackageID: packageID, Collection: "myCol", } collection, err := client.GetCollectionWithEntityScope(entityID, getCollectionInput) if err != nil { log.Fatal("error retrieving NerdStorage collection:", err) } fmt.Printf("Collection length: %v\n", len(collection)) // Get a NerdStorage document with account scope. getDocumentInput := GetDocumentInput{ PackageID: packageID, Collection: "myCol", DocumentID: "myDoc", } rawDoc, err := client.GetDocumentWithEntityScope(entityID, getDocumentInput) if err != nil { log.Fatal("error retrieving NerdStorage document:", err) } // Convert the document to a struct. var myDoc EntityScopedDoc // Method 1: marshalled, err := json.Marshal(rawDoc) if err != nil { log.Fatal("error marshalling NerdStorage document to json:", err) } err = json.Unmarshal(marshalled, &myDoc) if err != nil { log.Fatal("error unmarshalling NerdStorage document to struct:", err) } fmt.Printf("Document: %v\n", myDoc) // Method 2: err = mapstructure.Decode(rawDoc, &myDoc) if err != nil { log.Fatal("error converting NerdStorage document to struct:", err) } fmt.Printf("Document: %v\n", myDoc) // Delete a NerdStorage document with account scope. deleteDocumentInput := DeleteDocumentInput{ PackageID: packageID, Collection: "myCol", DocumentID: "myDoc", } ok, err := client.DeleteDocumentWithEntityScope(entityID, deleteDocumentInput) if !ok || err != nil { log.Fatal("error deleting NerdStorage document:", err) } // Delete a NerdStorage collection with account scope. deleteCollectionInput := DeleteCollectionInput{ PackageID: packageID, Collection: "myCol", } deleted, err := client.DeleteCollectionWithEntityScope(entityID, deleteCollectionInput) if err != nil { log.Fatal("error deleting NerdStorage collection:", err) } if !deleted { // NerdStorage collections are auto-deleted when their last remaining document is deleted. log.Println("deletion was not necessary, collection might have already been deleted", err) } }
Output:
Example (UserScope) ¶
package main import ( "encoding/json" "fmt" "log" "os" "github.com/mitchellh/mapstructure" "github.com/newrelic/newrelic-client-go/pkg/config" ) type UserScopedDoc struct { MyField string } func main() { // Initialize the client configuration. A Personal API key is required to // communicate with the backend API. cfg := config.New() cfg.PersonalAPIKey = os.Getenv("NEW_RELIC_API_KEY") // Initialize the client. client := New(cfg) packageID := "ecaeb28c-7b3f-4932-9e33-7385980efa1c" // Write a NerdStorage document with account scope. writeDocumentInput := WriteDocumentInput{ PackageID: packageID, Collection: "myCol", DocumentID: "myDoc", Document: UserScopedDoc{ MyField: "myValue", }, } _, err := client.WriteDocumentWithUserScope(writeDocumentInput) if err != nil { log.Fatal("error writing NerdStorage document:", err) } // Write a second NerdStorage document to the same collection with account scope. writeAlternateDocumentInput := writeDocumentInput writeAlternateDocumentInput.DocumentID = "myOtherDoc" _, err = client.WriteDocumentWithUserScope(writeAlternateDocumentInput) if err != nil { log.Fatal("error writing NerdStorage document:", err) } // Get a NerdStorage collection with account scope. getCollectionInput := GetCollectionInput{ PackageID: packageID, Collection: "myCol", } collection, err := client.GetCollectionWithUserScope(getCollectionInput) if err != nil { log.Fatal("error retrieving NerdStorage collection:", err) } fmt.Printf("Collection length: %v\n", len(collection)) // Get a NerdStorage document with account scope. getDocumentInput := GetDocumentInput{ PackageID: packageID, Collection: "myCol", DocumentID: "myDoc", } rawDoc, err := client.GetDocumentWithUserScope(getDocumentInput) if err != nil { log.Fatal("error retrieving NerdStorage document:", err) } // Convert the document to a struct. var myDoc UserScopedDoc // Method 1: marshalled, err := json.Marshal(rawDoc) if err != nil { log.Fatal("error marshalling NerdStorage document to json:", err) } err = json.Unmarshal(marshalled, &myDoc) if err != nil { log.Fatal("error unmarshalling NerdStorage document to struct:", err) } fmt.Printf("Document: %v\n", myDoc) // Method 2: err = mapstructure.Decode(rawDoc, &myDoc) if err != nil { log.Fatal("error converting NerdStorage document to struct:", err) } fmt.Printf("Document: %v\n", myDoc) // Delete a NerdStorage document with account scope. deleteDocumentInput := DeleteDocumentInput{ PackageID: packageID, Collection: "myCol", DocumentID: "myDoc", } ok, err := client.DeleteDocumentWithUserScope(deleteDocumentInput) if !ok || err != nil { log.Fatal("error deleting NerdStorage document:", err) } // Delete a NerdStorage collection with account scope. deleteCollectionInput := DeleteCollectionInput{ PackageID: packageID, Collection: "myCol", } deleted, err := client.DeleteCollectionWithUserScope(deleteCollectionInput) if err != nil { log.Fatal("error deleting NerdStorage collection:", err) } if !deleted { // NerdStorage collections are auto-deleted when their last remaining document is deleted. log.Println("deletion was not necessary, collection might have already been deleted", err) } }
Output:
Index ¶
- Variables
- type DeleteCollectionInput
- type DeleteDocumentInput
- type GetCollectionInput
- type GetDocumentInput
- type NerdStorage
- func (e *NerdStorage) DeleteCollectionWithAccountScope(accountID int, input DeleteCollectionInput) (bool, error)
- func (e *NerdStorage) DeleteCollectionWithEntityScope(entityGUID string, input DeleteCollectionInput) (bool, error)
- func (e *NerdStorage) DeleteCollectionWithUserScope(input DeleteCollectionInput) (bool, error)
- func (e *NerdStorage) DeleteDocumentWithAccountScope(accountID int, input DeleteDocumentInput) (bool, error)
- func (e *NerdStorage) DeleteDocumentWithEntityScope(entityGUID string, input DeleteDocumentInput) (bool, error)
- func (e *NerdStorage) DeleteDocumentWithUserScope(input DeleteDocumentInput) (bool, error)
- func (e *NerdStorage) GetCollectionWithAccountScope(accountID int, input GetCollectionInput) ([]interface{}, error)
- func (e *NerdStorage) GetCollectionWithEntityScope(entityGUID string, input GetCollectionInput) ([]interface{}, error)
- func (e *NerdStorage) GetCollectionWithUserScope(input GetCollectionInput) ([]interface{}, error)
- func (e *NerdStorage) GetDocumentWithAccountScope(accountID int, input GetDocumentInput) (interface{}, error)
- func (e *NerdStorage) GetDocumentWithEntityScope(entityGUID string, input GetDocumentInput) (interface{}, error)
- func (e *NerdStorage) GetDocumentWithUserScope(input GetDocumentInput) (interface{}, error)
- func (e *NerdStorage) WriteDocumentWithAccountScope(accountID int, input WriteDocumentInput) (interface{}, error)
- func (e *NerdStorage) WriteDocumentWithEntityScope(entityGUID string, input WriteDocumentInput) (interface{}, error)
- func (e *NerdStorage) WriteDocumentWithUserScope(input WriteDocumentInput) (interface{}, error)
- type NerdStorageCollectionMember
- type NerdStorageDocument
- type NerdStorageEntityScope
- type NerdStorageScope
- type NerdStorageScopeInput
- type WriteDocumentInput
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var NerdStorageScopeTypes = struct { // Account-level storage. ACCOUNT NerdStorageScope // Actor-level storage. ACTOR NerdStorageScope // Entity-level storage. ENTITY NerdStorageScope }{ ACCOUNT: "ACCOUNT", ACTOR: "ACTOR", ENTITY: "ENTITY", }
Functions ¶
This section is empty.
Types ¶
type DeleteCollectionInput ¶
DeleteCollectionInput represents the input data required for the DeleteCollection mutation.
type DeleteDocumentInput ¶
DeleteDocumentInput represents the input data required for the DeleteDocument mutation.
type GetCollectionInput ¶
GetCollectionInput represents the input data required for retrieving a NerdStorage collection.
type GetDocumentInput ¶
GetDocumentInput represents the input data required for retrieving a NerdStorage document.
type NerdStorage ¶
type NerdStorage struct {
// contains filtered or unexported fields
}
NerdStorage is used to communicate with the New Relic Workloads product.
func New ¶
func New(config config.Config) NerdStorage
New returns a new client for interacting with the New Relic One NerdStorage document store.
func (*NerdStorage) DeleteCollectionWithAccountScope ¶
func (e *NerdStorage) DeleteCollectionWithAccountScope(accountID int, input DeleteCollectionInput) (bool, error)
DeleteCollectionWithAccountScope deletes a NerdStorage collection with account scope.
func (*NerdStorage) DeleteCollectionWithEntityScope ¶
func (e *NerdStorage) DeleteCollectionWithEntityScope(entityGUID string, input DeleteCollectionInput) (bool, error)
DeleteCollectionWithEntityScope deletes a NerdStorage collection with entity scope.
func (*NerdStorage) DeleteCollectionWithUserScope ¶
func (e *NerdStorage) DeleteCollectionWithUserScope(input DeleteCollectionInput) (bool, error)
DeleteCollectionWithUserScope deletes a NerdStorage collection with user scope.
func (*NerdStorage) DeleteDocumentWithAccountScope ¶
func (e *NerdStorage) DeleteDocumentWithAccountScope(accountID int, input DeleteDocumentInput) (bool, error)
DeleteDocumentWithAccountScope deletes a NerdStorage document with account scope.
func (*NerdStorage) DeleteDocumentWithEntityScope ¶
func (e *NerdStorage) DeleteDocumentWithEntityScope(entityGUID string, input DeleteDocumentInput) (bool, error)
DeleteDocumentWithEntityScope deletes a NerdStorage document with entity scope.
func (*NerdStorage) DeleteDocumentWithUserScope ¶
func (e *NerdStorage) DeleteDocumentWithUserScope(input DeleteDocumentInput) (bool, error)
DeleteDocumentWithUserScope deletes a NerdStorage document with user scope.
func (*NerdStorage) GetCollectionWithAccountScope ¶
func (e *NerdStorage) GetCollectionWithAccountScope(accountID int, input GetCollectionInput) ([]interface{}, error)
GetCollectionWithAccountScope retrieves a NerdStorage collection with account scope.
func (*NerdStorage) GetCollectionWithEntityScope ¶
func (e *NerdStorage) GetCollectionWithEntityScope(entityGUID string, input GetCollectionInput) ([]interface{}, error)
GetCollectionWithEntityScope wretrieves a NerdStorage collection with entity scope.
func (*NerdStorage) GetCollectionWithUserScope ¶
func (e *NerdStorage) GetCollectionWithUserScope(input GetCollectionInput) ([]interface{}, error)
GetCollectionWithUserScope retrieves a NerdStorage collection with user scope.
func (*NerdStorage) GetDocumentWithAccountScope ¶
func (e *NerdStorage) GetDocumentWithAccountScope(accountID int, input GetDocumentInput) (interface{}, error)
GetDocumentWithAccountScope retrieves a NerdStorage document with account scope.
func (*NerdStorage) GetDocumentWithEntityScope ¶
func (e *NerdStorage) GetDocumentWithEntityScope(entityGUID string, input GetDocumentInput) (interface{}, error)
GetDocumentWithEntityScope retrieves a NerdStorage document with entity scope.
func (*NerdStorage) GetDocumentWithUserScope ¶
func (e *NerdStorage) GetDocumentWithUserScope(input GetDocumentInput) (interface{}, error)
GetDocumentWithUserScope retrieves a NerdStorage document with user scope.
func (*NerdStorage) WriteDocumentWithAccountScope ¶
func (e *NerdStorage) WriteDocumentWithAccountScope(accountID int, input WriteDocumentInput) (interface{}, error)
WriteDocumentWithAccountScope writes a NerdStorage document with account scope.
func (*NerdStorage) WriteDocumentWithEntityScope ¶
func (e *NerdStorage) WriteDocumentWithEntityScope(entityGUID string, input WriteDocumentInput) (interface{}, error)
WriteDocumentWithEntityScope writes a NerdStorage document with entity scope.
func (*NerdStorage) WriteDocumentWithUserScope ¶
func (e *NerdStorage) WriteDocumentWithUserScope(input WriteDocumentInput) (interface{}, error)
WriteDocumentWithUserScope writes a NerdStorage document with user scope.
type NerdStorageCollectionMember ¶ added in v0.53.0
type NerdStorageCollectionMember struct { // The NerdStorage document. Document NerdStorageDocument `json:"document,omitempty"` // The documentId. ID string `json:"id,omitempty"` }
NerdStorageCollectionMember -
type NerdStorageDocument ¶ added in v0.53.0
type NerdStorageDocument string
NerdStorageDocument - This scalar represents a NerdStorage document.
type NerdStorageEntityScope ¶ added in v0.53.0
type NerdStorageEntityScope struct { // Collection []NerdStorageCollectionMember `json:"collection,omitempty"` // Document NerdStorageDocument `json:"document,omitempty"` }
NerdStorageEntityScope -
type NerdStorageScope ¶ added in v0.53.0
type NerdStorageScope string
NerdStorageScope - The access level of the NerdStorage data.
type NerdStorageScopeInput ¶ added in v0.53.0
type NerdStorageScopeInput struct { // The ID for the selected scope. ID string `json:"id"` // The NerdStorage data access level. Name NerdStorageScope `json:"name"` }
NerdStorageScopeInput - The data access level and ID for the selected scope.
type WriteDocumentInput ¶
type WriteDocumentInput struct { Collection string Document interface{} DocumentID string PackageID string }
WriteDocumentInput represents the input data required for the WriteDocument mutation.