github.com/m-lab/locate@v0.17.6/prometheus/client.go (about)

     1  package prometheus
     2  
     3  import (
     4  	"net/http"
     5  
     6  	"github.com/prometheus/client_golang/api"
     7  	v1 "github.com/prometheus/client_golang/api/prometheus/v1"
     8  	"github.com/prometheus/common/config"
     9  )
    10  
    11  // Credentials contains Basic Authentication credentials to
    12  // access Prometheus.
    13  type Credentials struct {
    14  	Username string
    15  	Password config.Secret
    16  }
    17  
    18  // NewClient returns a new client for the Prometheus HTTP API.
    19  func NewClient(c *Credentials, addr string) (v1.API, error) {
    20  	promClient, err := api.NewClient(api.Config{
    21  		Address: addr,
    22  		Client: &http.Client{
    23  			Transport: config.NewBasicAuthRoundTripper(c.Username, c.Password, "", &http.Transport{}),
    24  		},
    25  	})
    26  	if err != nil {
    27  		return nil, err
    28  	}
    29  
    30  	return v1.NewAPI(promClient), nil
    31  }