https://github.com/ekomobile/dadata
Golang client for DaData.ru
https://github.com/ekomobile/dadata
address-validation dadata go golang suggestions
Last synced: 21 days ago
JSON representation
Golang client for DaData.ru
- Host: GitHub
- URL: https://github.com/ekomobile/dadata
- Owner: ekomobile
- License: mit
- Created: 2019-04-08T08:54:09.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2025-07-23T22:42:20.000Z (7 months ago)
- Last Synced: 2025-07-24T01:31:50.866Z (7 months ago)
- Topics: address-validation, dadata, go, golang, suggestions
- Language: Go
- Homepage:
- Size: 93.8 KB
- Stars: 25
- Watchers: 5
- Forks: 22
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Client for DaData.ru
Forked from https://github.com/webdeskltd/dadata.
[](https://travis-ci.com/ekomobile/dadata)
[](https://github.com/ekomobile/dadata/releases)
[](https://goreportcard.com/report/github.com/ekomobile/dadata/v2)
[](https://godoc.org/github.com/ekomobile/dadata/v2)
DaData API v2
Implemented [Clean](https://dadata.ru/api/clean/) and [Suggest](https://dadata.ru/api/suggest/) methods.
## Installation
`go get github.com/ekomobile/dadata/v2`
## Usage
```go
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(), ¶ms)
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.
```go
creds := client.Credentials{
ApiKeyValue: "",
SecretKeyValue: "",
}
api := NewSuggestApi(client.WithCredentialProvider(&creds))
```
### HTTP client
HTTP client may be overridden with custom one:
```go
httpClient := &http.Client{}
api := NewSuggestApi(WithHttpClient(httpClient))
```
### Low level client usage
Pass and consume raw bytes/strings:
```go
endpointUrl, err := url.Parse("https://suggestions.dadata.ru/suggestions/api/4_1/rs/")
if err != nil {
return
}
cli := client.NewClient(endpointUrl,
client.WithEncoderFactory(encoder.RawEncoderFactory()),
client.WithDecoderFactory(encoder.RawDecoderFactory()),
)
request := bytes.NewBufferString("{ \"query\": \"москва хабар\" }")
response := &bytes.Buffer{}
err = cli.Post(context.Background(), "suggest/address", request, response)
if err != nil {
return
}
fmt.Print(response.String()) // Output: `{"suggestions":[{"value":"г Москва, ул Хабаровская",...`
```
## Licence
MIT see [LICENSE](LICENSE)