or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

bpf.mdcontext-ctxhttp.mdcontext.mddict.mddns-dnsmessage.mdhtml-atom.mdhtml-charset.mdhtml.mdhttp-httpguts.mdhttp-httpproxy.mdhttp2-h2c.mdhttp2-hpack.mdhttp2.mdicmp.mdidna.mdindex.mdipv4.mdipv6.mdnettest.mdnetutil.mdproxy.mdpublicsuffix.mdquic-qlog.mdquic.mdtrace.mdwebdav.mdwebsocket.mdxsrftoken.md
tile.json

dict.mddocs/

DICT Protocol Client

Package dict implements the Dictionary Server Protocol as defined in RFC 2229.

The dict package is frozen and is not accepting new features.

Import

import "golang.org/x/net/dict"

Types

// Client represents a client connection to a dictionary server
type Client struct {
    // Has unexported fields
}

// Dict represents a dictionary available on the server
type Dict struct {
    Name string // short name of dictionary
    Desc string // long description
}

// Defn represents a definition
type Defn struct {
    Dict Dict   // Dict where definition was found
    Word string // Word being defined
    Text []byte // Definition text, typically multiple lines
}

Functions

// Dial returns a new client connected to a dictionary server at addr on the given network
func Dial(network, addr string) (*Client, error)

Client Methods

// Close closes the connection to the dictionary server
func (c *Client) Close() error

// Define requests the definition of the given word
func (c *Client) Define(dict, word string) ([]*Defn, error)

// Dicts returns a list of the dictionaries available on the server
func (c *Client) Dicts() ([]Dict, error)

Define

Define requests the definition of the given word. The argument dict names the dictionary to use, the Name field of a Dict returned by Dicts.

The special dictionary name "*" means to look in all the server's dictionaries. The special dictionary name "!" means to look in all the server's dictionaries in turn, stopping after finding the word in one of them.

Usage Examples

Connect and Query Dictionary

import (
    "fmt"
    "golang.org/x/net/dict"
)

func lookupWord(word string) error {
    // Connect to dict.org dictionary server
    client, err := dict.Dial("tcp", "dict.org:2628")
    if err != nil {
        return err
    }
    defer client.Close()

    // Get available dictionaries
    dicts, err := client.Dicts()
    if err != nil {
        return err
    }

    fmt.Println("Available dictionaries:")
    for _, d := range dicts {
        fmt.Printf("  %s: %s\n", d.Name, d.Desc)
    }

    // Define word in all dictionaries
    definitions, err := client.Define("*", word)
    if err != nil {
        return err
    }

    fmt.Printf("\nDefinitions for '%s':\n", word)
    for _, def := range definitions {
        fmt.Printf("\nFrom %s (%s):\n", def.Dict.Name, def.Dict.Desc)
        fmt.Printf("%s\n", def.Text)
    }

    return nil
}

Search in Specific Dictionary

func lookupInSpecificDict(dictName, word string) error {
    client, err := dict.Dial("tcp", "dict.org:2628")
    if err != nil {
        return err
    }
    defer client.Close()

    // Use "!" to search in sequence until found
    definitions, err := client.Define("!", word)
    if err != nil {
        return err
    }

    if len(definitions) > 0 {
        fmt.Printf("Found in %s:\n%s\n",
            definitions[0].Dict.Name,
            definitions[0].Text)
    }

    return nil
}