Documentation ¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is a transport for API calls.
func NewClient ¶
NewClient Create new client of DaData. Api and secret keys see on profile page (https://dadata.ru/profile/). By default client uses `DADATA_API_KEY` and `DADATA_SECRET_KEY` environment variables.
Example ¶
var err error endpointUrl, err := url.Parse("https://suggestions.dadata.ru/suggestions/api/4_1/rs/") if err != nil { return } api := suggest.Api{ Client: NewClient(endpointUrl), } params := suggest.RequestParams{ Query: "ул Свободы", } suggestions, err := api.Address(context.Background(), ¶ms) if err != nil { return } for _, s := range suggestions { fmt.Printf("%s", s.Value) }
Output:
type CredentialProvider ¶
CredentialProvider provides DaData API access keys.
type Credentials ¶
Credentials provides constant credential values.
Example ¶
var err error endpointUrl, err := url.Parse("https://suggestions.dadata.ru/suggestions/api/4_1/rs/") if err != nil { return } creds := Credentials{ ApiKeyValue: "<YOUR_API_KEY>", SecretKeyValue: "<YOUR_SECRET_KEY>", } api := suggest.Api{ Client: NewClient(endpointUrl, WithCredentialProvider(&creds)), } params := suggest.RequestParams{ Query: "ул Свободы", } suggestions, err := api.Address(context.Background(), ¶ms) if err != nil { return } for _, s := range suggestions { fmt.Printf("%s", s.Value) }
Output:
func (*Credentials) ApiKey ¶
func (c *Credentials) ApiKey() string
func (*Credentials) SecretKey ¶
func (c *Credentials) SecretKey() string
type EnvironmentCredentials ¶
EnvironmentCredentials provides credentials from environment variables.
func (*EnvironmentCredentials) ApiKey ¶
func (c *EnvironmentCredentials) ApiKey() string
func (*EnvironmentCredentials) SecretKey ¶
func (c *EnvironmentCredentials) SecretKey() string
type Option ¶
type Option func(opts *clientOptions)
Option applies some option to clientOptions.
func WithCredentialProvider ¶
func WithCredentialProvider(c CredentialProvider) Option
WithCredentialProvider sets credential provider.
func WithDecoderFactory ¶
func WithDecoderFactory(f transport.DecoderFactory) Option
func WithEncoderFactory ¶
func WithEncoderFactory(f transport.EncoderFactory) Option
Example ¶
var err error endpointUrl, err := url.Parse("https://suggestions.dadata.ru/suggestions/api/4_1/rs/") if err != nil { return } // Customize json encoding encoderFactory := func(w io.Writer) transport.Encoder { e := json.NewEncoder(w) e.SetIndent("", " ") return func(v interface{}) error { return e.Encode(v) } } // Customize json decoding decoderFactory := func(r io.Reader) transport.Decoder { d := json.NewDecoder(r) d.DisallowUnknownFields() return func(v interface{}) error { return d.Decode(v) } } api := suggest.Api{ Client: NewClient(endpointUrl, WithEncoderFactory(encoderFactory), WithDecoderFactory(decoderFactory)), } params := suggest.RequestParams{ Query: "ул Свободы", } suggestions, err := api.Address(context.Background(), ¶ms) if err != nil { return } for _, s := range suggestions { fmt.Printf("%s", s.Value) }
Output:
func WithHttpClient ¶
WithHttpClient sets custom http.Client.
type ResponseError ¶
ResponseError indicates an HTTP non-200 response code.
func (*ResponseError) Error ¶
func (e *ResponseError) Error() string
Click to show internal directories.
Click to hide internal directories.