chotot

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 15, 2026 License: Apache-2.0 Imports: 13 Imported by: 0

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

View Source
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.

View Source
const GatewayBase = "https://gateway.chotot.com"

GatewayBase is the REST gateway every request is built from.

View Source
const Host = "www.chotot.com"

Host is the display host claimed by the domain driver.

View Source
const ListingBase = "https://www.chotot.com"

ListingBase is the canonical web URL prefix for a single ad.

Variables

View Source
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 NewClient

func NewClient() *Client

NewClient returns a Client with DefaultConfig settings.

func NewClientWithConfig

func NewClientWithConfig(cfg Config) *Client

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) Get

func (c *Client) Get(ctx context.Context, rawURL string) ([]byte, error)

Get fetches rawURL and returns the full response body.

func (*Client) GetCategories

func (c *Client) GetCategories(ctx context.Context) ([]*Category, error)

GetCategories returns all Chợ Tốt listing categories.

func (*Client) GetListing

func (c *Client) GetListing(ctx context.Context, listID string) (*Listing, error)

GetListing fetches a single ad by its numeric list ID.

func (*Client) GetRegions

func (c *Client) GetRegions(ctx context.Context) ([]*Region, error)

GetRegions returns all Chợ Tốt regions (provinces/cities).

func (*Client) SearchListings

func (c *Client) SearchListings(ctx context.Context, query string, page, limit int) ([]*Listing, error)

SearchListings searches for listings matching query. page is 1-indexed.

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

func (Domain) Classify(input string) (uriType, id string, err error)

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.

func (Domain) Locate

func (Domain) Locate(uriType, id string) (string, error)

Locate is the inverse: the canonical https URL for a (uriType, id).

func (Domain) Register

func (Domain) Register(app *kit.App)

Register installs the client factory and every operation onto app.

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.

type Param

type Param struct {
	Label string `json:"label"`
	Value string `json:"value"`
}

Param is a structured attribute on a listing (e.g. brand, year, condition).

type Region

type Region struct {
	ID   string `json:"id"  kit:"id"`
	Name string `json:"name"`
}

Region is a Vietnamese province or city served by Chợ Tốt.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL