sendo

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: 12 Imported by: 0

Documentation

Overview

Package sendo is the library behind the sendo command line: the HTTP client, API parsing, and typed data models for Sendo (sendo.vn), a major Vietnamese e-commerce marketplace.

Sendo exposes an internal JSON API for product details. Listing pages and search results are parsed from HTML via JSON-LD or regex extraction. Product URLs follow the pattern: https://www.sendo.vn/{slug}-{id}.html.

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 mimics a real browser to avoid Cloudflare blocks.

View Source
const Host = "sendo.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 Sendo website over HTTP.

func NewClient

func NewClient() *Client

NewClient returns a Client from DefaultConfig.

func NewClientWithConfig

func NewClientWithConfig(cfg Config) *Client

NewClientWithConfig returns a Client built from cfg.

func (*Client) CategoryProducts

func (c *Client) CategoryProducts(ctx context.Context, slug string, limit int) ([]*Product, error)

CategoryProducts fetches products from a category listing page.

func (*Client) Get

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

Get fetches rawURL and returns the body bytes, pacing and retrying on transient errors.

func (*Client) GetProduct

func (c *Client) GetProduct(ctx context.Context, id string) (*Product, error)

GetProduct fetches full details for a single product by numeric ID.

func (*Client) SearchProducts

func (c *Client) SearchProducts(ctx context.Context, query string, limit int) ([]*Product, error)

SearchProducts fetches products matching a search query from the listing HTML.

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 Sendo driver.

func (Domain) Classify

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

Classify turns a Sendo URL or product ID into (type, id).

func (Domain) Info

func (Domain) Info() kit.DomainInfo

func (Domain) Locate

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

Locate returns the live https URL for a (type, id).

func (Domain) Register

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

type Product

type Product struct {
	ID              string  `json:"id"                         kit:"id" table:"id"`
	Name            string  `json:"name"                                table:"name"`
	URL             string  `json:"url,omitempty"                       table:"url,url"`
	Price           float64 `json:"price"                               table:"price"`
	OriginalPrice   float64 `json:"original_price,omitempty"            table:"original_price"`
	DiscountPercent int     `json:"discount_percent,omitempty"          table:"discount_percent"`
	SellerName      string  `json:"seller_name,omitempty"               table:"seller_name"`
	SellerRating    float64 `json:"seller_rating,omitempty"             table:"seller_rating"`
	Rating          float64 `json:"rating,omitempty"                    table:"rating"`
	ReviewCount     int     `json:"review_count,omitempty"              table:"reviews"`
	SoldCount       int64   `json:"sold_count,omitempty"                table:"sold"`
	IsAuthentic     bool    `json:"is_authentic,omitempty"              table:"authentic"`
	IsFreeShip      bool    `json:"is_freeship,omitempty"               table:"freeship"`
	Location        string  `json:"location,omitempty"                  table:"location"`
	FetchedAt       string  `json:"fetched_at,omitempty"                table:"fetched_at"`
}

Product is one Sendo product fetched from the internal API.

Jump to

Keyboard shortcuts

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