Official Go SDK for the FastComments API.
go get github.com/fastcomments/fastcomments-goThe PublicAPI allows unauthenticated access to public endpoints:
package main
import (
"context"
"fmt"
"github.com/fastcomments/fastcomments-go/client"
)
func main() {
config := client.NewConfiguration()
apiClient := client.NewAPIClient(config)
// Get comments using PublicAPI
response, httpResp, err := apiClient.PublicAPI.GetCommentsPublic(
context.Background(),
"your-tenant-id",
).UrlId("your-page-url-id").Execute()
if err != nil {
panic(err)
}
fmt.Printf("Status: %d\n", httpResp.StatusCode)
fmt.Printf("Comments: %+v\n", response)
}The DefaultAPI requires authentication using your API key:
package main
import (
"context"
"fmt"
"github.com/fastcomments/fastcomments-go/client"
)
func main() {
config := client.NewConfiguration()
apiClient := client.NewAPIClient(config)
// Create authenticated context with API key
auth := context.WithValue(
context.Background(),
client.ContextAPIKeys,
map[string]client.APIKey{
"api_key": {Key: "your-api-key-here"},
},
)
// Get comments using authenticated DefaultAPI
response, httpResp, err := apiClient.DefaultAPI.GetComments(auth).
TenantId("your-tenant-id").
UrlId("your-page-url-id").
Execute()
if err != nil {
panic(err)
}
fmt.Printf("Status: %d\n", httpResp.StatusCode)
fmt.Printf("Comments: %+v\n", response)
}package main
import (
"context"
"fmt"
"github.com/fastcomments/fastcomments-go/client"
"github.com/fastcomments/fastcomments-go/sso"
)
func main() {
// Create Simple SSO token
user := &sso.SimpleSSOUserData{
UserID: "user-123",
Email: "user@example.com",
Avatar: "https://example.com/avatar.jpg",
}
ssoInstance := sso.NewSimple(user)
token, err := ssoInstance.CreateToken()
if err != nil {
panic(err)
}
fmt.Println("SSO Token:", token)
// Use the SSO token to make an authenticated API call
config := client.NewConfiguration()
apiClient := client.NewAPIClient(config)
response, httpResp, err := apiClient.PublicAPI.GetCommentsPublic(
context.Background(),
"your-tenant-id",
).UrlId("your-page-url-id").Sso(token).Execute()
if err != nil {
panic(err)
}
fmt.Printf("Status: %d\n", httpResp.StatusCode)
fmt.Printf("Comments: %+v\n", response)
}package main
import (
"context"
"fmt"
"github.com/fastcomments/fastcomments-go/client"
"github.com/fastcomments/fastcomments-go/sso"
)
func main() {
// Create Secure SSO token
user := &sso.SecureSSOUserData{
UserID: "user-123",
Email: "user@example.com",
Username: "johndoe",
Avatar: "https://example.com/avatar.jpg",
}
apiKey := "your-api-key"
ssoInstance, err := sso.NewSecure(apiKey, user)
if err != nil {
panic(err)
}
token, err := ssoInstance.CreateToken()
if err != nil {
panic(err)
}
fmt.Println("Secure SSO Token:", token)
// Use the SSO token to make an authenticated API call
config := client.NewConfiguration()
apiClient := client.NewAPIClient(config)
response, httpResp, err := apiClient.PublicAPI.GetCommentsPublic(
context.Background(),
"your-tenant-id",
).UrlId("your-page-url-id").Sso(token).Execute()
if err != nil {
panic(err)
}
fmt.Printf("Status: %d\n", httpResp.StatusCode)
fmt.Printf("Comments: %+v\n", response)
}Set the required environment variables:
export FASTCOMMENTS_API_KEY="your-api-key"
export FASTCOMMENTS_TENANT_ID="your-tenant-id"Run the tests:
go test ./testsTo update the generated client from the OpenAPI spec:
./update.shThis will download the latest OpenAPI spec from a running FastComments server (or use a local copy) and regenerate the client code.
MIT License - see LICENSE file for details
For support, please visit https://fastcomments.com/auth/my-account/help or email support@fastcomments.com