dadata

package module
v2.11.0 Latest Latest
Warning

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

Go to latest
Published: Mar 31, 2024 License: MIT Imports: 6 Imported by: 3

README

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

Documentation

Index

Examples

Constants

View Source
const (
	// EndpointURL is a base API endpoint.
	EndpointURL = "https://dadata.ru/api/v2/"
	// EndpointURLSuggest is a suggestion API endpoint.
	EndpointURLSuggest = "https://suggestions.dadata.ru/suggestions/api/4_1/rs/"
	// EndpointURLClean is a cleaner API endpoint.
	EndpointURLClean = "https://cleaner.dadata.ru/api/v1/"
)

Variables

This section is empty.

Functions

func NewCleanApi

func NewCleanApi(opts ...client.Option) *clean.Api

NewCleanApi provides "clean" API.

func NewProfileApi

func NewProfileApi(opts ...client.Option) *profile.Api

NewProfileApi provides profile related API.

func NewStatApi

func NewStatApi(opts ...client.Option) *stat.Api

NewStatApi provides statistic API.

func NewSuggestApi

func NewSuggestApi(opts ...client.Option) *suggest.Api

NewSuggestApi provides suggestion API.

Example
api := 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)
}
Output:

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