// Geolocation API SDK // Auto-generated — v1.0 package geolocation import ( "bytes" "encoding/json" "fmt" "io" "net/http" "net/url" "time" ) type Client struct { BaseURL string Token string HTTPClient *http.Client } func NewClient(token string, baseURL ...string) *Client { base := "https://api.aikdata.com/v1/geo" if len(baseURL) > 0 && baseURL[0] != "" { base = baseURL[0] } return &Client{ BaseURL: base, Token: token, HTTPClient: &http.Client{Timeout: 30 * time.Second}, } } type Response struct { Status int Data map[string]interface{} } // ── Geocoding ── // GeocodeAddress — Convert address to coordinates func (c *Client) GeocodeAddress(query url.Values) (*Response, error) { return c.doRequest("GET", "/geocode", query, nil) } // ReverseGeocode — Convert coordinates to address func (c *Client) ReverseGeocode(query url.Values) (*Response, error) { return c.doRequest("GET", "/reverse", query, nil) } func (c *Client) doRequest(method, path string, query url.Values, body map[string]interface{}) (*Response, error) { u := c.BaseURL + path if len(query) > 0 { u += "?" + query.Encode() } var reqBody io.Reader if body != nil { b, _ := json.Marshal(body) reqBody = bytes.NewBuffer(b) } req, err := http.NewRequest(method, u, reqBody) if err != nil { return nil, err } req.Header.Set("Authorization", "Bearer "+c.Token) req.Header.Set("Content-Type", "application/json") req.Header.Set("Accept", "application/json") resp, err := c.HTTPClient.Do(req) if err != nil { return nil, err } defer resp.Body.Close() data := map[string]interface{}{} _ = json.NewDecoder(resp.Body).Decode(&data) return &Response{Status: resp.StatusCode, Data: data}, nil }