Go SDK
Idiomatic Go client with context support. No reflection. Requires Go 1.21+.
Installation
bash
go get github.com/kalimalab/kalimalab-goClient initialization
go
package mainimport ( "os" "github.com/kalimalab/kalimalab-go")func main() { client := kalimalab.New(os.Getenv("KALIMALAB_API_KEY"))}Methods
client.Words.SearchSearch Arabic words with optional filters.
go
func (c *Client) Words.Search(ctx context.Context, params SearchParams) (*SearchResult, error)| Param | Type | Req | Description |
|---|---|---|---|
ctx | context.Context | Yes | Request context |
Q | string | Yes | Search query |
Limit | int | No | 1–100. Default: 20 |
Offset | int | No | Pagination offset |
Root | string | No | Filter by root |
POS | string | No | Part-of-speech filter |
go
result, err := client.Words.Search(ctx, kalimalab.SearchParams{ Q: "كتب", Limit: 10,})if err != nil { log.Fatal(err) }fmt.Println(result.Total) // 47client.Words.GetFetch full details for a single word.
go
func (c *Client) Words.Get(ctx context.Context, slug string) (*Word, error)| Param | Type | Req | Description |
|---|---|---|---|
slug | string | Yes | Word slug or ID |
go
word, err := client.Words.Get(ctx, "كتب")if err != nil { log.Fatal(err) }fmt.Println(word.MeaningEN) // "to write"client.Words.DailyGet the word of the day.
go
func (c *Client) Words.Daily(ctx context.Context) (*Word, error)go
word, err := client.Words.Daily(ctx)fmt.Println(word.Word) // 'الأَمَل'client.Words.ValidateValidate Arabic words against the database.
go
func (c *Client) Words.Validate(ctx context.Context, words []string) (*ValidationResult, error)| Param | Type | Req | Description |
|---|---|---|---|
words | []string | Yes | Up to 100 words |
go
result, _ := client.Words.Validate(ctx, []string{"كتب", "xyz", "مدرسة"})fmt.Println(result.Valid) // [كتب مدرسة]client.Text.AnalyzeAnalyze a passage of Arabic text.
go
func (c *Client) Text.Analyze(ctx context.Context, text string) (*TextAnalysis, error)| Param | Type | Req | Description |
|---|---|---|---|
text | string | Yes | Arabic text (max 5,000 characters) |
go
analysis, _ := client.Text.Analyze(ctx, "بسم الله الرحمن الرحيم")fmt.Println(analysis.WordCount) // 4Error handling
go
result, err := client.Words.Search(ctx, params)if err != nil { var kErr *kalimalab.Error if errors.As(err, &kErr) { fmt.Println(kErr.Status) // 401, 429, 500 fmt.Println(kErr.Code) // "unauthorized", "rate_limited" fmt.Println(kErr.Message) }}All methods accept a context.Context as the first argument. Pass a context with a deadline or cancellation to control request timeouts.