Go SDK

Idiomatic Go client with context support. No reflection. Requires Go 1.21+.

Installation

bash
go get github.com/kalimalab/kalimalab-go

Client initialization

go
package mainimport (    "os"    "github.com/kalimalab/kalimalab-go")func main() {    client := kalimalab.New(os.Getenv("KALIMALAB_API_KEY"))}

Methods

client.Words.Get

Fetch full details for a single word.

go
func (c *Client) Words.Get(ctx context.Context, slug string) (*Word, error)
ParamTypeReqDescription
slugstringYesWord slug or ID
go
word, err := client.Words.Get(ctx, "كتب")if err != nil { log.Fatal(err) }fmt.Println(word.MeaningEN) // "to write"
client.Words.Daily

Get 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.Validate

Validate Arabic words against the database.

go
func (c *Client) Words.Validate(ctx context.Context, words []string) (*ValidationResult, error)
ParamTypeReqDescription
words[]stringYesUp to 100 words
go
result, _ := client.Words.Validate(ctx, []string{"كتب", "xyz", "مدرسة"})fmt.Println(result.Valid)   // [كتب مدرسة]
client.Text.Analyze

Analyze a passage of Arabic text.

go
func (c *Client) Text.Analyze(ctx context.Context, text string) (*TextAnalysis, error)
ParamTypeReqDescription
textstringYesArabic text (max 5,000 characters)
go
analysis, _ := client.Text.Analyze(ctx, "بسم الله الرحمن الرحيم")fmt.Println(analysis.WordCount) // 4

Error 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.