Go SDK
عميل Go اصطلاحي مع دعم context. بدون reflection. يدعم Go 1.21+.
التثبيت
go get github.com/kalimalab/kalimalab-goتهيئة العميل
package mainimport ( "os" "github.com/kalimalab/kalimalab-go")func main() { client := kalimalab.New(os.Getenv("KALIMALAB_API_KEY"))}الطرق
client.Words.Searchابحث في الكلمات العربية مع فلاتر اختيارية.
func (c *Client) Words.Search(ctx context.Context, params SearchParams) (*SearchResult, error)| Param | Type | Req | Description |
|---|---|---|---|
ctx | context.Context | Yes | سياق الطلب |
Q | string | Yes | استعلام البحث |
Limit | int | No | 1-100. الافتراضي: 20 |
Offset | int | No | إزاحة الترقيم |
Root | string | No | فلتر بالجذر |
POS | string | No | فلتر تصنيف الكلام |
result, err := client.Words.Search(ctx, kalimalab.SearchParams{ Q: "كتب", Limit: 10,})if err != nil { log.Fatal(err) }fmt.Println(result.Total) // 47client.Words.Getجلب التفاصيل الكاملة لكلمة واحدة.
func (c *Client) Words.Get(ctx context.Context, slug string) (*Word, error)| Param | Type | Req | Description |
|---|---|---|---|
slug | string | Yes | slug الكلمة أو معرّفها |
word, err := client.Words.Get(ctx, "كتب")if err != nil { log.Fatal(err) }fmt.Println(word.MeaningEN) // "to write"client.Words.Dailyاحصل على كلمة اليوم.
func (c *Client) Words.Daily(ctx context.Context) (*Word, error)word, err := client.Words.Daily(ctx)fmt.Println(word.Word) // 'الأَمَل'client.Words.Validateتحقق من صحة الكلمات العربية في قاعدة البيانات.
func (c *Client) Words.Validate(ctx context.Context, words []string) (*ValidationResult, error)| Param | Type | Req | Description |
|---|---|---|---|
words | []string | Yes | حتى 100 كلمة |
result, _ := client.Words.Validate(ctx, []string{"كتب", "xyz", "مدرسة"})fmt.Println(result.Valid) // [كتب مدرسة]client.Text.Analyzeحلّل مقطعاً من النص العربي.
func (c *Client) Text.Analyze(ctx context.Context, text string) (*TextAnalysis, error)| Param | Type | Req | Description |
|---|---|---|---|
text | string | Yes | نص عربي (حد أقصى 5,000 حرف) |
analysis, _ := client.Text.Analyze(ctx, "بسم الله الرحمن الرحيم")fmt.Println(analysis.WordCount) // 4معالجة الأخطاء
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) }}جميع الطرق تقبل context.Context كأول وسيطة. مرّر context مع موعد نهائي أو إلغاء للتحكم في مهل الطلبات.