Golang client for DaData.ru
Go to file
2022-07-13 12:54:06 +02:00
api Okopf code added 2022-07-13 12:54:06 +02:00
client Credentials docs. 2022-03-30 23:30:20 +03:00
.gitignore Forked and cleaned. 2019-04-08 14:49:07 +03:00
.travis.yml Credentials docs. 2022-03-30 23:30:20 +03:00
dadata_test.go Party by ID suggestion. 2020-12-14 19:00:36 +03:00
dadata.go V2. 2019-04-09 17:08:32 +03:00
go.mod Credentials docs. 2022-03-30 23:30:20 +03:00
go.sum Credentials docs. 2022-03-30 23:30:20 +03:00
LICENSE Initial commit 2019-04-08 11:54:10 +03:00
README.md HTTP client docs. 2022-03-31 00:16:33 +03:00
VERSION HTTP client docs. 2022-03-31 00:16:33 +03:00

Client for DaData.ru

Forked from https://github.com/webdeskltd/dadata.

Build Status GitHub release Go Report Card GoDoc

DaData API v2

Implemented Clean and Suggest methods.

Installation

go get github.com/ekomobile/dadata/v2

Usage

import (
	"context"
	"fmt"

	"github.com/ekomobile/dadata/v2"
	"github.com/ekomobile/dadata/v2/api/suggest"
)

func DaDataExample()  {
	api := dadata.NewSuggestApi()

	params := suggest.RequestParams{
		Query: "ул Свободы",
	}

	suggestions, err := api.Address(context.Background(), &params)
	if err != nil {
		return
	}

	for _, s := range suggestions {
		fmt.Printf("%s", s.Value)
	}
}

Configuration

Credentials

DADATA_API_KEY and DADATA_SECRET_KEY environment variables are used by default to authenticate client.

Custom credential provider may be used by implementing client.CredentialProvider interface.

Also, there is a "simple" credential provider client.Credentials you may utilize.

creds := client.Credentials{
    ApiKeyValue:    "<YOUR_API_KEY>",
    SecretKeyValue: "<YOUR_SECRET_KEY>",
}

api := NewSuggestApi(client.WithCredentialProvider(&creds))

HTTP client

HTTP client may be overridden with custom one:

httpClient := &http.Client{}

api := NewSuggestApi(WithHttpClient(httpClient))

Licence

MIT see LICENSE