forked from abclogin/dadata
-
Notifications
You must be signed in to change notification settings - Fork 0
/
find_by_id.go
47 lines (40 loc) · 1.65 KB
/
find_by_id.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package dadata // import "gopkg.in/webdeskltd/dadata.v2"
import (
"context"
"fmt"
)
// AddressByID find address by Fias or Kladr
// see full documentation https://confluence.hflabs.ru/pages/viewpage.action?pageId=312016944
func (daData *DaData) AddressByID(id string) (*ResponseAddress, error) {
return daData.AddressByIDWithCtx(context.Background(), id)
}
// AddressByIDWithCtx find address by Fias or Kladr
// see full documentation https://confluence.hflabs.ru/pages/viewpage.action?pageId=312016944
func (daData *DaData) AddressByIDWithCtx(ctx context.Context, id string) (address *ResponseAddress, err error) {
var result []ResponseAddress
if result, err = daData.AddressesByIDWithCtx(ctx, id); err != nil {
return
}
address = &result[0]
return
}
// AddressesByID find addresses by Fias or Kladr
// see full documentation https://confluence.hflabs.ru/pages/viewpage.action?pageId=312016944
func (daData *DaData) AddressesByID(id string) ([]ResponseAddress, error) {
return daData.AddressesByIDWithCtx(context.Background(), id)
}
// AddressesByIDWithCtx find addresses by Fias or Kladr
// see full documentation https://confluence.hflabs.ru/pages/viewpage.action?pageId=312016944
func (daData *DaData) AddressesByIDWithCtx(ctx context.Context, id string) (addresses []ResponseAddress, err error) {
var result = &SuggestAddressResponse{}
var req = SuggestRequestParams{Query: id}
if err = daData.sendRequestToURL(ctx, "POST", baseSuggestURL+"findById/address", req, result); err != nil {
return
}
if len(result.Suggestions) == 0 {
err = fmt.Errorf("dadata.AddressByID: cannot detect address by id %s", id)
return
}
addresses = result.Suggestions
return
}