Documentation
¶
Overview ¶
Package cellphones is the library behind the cellphones command line: the HTTP client, HTML scraping, and typed data models for CellphoneS (cellphones.com.vn), Vietnam's top mobile and tech retail chain.
Product detail pages embed JSON-LD Product schema. Category listings are fetched from the internal JSON API at /api/products. Product URLs follow the pattern: https://cellphones.com.vn/{slug}.html.
Index ¶
- Constants
- type Client
- func (c *Client) Get(ctx context.Context, rawURL string) ([]byte, error)
- func (c *Client) GetProduct(ctx context.Context, slug string) (*Product, error)
- func (c *Client) ListProducts(ctx context.Context, categoryID string, page, limit int) ([]*Product, error)
- func (c *Client) ListReviews(ctx context.Context, slug string, limit int) ([]*Review, error)
- type Config
- type Domain
- type Product
- type Review
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 mimics a real browser.
const Host = "cellphones.com.vn"
Host is the canonical site hostname.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client talks to the CellphoneS website over HTTP.
func NewClientWithConfig ¶
NewClientWithConfig returns a Client built from cfg.
func (*Client) Get ¶
Get fetches rawURL and returns the body bytes, pacing and retrying on transient errors.
func (*Client) GetProduct ¶
GetProduct fetches a product detail page by slug.
type Config ¶
type Config struct {
BaseURL string
Rate time.Duration
Retries int
Timeout time.Duration
UserAgent string
}
Config holds the tunable knobs for the HTTP client.
func DefaultConfig ¶
func DefaultConfig() Config
DefaultConfig returns sensible production defaults.
type Domain ¶
type Domain struct{}
Domain is the CellphoneS kit driver.
func (Domain) Info ¶
func (Domain) Info() kit.DomainInfo
type Product ¶
type Product struct {
Slug string `json:"slug" kit:"id" table:"slug"`
Name string `json:"name" table:"name"`
URL string `json:"url,omitempty" table:"url,url"`
Price float64 `json:"price" table:"price"`
OldPrice float64 `json:"old_price,omitempty" table:"old_price"`
Brand string `json:"brand,omitempty" table:"brand"`
Category string `json:"category,omitempty" table:"category"`
Description string `json:"description,omitempty" table:"-"`
Rating float64 `json:"rating,omitempty" table:"rating"`
ReviewCount int `json:"review_count,omitempty" table:"reviews"`
IsGenuine bool `json:"is_genuine,omitempty" table:"genuine"`
WarrantyMonths int `json:"warranty_months,omitempty" table:"warranty_mo"`
PreOrder bool `json:"pre_order,omitempty" table:"pre_order"`
FetchedAt string `json:"fetched_at,omitempty" table:"fetched_at"`
}
Product is one CellphoneS product.
type Review ¶
type Review struct {
ID string `json:"id" kit:"id" table:"id"`
ProductSlug string `json:"product_slug" table:"product_slug"`
CustomerName string `json:"customer_name,omitempty" table:"customer_name"`
Rating int `json:"rating" table:"rating"`
Content string `json:"content,omitempty" table:"-"`
HelpfulCount int `json:"helpful_count,omitempty" table:"helpful"`
CreatedAt string `json:"created_at,omitempty" table:"created_at"`
FetchedAt string `json:"fetched_at,omitempty" table:"fetched_at"`
}
Review is one customer review.