-
Notifications
You must be signed in to change notification settings - Fork 20
/
dadata.go
74 lines (61 loc) · 1.63 KB
/
dadata.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package dadata
import (
"net/url"
"github.com/ekomobile/dadata/v2/api/clean"
"github.com/ekomobile/dadata/v2/api/profile"
"github.com/ekomobile/dadata/v2/api/stat"
"github.com/ekomobile/dadata/v2/api/suggest"
"github.com/ekomobile/dadata/v2/client"
)
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/"
)
var (
endpointURL *url.URL
endpointURLSuggest *url.URL
endpointURLClean *url.URL
)
func init() {
var err error
endpointURL, err = url.Parse(EndpointURL)
if err != nil {
panic(err)
}
endpointURLSuggest, err = url.Parse(EndpointURLSuggest)
if err != nil {
panic(err)
}
endpointURLClean, err = url.Parse(EndpointURLClean)
if err != nil {
panic(err)
}
}
// NewCleanApi provides "clean" API.
func NewCleanApi(opts ...client.Option) *clean.Api {
return &clean.Api{
Client: client.NewClient(endpointURLClean, opts...),
}
}
// NewSuggestApi provides suggestion API.
func NewSuggestApi(opts ...client.Option) *suggest.Api {
return &suggest.Api{
Client: client.NewClient(endpointURLSuggest, opts...),
}
}
// NewProfileApi provides profile related API.
func NewProfileApi(opts ...client.Option) *profile.Api {
return &profile.Api{
Client: client.NewClient(endpointURL, opts...),
}
}
// NewStatApi provides statistic API.
func NewStatApi(opts ...client.Option) *stat.Api {
return &stat.Api{
Client: client.NewClient(endpointURL, opts...),
}
}