client

package module
v1.2.1-0...-837e979 Latest Latest
Warning

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

Go to latest
Published: Aug 16, 2021 License: Apache-2.0 Imports: 0 Imported by: 0

README

datadog-api-client-go

This repository contains a Go API client for the Datadog API. The code is generated using openapi-generator and apigentools.

Requirements

  • Go 1.14+

Layout

This repository contains per-major-version API client packages. Right now, Datadog has two API versions, v1 and v2.

The API v1 Client

The client library for Datadog API v1 is located in the api/v1/datadog directory. Import it with

import "github.com/DataDog/datadog-api-client-go/api/v1/datadog"

All the documentation for this package is available here.

The API v2 Client

The client library for Datadog API v2 is located in the api/v2/datadog directory. Import it with

import "github.com/DataDog/datadog-api-client-go/api/v2/datadog"

All the documentation for this package is available here.

Getting Started

Here's an example creating a user:

package main

import (
    "context"
    "fmt"
    "os"
    datadog "github.com/DataDog/datadog-api-client-go/api/v2/datadog"
)

func main() {
    ctx := context.WithValue(
        context.Background(),
        datadog.ContextAPIKeys,
        map[string]datadog.APIKey{
            "apiKeyAuth": {
                Key: os.Getenv("DD_CLIENT_API_KEY"),
            },
            "appKeyAuth": {
                Key: os.Getenv("DD_CLIENT_APP_KEY"),
            },
        },
    )

    body := *datadog.NewUserCreateRequest(*datadog.NewUserCreateData(*datadog.NewUserCreateAttributes("jane.doe@example.com"), datadog.UsersType("users")))

    configuration := datadog.NewConfiguration()

    apiClient := datadog.NewAPIClient(configuration)
    resp, r, err := apiClient.UsersApi.CreateUser(ctx, body)
    if err != nil {
        fmt.Fprintf(os.Stderr, "Error creating user: %v\n", err)
        fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r)
    }
    responseData := resp.GetData()
    fmt.Fprintf(os.Stdout, "User ID: %s", responseData.GetId())
}

Save it to example.go, then run go get github.com/DataDog/datadog-api-client-go/api/v2/datadog. Set the DD_CLIENT_API_KEY and DD_CLIENT_APP_KEY to your Datadog credentials, and then run go run example.go.

Unstable Endpoints

This client includes access to Datadog API endpoints while they are in an unstable state and may undergo breaking changes. An extra configuration step is required to enable these endpoints:

    configuration.SetUnstableOperationEnabled("<OperationName>", true)

where <OperationName> is the name of the method used to interact with that endpoint. For example: GetLogsIndex, or UpdateLogsIndex

Changing Server

When talking to a different server, like the eu instance, change the ContextServerVariables:

    ctx = context.WithValue(ctx,
        datadog.ContextServerVariables,
        map[string]string{
            "site": "datadoghq.eu",
    })

Documentation

Documentation for API endpoints and models can be found under the docs subdirectories, in v1 and v2.

It's also available on pkg.go.dev.

Contributing

As most of the code in this repository is generated, we will only accept PRs for files that are not modified by our code-generation machinery (changes to the generated files would get overwritten). We happily accept contributions to files that are not autogenerated, such as tests and development tooling.

Author

support@datadoghq.com

Documentation

Index

Constants

View Source
const Version = "1.2.1+dev"

Version used in User-Agent header.

Variables

This section is empty.

Functions

This section is empty.

Types

This section is empty.

Directories

Path Synopsis
api

Jump to

Keyboard shortcuts

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