SmartGen Docs Go
Your reading session

Page 28 of 68

Go

SmartGen Docs Go SDK

The SmartGen Go SDK provides high-performance Go microservices and tools with native client bindings for querying SmartGen documentation endpoints, verifying sitemaps, and interacting with developer portals [1].

Go Client Example

package smartgen

import (
    "fmt"
    "net/http"
)

type Client struct {
    BaseURL    string
    HTTPClient *http.Client
}

func NewClient(baseURL string) *Client {
    return &Client{
        BaseURL:    baseURL,
        HTTPClient: &http.Client{},
    }
}

func (c *Client) Ping() error {
    resp, err := c.HTTPClient.Get(c.BaseURL + "/robots.txt")
    if err != nil {
        return err
    }
    defer resp.Body.Close()
    if resp.StatusCode != http.StatusOK {
        return fmt.Errorf("unexpected status code: %d", resp.StatusCode)
    }
    return nil
}

References