The Glean Go SDK provides convenient access to the Glean REST API for Go 1.18+. It offers strongly typed request and response structs, context-based request handling, and uses the standard net/http package.
This SDK combines both the Client and Indexing API namespaces into a single unified package:
- Client API: Used for search, retrieval, and end-user interactions with Glean content
- Indexing API: Used for indexing content, permissions, and other administrative operations
Each namespace has its own authentication requirements and access patterns. While they serve different purposes, having them in a single SDK provides a consistent developer experience across all Glean API interactions.
// Example of accessing Client namespace
s := apiclientgo.New(
apiclientgo.WithSecurity("client-token"),
)
res, err := s.Client.Search.Query(ctx, components.SearchRequest{
Query: "search term",
})
// Example of accessing Indexing namespace
s := apiclientgo.New(
apiclientgo.WithSecurity("indexing-token"),
)
res, err := s.Indexing.Documents.Index(ctx, components.DocumentRequest{
// document data
})
Remember that each namespace requires its own authentication token type as described in the Authentication Methods section.
To add the SDK as a dependency to your project:
go get github.com/gleanwork/api-client-go
package main
import (
"context"
apiclientgo "github.com/gleanwork/api-client-go"
"github.com/gleanwork/api-client-go/models/components"
"log"
"os"
)
func main() {
ctx := context.Background()
s := apiclientgo.New(
apiclientgo.WithSecurity(os.Getenv("GLEAN_API_TOKEN")),
)
res, err := s.Client.Chat.Create(ctx, components.ChatRequest{
Messages: []components.ChatMessage{
components.ChatMessage{
Fragments: []components.ChatMessageFragment{
components.ChatMessageFragment{
Text: apiclientgo.String("What are the company holidays this year?"),
},
},
},
},
}, nil)
if err != nil {
log.Fatal(err)
}
if res.ChatResponse != nil {
// handle response
}
}
package main
import (
"context"
apiclientgo "github.com/gleanwork/api-client-go"
"github.com/gleanwork/api-client-go/models/components"
"log"
"os"
)
func main() {
ctx := context.Background()
s := apiclientgo.New(
apiclientgo.WithSecurity(os.Getenv("GLEAN_API_TOKEN")),
)
res, err := s.Client.Chat.CreateStream(ctx, components.ChatRequest{
Messages: []components.ChatMessage{
components.ChatMessage{
Fragments: []components.ChatMessageFragment{
components.ChatMessageFragment{
Text: apiclientgo.String("What are the company holidays this year?"),
},
},
},
},
}, nil)
if err != nil {
log.Fatal(err)
}
if res.ChatRequestStream != nil {
// handle response
}
}
This SDK supports the following security scheme globally:
Name | Type | Scheme | Environment Variable |
---|---|---|---|
APIToken |
http | HTTP Bearer | GLEAN_API_TOKEN |
You can configure it using the WithSecurity
option when initializing the SDK client instance. For example:
package main
import (
"context"
apiclientgo "github.com/gleanwork/api-client-go"
"github.com/gleanwork/api-client-go/models/components"
"github.com/gleanwork/api-client-go/types"
"log"
"os"
)
func main() {
ctx := context.Background()
s := apiclientgo.New(
apiclientgo.WithSecurity(os.Getenv("GLEAN_API_TOKEN")),
)
res, err := s.Client.Activity.Report(ctx, components.Activity{
Events: []components.ActivityEvent{
components.ActivityEvent{
Action: components.ActivityEventActionHistoricalView,
Timestamp: types.MustTimeFromString("2000-01-23T04:56:07.000Z"),
URL: "https://example.com/",
},
components.ActivityEvent{
Action: components.ActivityEventActionSearch,
Params: &components.ActivityEventParams{
Query: apiclientgo.String("query"),
},
Timestamp: types.MustTimeFromString("2000-01-23T04:56:07.000Z"),
URL: "https://example.com/search?q=query",
},
components.ActivityEvent{
Action: components.ActivityEventActionView,
Params: &components.ActivityEventParams{
Duration: apiclientgo.Int64(20),
Referrer: apiclientgo.String("https://example.com/document"),
},
Timestamp: types.MustTimeFromString("2000-01-23T04:56:07.000Z"),
URL: "https://example.com/",
},
},
})
if err != nil {
log.Fatal(err)
}
if res != nil {
// handle response
}
}
Glean supports different authentication methods depending on which API namespace you're using:
The Client namespace supports two authentication methods:
-
Manually Provisioned API Tokens
- Can be created by an Admin or a user with the API Token Creator role
- Used for server-to-server integrations
-
OAuth
- Requires OAuth setup to be completed by an Admin
- Used for user-based authentication flows
The Indexing namespace supports only one authentication method:
- Manually Provisioned API Tokens
- Can be created by an Admin or a user with the API Token Creator role
- Used for secure document indexing operations
Important
Client tokens will not work for Indexing operations, and Indexing tokens will not work for Client operations. You must use the appropriate token type for the namespace you're accessing.
For more information on obtaining the appropriate token type, please contact your Glean administrator.
Available methods
- Retrieve - Get Agent
- RetrieveSchemas - Get Agent Schemas
- List - Search Agents
- RunStream - Create Run, Stream Output
- Run - Create Run, Wait for Output
- Create - Create Answer
- Delete - Delete Answer
- Update - Update Answer
- Retrieve - Read Answer
- List - List Answers
- CreateToken - Create authentication token
- Create - Chat
- DeleteAll - Deletes all saved Chats owned by a user
- Delete - Deletes saved Chats
- Retrieve - Retrieves a Chat
- List - Retrieves all saved Chats
- RetrieveApplication - Gets the metadata for a custom Chat application
- UploadFiles - Upload files for Chat.
- RetrieveFiles - Get files uploaded by a user for Chat.
- DeleteFiles - Delete files uploaded by a user for chat.
- CreateStream - Chat
- AddItems - Add Collection item
- Create - Create Collection
- Delete - Delete Collection
- DeleteItem - Delete Collection item
- Update - Update Collection
- UpdateItem - Update Collection item
- Retrieve - Read Collection
- List - List Collections
- RetrievePermissions - Read document permissions
- Retrieve - Read documents
- RetrieveByFacets - Read documents by facets
- Summarize - Summarize documents
- List - List entities
- ReadPeople - Read people
- Retrieve - Gets specified policy
- Update - Updates an existing policy
- List - Lists policies
- Create - Creates new policy
- Download - Downloads violations CSV for policy
- Create - Creates new one-time report
- Download - Downloads violations CSV for report
- Status - Fetches report run status
- Retrieve - Read insights
- Retrieve - Read messages
- QueryAsAdmin - Search the index (admin)
- Autocomplete - Autocomplete
- RetrieveFeed - Feed of documents and events
- Recommendations - Recommend documents
- Query - Search
- Create - Create shortcut
- Delete - Delete shortcut
- Retrieve - Read shortcut
- List - List shortcuts
- Update - Update shortcut
- AddReminder - Create verification
- List - List verifications
- Verify - Update verification
- RotateToken - Rotate token
- Status - Beta: Get datasource status
- Add - Add or update datasource
- RetrieveConfig - Get datasource config
-
AddOrUpdate - Index document
-
Index - Index documents
-
BulkIndex - Bulk index documents
-
ProcessAll - Schedules the processing of uploaded documents
-
Delete - Delete document
-
Debug - Beta: Get document information
-
DebugMany - Beta: Get information of a batch of documents
-
CheckAccess - Check document access
-
Status- Get document upload and indexing status⚠️ Deprecated -
Count- Get document count⚠️ Deprecated
-
Debug - Beta: Get user information
-
Count- Get user count⚠️ Deprecated -
Index - Index employee
-
BulkIndex - Bulk index employees
-
ProcessAllEmployeesAndTeams - Schedules the processing of uploaded employees and teams
-
Delete - Delete employee
-
IndexTeam - Index team
-
DeleteTeam - Delete team
-
BulkIndexTeams - Bulk index teams
- UpdatePermissions - Update document permissions
- IndexUser - Index user
- BulkIndexUsers - Bulk index users
- IndexGroup - Index group
- BulkIndexGroups - Bulk index groups
- IndexMembership - Index membership
- BulkIndexMemberships - Bulk index memberships for a group
- ProcessMemberships - Schedules the processing of group memberships
- DeleteUser - Delete user
- DeleteGroup - Delete group
- DeleteMembership - Delete membership
- AuthorizeBetaUsers - Beta users
Some of the endpoints in this SDK support retries. If you use the SDK without any configuration, it will fall back to the default retry strategy provided by the API. However, the default retry strategy can be overridden on a per-operation basis, or across the entire SDK.
To change the default retry strategy for a single API call, simply provide a retry.Config
object to the call by using the WithRetries
option:
package main
import (
"context"
apiclientgo "github.com/gleanwork/api-client-go"
"github.com/gleanwork/api-client-go/models/components"
"github.com/gleanwork/api-client-go/retry"
"github.com/gleanwork/api-client-go/types"
"log"
"models/operations"
"os"
)
func main() {
ctx := context.Background()
s := apiclientgo.New(
apiclientgo.WithSecurity(os.Getenv("GLEAN_API_TOKEN")),
)
res, err := s.Client.Activity.Report(ctx, components.Activity{
Events: []components.ActivityEvent{
components.ActivityEvent{
Action: components.ActivityEventActionHistoricalView,
Timestamp: types.MustTimeFromString("2000-01-23T04:56:07.000Z"),
URL: "https://example.com/",
},
components.ActivityEvent{
Action: components.ActivityEventActionSearch,
Params: &components.ActivityEventParams{
Query: apiclientgo.String("query"),
},
Timestamp: types.MustTimeFromString("2000-01-23T04:56:07.000Z"),
URL: "https://example.com/search?q=query",
},
components.ActivityEvent{
Action: components.ActivityEventActionView,
Params: &components.ActivityEventParams{
Duration: apiclientgo.Int64(20),
Referrer: apiclientgo.String("https://example.com/document"),
},
Timestamp: types.MustTimeFromString("2000-01-23T04:56:07.000Z"),
URL: "https://example.com/",
},
},
}, operations.WithRetries(
retry.Config{
Strategy: "backoff",
Backoff: &retry.BackoffStrategy{
InitialInterval: 1,
MaxInterval: 50,
Exponent: 1.1,
MaxElapsedTime: 100,
},
RetryConnectionErrors: false,
}))
if err != nil {
log.Fatal(err)
}
if res != nil {
// handle response
}
}
If you'd like to override the default retry strategy for all operations that support retries, you can use the WithRetryConfig
option at SDK initialization:
package main
import (
"context"
apiclientgo "github.com/gleanwork/api-client-go"
"github.com/gleanwork/api-client-go/models/components"
"github.com/gleanwork/api-client-go/retry"
"github.com/gleanwork/api-client-go/types"
"log"
"os"
)
func main() {
ctx := context.Background()
s := apiclientgo.New(
apiclientgo.WithRetryConfig(
retry.Config{
Strategy: "backoff",
Backoff: &retry.BackoffStrategy{
InitialInterval: 1,
MaxInterval: 50,
Exponent: 1.1,
MaxElapsedTime: 100,
},
RetryConnectionErrors: false,
}),
apiclientgo.WithSecurity(os.Getenv("GLEAN_API_TOKEN")),
)
res, err := s.Client.Activity.Report(ctx, components.Activity{
Events: []components.ActivityEvent{
components.ActivityEvent{
Action: components.ActivityEventActionHistoricalView,
Timestamp: types.MustTimeFromString("2000-01-23T04:56:07.000Z"),
URL: "https://example.com/",
},
components.ActivityEvent{
Action: components.ActivityEventActionSearch,
Params: &components.ActivityEventParams{
Query: apiclientgo.String("query"),
},
Timestamp: types.MustTimeFromString("2000-01-23T04:56:07.000Z"),
URL: "https://example.com/search?q=query",
},
components.ActivityEvent{
Action: components.ActivityEventActionView,
Params: &components.ActivityEventParams{
Duration: apiclientgo.Int64(20),
Referrer: apiclientgo.String("https://example.com/document"),
},
Timestamp: types.MustTimeFromString("2000-01-23T04:56:07.000Z"),
URL: "https://example.com/",
},
},
})
if err != nil {
log.Fatal(err)
}
if res != nil {
// handle response
}
}
Handling errors in this SDK should largely match your expectations. All operations return a response object or an error, they will never return both.
By Default, an API error will return apierrors.APIError
. When custom error responses are specified for an operation, the SDK may also return their associated error. You can refer to respective Errors tables in SDK docs for more details on possible error types for each operation.
For example, the Create
function may return the following errors:
Error Type | Status Code | Content Type |
---|---|---|
apierrors.CollectionError | 422 | application/json |
apierrors.APIError | 4XX, 5XX | */* |
package main
import (
"context"
"errors"
apiclientgo "github.com/gleanwork/api-client-go"
"github.com/gleanwork/api-client-go/models/apierrors"
"github.com/gleanwork/api-client-go/models/components"
"github.com/gleanwork/api-client-go/types"
"log"
"os"
)
func main() {
ctx := context.Background()
s := apiclientgo.New(
apiclientgo.WithSecurity(os.Getenv("GLEAN_API_TOKEN")),
)
res, err := s.Client.Collections.Create(ctx, components.CreateCollectionRequest{
Name: "<value>",
AddedRoles: []components.UserRoleSpecification{
components.UserRoleSpecification{
Person: &components.Person{
Name: "George Clooney",
ObfuscatedID: "abc123",
RelatedDocuments: []components.RelatedDocuments{
components.RelatedDocuments{
QuerySuggestion: &components.QuerySuggestion{
Query: "app:github type:pull author:mortimer",
SearchProviderInfo: &components.SearchProviderInfo{
Name: apiclientgo.String("Google"),
SearchLinkURLTemplate: apiclientgo.String("https://www.google.com/search?q={query}&hl=en"),
},
Label: apiclientgo.String("Mortimer's PRs"),
Datasource: apiclientgo.String("github"),
RequestOptions: &components.SearchRequestOptions{
DatasourceFilter: apiclientgo.String("JIRA"),
DatasourcesFilter: []string{
"JIRA",
},
QueryOverridesFacetFilters: apiclientgo.Bool(true),
FacetFilters: []components.FacetFilter{
components.FacetFilter{
FieldName: apiclientgo.String("type"),
Values: []components.FacetFilterValue{
components.FacetFilterValue{
Value: apiclientgo.String("Spreadsheet"),
RelationType: components.RelationTypeEquals.ToPointer(),
},
components.FacetFilterValue{
Value: apiclientgo.String("Presentation"),
RelationType: components.RelationTypeEquals.ToPointer(),
},
},
},
},
FacetFilterSets: []components.FacetFilterSet{
components.FacetFilterSet{
Filters: []components.FacetFilter{
components.FacetFilter{
FieldName: apiclientgo.String("type"),
Values: []components.FacetFilterValue{
components.FacetFilterValue{
Value: apiclientgo.String("Spreadsheet"),
RelationType: components.RelationTypeEquals.ToPointer(),
},
components.FacetFilterValue{
Value: apiclientgo.String("Presentation"),
RelationType: components.RelationTypeEquals.ToPointer(),
},
},
},
},
},
components.FacetFilterSet{
Filters: []components.FacetFilter{
components.FacetFilter{
FieldName: apiclientgo.String("type"),
Values: []components.FacetFilterValue{
components.FacetFilterValue{
Value: apiclientgo.String("Spreadsheet"),
RelationType: components.RelationTypeEquals.ToPointer(),
},
components.FacetFilterValue{
Value: apiclientgo.String("Presentation"),
RelationType: components.RelationTypeEquals.ToPointer(),
},
},
},
},
},
components.FacetFilterSet{
Filters: []components.FacetFilter{
components.FacetFilter{
FieldName: apiclientgo.String("type"),
Values: []components.FacetFilterValue{
components.FacetFilterValue{
Value: apiclientgo.String("Spreadsheet"),
RelationType: components.RelationTypeEquals.ToPointer(),
},
components.FacetFilterValue{
Value: apiclientgo.String("Presentation"),
RelationType: components.RelationTypeEquals.ToPointer(),
},
},
},
},
},
},
FacetBucketSize: 977077,
AuthTokens: []components.AuthToken{
components.AuthToken{
AccessToken: "123abc",
Datasource: "gmail",
Scope: apiclientgo.String("email profile https://www.googleapis.com/auth/gmail.readonly"),
TokenType: apiclientgo.String("Bearer"),
AuthUser: apiclientgo.String("1"),
},
},
},
Ranges: []components.TextRange{
components.TextRange{
StartIndex: 86650,
Document: &components.Document{
Metadata: &components.DocumentMetadata{
Datasource: apiclientgo.String("datasource"),
ObjectType: apiclientgo.String("Feature Request"),
Container: apiclientgo.String("container"),
ParentID: apiclientgo.String("JIRA_EN-1337"),
MimeType: apiclientgo.String("mimeType"),
DocumentID: apiclientgo.String("documentId"),
CreateTime: types.MustNewTimeFromString("2000-01-23T04:56:07.000Z"),
UpdateTime: types.MustNewTimeFromString("2000-01-23T04:56:07.000Z"),
Components: []string{
"Backend",
"Networking",
},
Status: apiclientgo.String("[\"Done\"]"),
Pins: []components.PinDocument{
components.PinDocument{
AudienceFilters: []components.FacetFilter{
components.FacetFilter{
FieldName: apiclientgo.String("type"),
Values: []components.FacetFilterValue{
components.FacetFilterValue{
Value: apiclientgo.String("Spreadsheet"),
RelationType: components.RelationTypeEquals.ToPointer(),
},
components.FacetFilterValue{
Value: apiclientgo.String("Presentation"),
RelationType: components.RelationTypeEquals.ToPointer(),
},
},
},
},
DocumentID: "<id>",
},
},
Collections: []components.Collection{
components.Collection{
Name: "<value>",
Description: "meaty dial elegantly while react",
AudienceFilters: []components.FacetFilter{
components.FacetFilter{
FieldName: apiclientgo.String("type"),
Values: []components.FacetFilterValue{
components.FacetFilterValue{
Value: apiclientgo.String("Spreadsheet"),
RelationType: components.RelationTypeEquals.ToPointer(),
},
components.FacetFilterValue{
Value: apiclientgo.String("Presentation"),
RelationType: components.RelationTypeEquals.ToPointer(),
},
},
},
},
ID: 854591,
Items: []components.CollectionItem{
components.CollectionItem{
CollectionID: 697663,
Shortcut: &components.Shortcut{
InputAlias: "<value>",
},
ItemType: components.CollectionItemItemTypeText,
},
components.CollectionItem{
CollectionID: 697663,
Shortcut: &components.Shortcut{
InputAlias: "<value>",
},
ItemType: components.CollectionItemItemTypeText,
},
components.CollectionItem{
CollectionID: 697663,
Shortcut: &components.Shortcut{
InputAlias: "<value>",
},
ItemType: components.CollectionItemItemTypeText,
},
},
},
},
Interactions: &components.DocumentInteractions{
Reacts: []components.Reaction{
components.Reaction{},
components.Reaction{},
},
Shares: []components.Share{
components.Share{
NumDaysAgo: 365776,
},
components.Share{
NumDaysAgo: 365776,
},
components.Share{
NumDaysAgo: 365776,
},
},
},
Verification: &components.Verification{
State: components.StateDeprecated,
Metadata: &components.VerificationMetadata{
Reminders: []components.Reminder{
components.Reminder{
Assignee: components.Person{
Name: "George Clooney",
ObfuscatedID: "abc123",
},
RemindAt: 268615,
},
},
LastReminder: &components.Reminder{
Assignee: components.Person{
Name: "George Clooney",
ObfuscatedID: "abc123",
},
RemindAt: 423482,
},
},
},
Shortcuts: []components.Shortcut{
components.Shortcut{
InputAlias: "<value>",
},
components.Shortcut{
InputAlias: "<value>",
},
components.Shortcut{
InputAlias: "<value>",
},
},
CustomData: map[string]components.CustomDataValue{
"someCustomField": components.CustomDataValue{},
},
},
},
},
},
InputDetails: &components.SearchRequestInputDetails{
HasCopyPaste: apiclientgo.Bool(true),
},
},
Results: []components.SearchResult{
components.SearchResult{
Title: apiclientgo.String("title"),
URL: "https://example.com/foo/bar",
NativeAppURL: apiclientgo.String("slack://foo/bar"),
Snippets: []components.SearchResultSnippet{
components.SearchResultSnippet{
Snippet: "snippet",
MimeType: apiclientgo.String("mimeType"),
},
},
},
},
},
components.RelatedDocuments{
QuerySuggestion: &components.QuerySuggestion{
Query: "app:github type:pull author:mortimer",
SearchProviderInfo: &components.SearchProviderInfo{
Name: apiclientgo.String("Google"),
SearchLinkURLTemplate: apiclientgo.String("https://www.google.com/search?q={query}&hl=en"),
},
Label: apiclientgo.String("Mortimer's PRs"),
Datasource: apiclientgo.String("github"),
RequestOptions: &components.SearchRequestOptions{
DatasourceFilter: apiclientgo.String("JIRA"),
DatasourcesFilter: []string{
"JIRA",
},
QueryOverridesFacetFilters: apiclientgo.Bool(true),
FacetFilters: []components.FacetFilter{
components.FacetFilter{
FieldName: apiclientgo.String("type"),
Values: []components.FacetFilterValue{
components.FacetFilterValue{
Value: apiclientgo.String("Spreadsheet"),
RelationType: components.RelationTypeEquals.ToPointer(),
},
components.FacetFilterValue{
Value: apiclientgo.String("Presentation"),
RelationType: components.RelationTypeEquals.ToPointer(),
},
},
},
},
FacetFilterSets: []components.FacetFilterSet{
components.FacetFilterSet{
Filters: []components.FacetFilter{
components.FacetFilter{
FieldName: apiclientgo.String("type"),
Values: []components.FacetFilterValue{
components.FacetFilterValue{
Value: apiclientgo.String("Spreadsheet"),
RelationType: components.RelationTypeEquals.ToPointer(),
},
components.FacetFilterValue{
Value: apiclientgo.String("Presentation"),
RelationType: components.RelationTypeEquals.ToPointer(),
},
},
},
},
},
components.FacetFilterSet{
Filters: []components.FacetFilter{
components.FacetFilter{
FieldName: apiclientgo.String("type"),
Values: []components.FacetFilterValue{
components.FacetFilterValue{
Value: apiclientgo.String("Spreadsheet"),
RelationType: components.RelationTypeEquals.ToPointer(),
},
components.FacetFilterValue{
Value: apiclientgo.String("Presentation"),
RelationType: components.RelationTypeEquals.ToPointer(),
},
},
},
},
},
components.FacetFilterSet{
Filters: []components.FacetFilter{
components.FacetFilter{
FieldName: apiclientgo.String("type"),
Values: []components.FacetFilterValue{
components.FacetFilterValue{
Value: apiclientgo.String("Spreadsheet"),
RelationType: components.RelationTypeEquals.ToPointer(),
},
components.FacetFilterValue{
Value: apiclientgo.String("Presentation"),
RelationType: components.RelationTypeEquals.ToPointer(),
},
},
},
},
},
},
FacetBucketSize: 977077,
AuthTokens: []components.AuthToken{
components.AuthToken{
AccessToken: "123abc",
Datasource: "gmail",
Scope: apiclientgo.String("email profile https://www.googleapis.com/auth/gmail.readonly"),
TokenType: apiclientgo.String("Bearer"),
AuthUser: apiclientgo.String("1"),
},
},
},
Ranges: []components.TextRange{
components.TextRange{
StartIndex: 86650,
Document: &components.Document{
Metadata: &components.DocumentMetadata{
Datasource: apiclientgo.String("datasource"),
ObjectType: apiclientgo.String("Feature Request"),
Container: apiclientgo.String("container"),
ParentID: apiclientgo.String("JIRA_EN-1337"),
MimeType: apiclientgo.String("mimeType"),
DocumentID: apiclientgo.String("documentId"),
CreateTime: types.MustNewTimeFromString("2000-01-23T04:56:07.000Z"),
UpdateTime: types.MustNewTimeFromString("2000-01-23T04:56:07.000Z"),
Components: []string{
"Backend",
"Networking",
},
Status: apiclientgo.String("[\"Done\"]"),
Pins: []components.PinDocument{
components.PinDocument{
AudienceFilters: []components.FacetFilter{
components.FacetFilter{
FieldName: apiclientgo.String("type"),
Values: []components.FacetFilterValue{
components.FacetFilterValue{
Value: apiclientgo.String("Spreadsheet"),
RelationType: components.RelationTypeEquals.ToPointer(),
},
components.FacetFilterValue{
Value: apiclientgo.String("Presentation"),
RelationType: components.RelationTypeEquals.ToPointer(),
},
},
},
},
DocumentID: "<id>",
},
},
Collections: []components.Collection{
components.Collection{
Name: "<value>",
Description: "meaty dial elegantly while react",
AudienceFilters: []components.FacetFilter{
components.FacetFilter{
FieldName: apiclientgo.String("type"),
Values: []components.FacetFilterValue{
components.FacetFilterValue{
Value: apiclientgo.String("Spreadsheet"),
RelationType: components.RelationTypeEquals.ToPointer(),
},
components.FacetFilterValue{
Value: apiclientgo.String("Presentation"),
RelationType: components.RelationTypeEquals.ToPointer(),
},
},
},
},
ID: 854591,
Items: []components.CollectionItem{
components.CollectionItem{
CollectionID: 697663,
Shortcut: &components.Shortcut{
InputAlias: "<value>",
},
ItemType: components.CollectionItemItemTypeText,
},
components.CollectionItem{
CollectionID: 697663,
Shortcut: &components.Shortcut{
InputAlias: "<value>",
},
ItemType: components.CollectionItemItemTypeText,
},
components.CollectionItem{
CollectionID: 697663,
Shortcut: &components.Shortcut{
InputAlias: "<value>",
},
ItemType: components.CollectionItemItemTypeText,
},
},
},
},
Interactions: &components.DocumentInteractions{
Reacts: []components.Reaction{
components.Reaction{},
components.Reaction{},
},
Shares: []components.Share{
components.Share{
NumDaysAgo: 365776,
},
components.Share{
NumDaysAgo: 365776,
},
components.Share{
NumDaysAgo: 365776,
},
},
},
Verification: &components.Verification{
State: components.StateDeprecated,
Metadata: &components.VerificationMetadata{
Reminders: []components.Reminder{
components.Reminder{
Assignee: components.Person{
Name: "George Clooney",
ObfuscatedID: "abc123",
},
RemindAt: 268615,
},
},
LastReminder: &components.Reminder{
Assignee: components.Person{
Name: "George Clooney",
ObfuscatedID: "abc123",
},
RemindAt: 423482,
},
},
},
Shortcuts: []components.Shortcut{
components.Shortcut{
InputAlias: "<value>",
},
components.Shortcut{
InputAlias: "<value>",
},
components.Shortcut{
InputAlias: "<value>",
},
},
CustomData: map[string]components.CustomDataValue{
"someCustomField": components.CustomDataValue{},
},
},
},
},
},
InputDetails: &components.SearchRequestInputDetails{
HasCopyPaste: apiclientgo.Bool(true),
},
},
Results: []components.SearchResult{
components.SearchResult{
Title: apiclientgo.String("title"),
URL: "https://example.com/foo/bar",
NativeAppURL: apiclientgo.String("slack://foo/bar"),
Snippets: []components.SearchResultSnippet{
components.SearchResultSnippet{
Snippet: "snippet",
MimeType: apiclientgo.String("mimeType"),
},
},
},
},
},
},
Metadata: &components.PersonMetadata{
Type: components.PersonMetadataTypeFullTime.ToPointer(),
Title: apiclientgo.String("Actor"),
Department: apiclientgo.String("Movies"),
Email: apiclientgo.String("george@example.com"),
Location: apiclientgo.String("Hollywood, CA"),
Phone: apiclientgo.String("6505551234"),
PhotoURL: apiclientgo.String("https://example.com/george.jpg"),
StartDate: types.MustNewDateFromString("2000-01-23"),
DatasourceProfile: []components.DatasourceProfile{
components.DatasourceProfile{
Datasource: "github",
Handle: "<value>",
},
components.DatasourceProfile{
Datasource: "github",
Handle: "<value>",
},
},
QuerySuggestions: &components.QuerySuggestionList{
Suggestions: []components.QuerySuggestion{
components.QuerySuggestion{
Query: "app:github type:pull author:mortimer",
Label: apiclientgo.String("Mortimer's PRs"),
Datasource: apiclientgo.String("github"),
},
},
},
InviteInfo: &components.InviteInfo{
Invites: []components.ChannelInviteInfo{
components.ChannelInviteInfo{},
components.ChannelInviteInfo{},
},
},
CustomFields: []components.CustomFieldData{
components.CustomFieldData{
Label: "<value>",
Values: []components.CustomFieldValue{
components.CreateCustomFieldValueCustomFieldValueStr(
components.CustomFieldValueStr{},
),
components.CreateCustomFieldValueCustomFieldValueStr(
components.CustomFieldValueStr{},
),
components.CreateCustomFieldValueCustomFieldValueStr(
components.CustomFieldValueStr{},
),
},
},
components.CustomFieldData{
Label: "<value>",
Values: []components.CustomFieldValue{
components.CreateCustomFieldValueCustomFieldValueStr(
components.CustomFieldValueStr{},
),
components.CreateCustomFieldValueCustomFieldValueStr(
components.CustomFieldValueStr{},
),
components.CreateCustomFieldValueCustomFieldValueStr(
components.CustomFieldValueStr{},
),
},
},
},
Badges: []components.Badge{
components.Badge{
Key: apiclientgo.String("deployment_name_new_hire"),
DisplayName: apiclientgo.String("New hire"),
IconConfig: &components.IconConfig{
Color: apiclientgo.String("#343CED"),
Key: apiclientgo.String("person_icon"),
IconType: components.IconTypeGlyph.ToPointer(),
Name: apiclientgo.String("user"),
},
},
},
},
},
Role: components.UserRoleVerifier,
},
},
RemovedRoles: []components.UserRoleSpecification{
components.UserRoleSpecification{
Person: &components.Person{
Name: "George Clooney",
ObfuscatedID: "abc123",
Metadata: &components.PersonMetadata{
Type: components.PersonMetadataTypeFullTime.ToPointer(),
Title: apiclientgo.String("Actor"),
Department: apiclientgo.String("Movies"),
Email: apiclientgo.String("george@example.com"),
Location: apiclientgo.String("Hollywood, CA"),
Phone: apiclientgo.String("6505551234"),
PhotoURL: apiclientgo.String("https://example.com/george.jpg"),
StartDate: types.MustNewDateFromString("2000-01-23"),
DatasourceProfile: []components.DatasourceProfile{
components.DatasourceProfile{
Datasource: "github",
Handle: "<value>",
},
components.DatasourceProfile{
Datasource: "github",
Handle: "<value>",
},
},
QuerySuggestions: &components.QuerySuggestionList{
Suggestions: []components.QuerySuggestion{
components.QuerySuggestion{
Query: "app:github type:pull author:mortimer",
Label: apiclientgo.String("Mortimer's PRs"),
Datasource: apiclientgo.String("github"),
},
},
},
InviteInfo: &components.InviteInfo{
Invites: []components.ChannelInviteInfo{
components.ChannelInviteInfo{},
components.ChannelInviteInfo{},
},
},
Badges: []components.Badge{
components.Badge{
Key: apiclientgo.String("deployment_name_new_hire"),
DisplayName: apiclientgo.String("New hire"),
IconConfig: &components.IconConfig{
Color: apiclientgo.String("#343CED"),
Key: apiclientgo.String("person_icon"),
IconType: components.IconTypeGlyph.ToPointer(),
Name: apiclientgo.String("user"),
},
},
},
},
},
Role: components.UserRoleViewer,
},
},
AudienceFilters: []components.FacetFilter{
components.FacetFilter{
FieldName: apiclientgo.String("type"),
Values: []components.FacetFilterValue{
components.FacetFilterValue{
Value: apiclientgo.String("Spreadsheet"),
RelationType: components.RelationTypeEquals.ToPointer(),
},
components.FacetFilterValue{
Value: apiclientgo.String("Presentation"),
RelationType: components.RelationTypeEquals.ToPointer(),
},
},
},
},
})
if err != nil {
var e *apierrors.CollectionError
if errors.As(err, &e) {
// handle error
log.Fatal(e.Error())
}
var e *apierrors.APIError
if errors.As(err, &e) {
// handle error
log.Fatal(e.Error())
}
}
}
The default server https://{instance}-be.glean.com
contains variables and is set to https://instance-name-be.glean.com
by default. To override default values, the following options are available when initializing the SDK client instance:
Variable | Option | Default | Description |
---|---|---|---|
instance |
WithInstance(instance string) |
"instance-name" |
The instance name (typically the email domain without the TLD) that determines the deployment backend. |
package main
import (
"context"
apiclientgo "github.com/gleanwork/api-client-go"
"github.com/gleanwork/api-client-go/models/components"
"github.com/gleanwork/api-client-go/types"
"log"
"os"
)
func main() {
ctx := context.Background()
s := apiclientgo.New(
apiclientgo.WithInstance("<value>"),
apiclientgo.WithSecurity(os.Getenv("GLEAN_API_TOKEN")),
)
res, err := s.Client.Activity.Report(ctx, components.Activity{
Events: []components.ActivityEvent{
components.ActivityEvent{
Action: components.ActivityEventActionHistoricalView,
Timestamp: types.MustTimeFromString("2000-01-23T04:56:07.000Z"),
URL: "https://example.com/",
},
components.ActivityEvent{
Action: components.ActivityEventActionSearch,
Params: &components.ActivityEventParams{
Query: apiclientgo.String("query"),
},
Timestamp: types.MustTimeFromString("2000-01-23T04:56:07.000Z"),
URL: "https://example.com/search?q=query",
},
components.ActivityEvent{
Action: components.ActivityEventActionView,
Params: &components.ActivityEventParams{
Duration: apiclientgo.Int64(20),
Referrer: apiclientgo.String("https://example.com/document"),
},
Timestamp: types.MustTimeFromString("2000-01-23T04:56:07.000Z"),
URL: "https://example.com/",
},
},
})
if err != nil {
log.Fatal(err)
}
if res != nil {
// handle response
}
}
The default server can be overridden globally using the WithServerURL(serverURL string)
option when initializing the SDK client instance. For example:
package main
import (
"context"
apiclientgo "github.com/gleanwork/api-client-go"
"github.com/gleanwork/api-client-go/models/components"
"github.com/gleanwork/api-client-go/types"
"log"
"os"
)
func main() {
ctx := context.Background()
s := apiclientgo.New(
apiclientgo.WithServerURL("https://instance-name-be.glean.com"),
apiclientgo.WithSecurity(os.Getenv("GLEAN_API_TOKEN")),
)
res, err := s.Client.Activity.Report(ctx, components.Activity{
Events: []components.ActivityEvent{
components.ActivityEvent{
Action: components.ActivityEventActionHistoricalView,
Timestamp: types.MustTimeFromString("2000-01-23T04:56:07.000Z"),
URL: "https://example.com/",
},
components.ActivityEvent{
Action: components.ActivityEventActionSearch,
Params: &components.ActivityEventParams{
Query: apiclientgo.String("query"),
},
Timestamp: types.MustTimeFromString("2000-01-23T04:56:07.000Z"),
URL: "https://example.com/search?q=query",
},
components.ActivityEvent{
Action: components.ActivityEventActionView,
Params: &components.ActivityEventParams{
Duration: apiclientgo.Int64(20),
Referrer: apiclientgo.String("https://example.com/document"),
},
Timestamp: types.MustTimeFromString("2000-01-23T04:56:07.000Z"),
URL: "https://example.com/",
},
},
})
if err != nil {
log.Fatal(err)
}
if res != nil {
// handle response
}
}
The Go SDK makes API calls that wrap an internal HTTP client. The requirements for the HTTP client are very simple. It must match this interface:
type HTTPClient interface {
Do(req *http.Request) (*http.Response, error)
}
The built-in net/http
client satisfies this interface and a default client based on the built-in is provided by default. To replace this default with a client of your own, you can implement this interface yourself or provide your own client configured as desired. Here's a simple example, which adds a client with a 30 second timeout.
import (
"net/http"
"time"
"github.com/myorg/your-go-sdk"
)
var (
httpClient = &http.Client{Timeout: 30 * time.Second}
sdkClient = sdk.New(sdk.WithClient(httpClient))
)
This can be a convenient way to configure timeouts, cookies, proxies, custom headers, and other low-level configuration.
This SDK defines the following custom types to assist with marshalling and unmarshalling data.
types.Date
is a wrapper around time.Time that allows for JSON marshaling a date string formatted as "2006-01-02".
d1 := types.NewDate(time.Now()) // returns *types.Date
d2 := types.DateFromTime(time.Now()) // returns types.Date
d3, err := types.NewDateFromString("2019-01-01") // returns *types.Date, error
d4, err := types.DateFromString("2019-01-01") // returns types.Date, error
d5 := types.MustNewDateFromString("2019-01-01") // returns *types.Date and panics on error
d6 := types.MustDateFromString("2019-01-01") // returns types.Date and panics on error
This SDK is in beta, and there may be breaking changes between versions without a major version update. Therefore, we recommend pinning usage to a specific package version. This way, you can install the same version each time without breaking changes unless you are intentionally looking for the latest version.
While we value open-source contributions to this SDK, this library is generated programmatically. Any manual changes added to internal files will be overwritten on the next generation. We look forward to hearing your feedback. Feel free to open a PR or an issue with a proof of concept and we'll do our best to include it in a future release.