Documentation
¶
Overview ¶
Package chotot is the library behind the chotot command: the HTTP client, request shaping, and typed data models for Chợ Tốt (chotot.com), Vietnam's largest classifieds marketplace.
The client talks to gateway.chotot.com over plain HTTPS, shapes each API response into clean Go records, and paces requests so a busy session stays polite. No API key or account is required for the public listing endpoints.
domain.go exposes chotot as a kit Domain: a driver that a multi-domain host (ant) enables with a single blank import,
import _ "github.com/tamnd/chotot-cli/chotot"
The init below registers it; the host then dereferences chotot:// URIs by routing to the operations Register installs. The same Domain also builds the standalone chotot binary, so the binary and a host share one source of truth.
Index ¶
- Constants
- Variables
- type Category
- type Client
- func (c *Client) BrowseListings(ctx context.Context, categoryID, regionID, page, limit int) ([]*Listing, error)
- func (c *Client) Get(ctx context.Context, rawURL string) ([]byte, error)
- func (c *Client) GetCategories(ctx context.Context) ([]*Category, error)
- func (c *Client) GetListing(ctx context.Context, listID string) (*Listing, error)
- func (c *Client) GetRegions(ctx context.Context) ([]*Region, error)
- func (c *Client) SearchListings(ctx context.Context, query string, page, limit int) ([]*Listing, error)
- type Config
- type Domain
- type Listing
- type Param
- type Region
Constants ¶
const DefaultUserAgent = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36"
DefaultUserAgent is the UA sent with every request.
const GatewayBase = "https://gateway.chotot.com"
GatewayBase is the REST gateway every request is built from.
const Host = "www.chotot.com"
Host is the display host claimed by the domain driver.
const ListingBase = "https://www.chotot.com"
ListingBase is the canonical web URL prefix for a single ad.
Variables ¶
var ErrNotFound = errors.New("chotot: not found")
ErrNotFound is returned when the API reports no ad for the requested id.
Functions ¶
This section is empty.
Types ¶
type Category ¶
type Category struct {
ID string `json:"id" kit:"id"`
Name string `json:"name"`
ParentID string `json:"parent_id,omitempty"`
Parent string `json:"parent,omitempty"`
}
Category is a Chợ Tốt listing category.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client talks to the Chợ Tốt public REST API.
func NewClientWithConfig ¶
NewClientWithConfig returns a Client built from cfg.
func (*Client) BrowseListings ¶
func (c *Client) BrowseListings(ctx context.Context, categoryID, regionID, page, limit int) ([]*Listing, error)
BrowseListings lists recent ads, optionally filtered by numeric category ID and/or region ID. Passing 0 for either omits that filter.
func (*Client) GetCategories ¶
GetCategories returns all Chợ Tốt listing categories.
func (*Client) GetListing ¶
GetListing fetches a single ad by its numeric list ID.
func (*Client) GetRegions ¶
GetRegions returns all Chợ Tốt regions (provinces/cities).
type Config ¶
type Config struct {
// BaseURL overrides the gateway host (used in tests).
BaseURL string
UserAgent string
Rate time.Duration
Timeout time.Duration
Retries int
}
Config holds the constructor parameters for a Client.
func DefaultConfig ¶
func DefaultConfig() Config
DefaultConfig returns sensible production defaults.
type Domain ¶
type Domain struct{}
Domain is the chotot driver. It carries no state.
func (Domain) Classify ¶
Classify turns any accepted input into the canonical (uriType, id). It accepts a bare numeric ID, a full chotot.com listing URL, or a chotot:// URI path.
func (Domain) Info ¶
func (Domain) Info() kit.DomainInfo
Info describes the domain's scheme, owned hosts, and binary identity.
type Listing ¶
type Listing struct {
ID string `json:"id" kit:"id" table:"id"`
Title string `json:"title" table:"title"`
Price int64 `json:"price,omitempty"`
PriceStr string `json:"price_string,omitempty" table:"price"`
Category string `json:"category,omitempty" table:"category"`
Region string `json:"region,omitempty" table:"region"`
Area string `json:"area,omitempty" table:"area"`
SellerName string `json:"seller_name,omitempty" table:"seller"`
IsPro bool `json:"is_pro,omitempty"`
IsVerified bool `json:"is_verified,omitempty"`
Condition string `json:"condition,omitempty"`
Body string `json:"body,omitempty" kit:"body" table:"-"`
Images []string `json:"images,omitempty" table:"-"`
Params []Param `json:"params,omitempty" table:"-"`
Phone string `json:"phone,omitempty" table:"-"`
ViewCount int `json:"view_count,omitempty"`
PostedAt string `json:"posted_at,omitempty"`
URL string `json:"url,omitempty" table:"url,url"`
}
Listing is one classified ad on Chợ Tốt.