fptshop

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

Documentation

Overview

Package fptshop is the library behind the fptshop command line: the HTTP client, HTML scraping, and typed data models for FPT Shop (fptshop.com.vn), Vietnam's major electronics retail chain.

Product detail pages embed JSON-LD Product schema for structured data. Category listings are fetched from an internal JSON API at /api/product/list. Product URLs follow the pattern: https://fptshop.com.vn/{category}/{slug}.

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.

View Source
const Host = "fptshop.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 FPT Shop 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) 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, path string) (*Product, error)

GetProduct fetches a product detail page by its two-segment path.

func (*Client) ListProducts

func (c *Client) ListProducts(ctx context.Context, categorySlug string, page, limit int) ([]*Product, error)

ListProducts fetches products from the internal category listing API.

func (*Client) ListReviews

func (c *Client) ListReviews(ctx context.Context, productPath string, limit int) ([]*Review, error)

ListReviews fetches customer reviews for a product by path.

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 FPT Shop kit driver.

func (Domain) Classify

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

func (Domain) Info

func (Domain) Info() kit.DomainInfo

func (Domain) Locate

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

func (Domain) Register

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

type Product

type Product struct {
	// Path is "{category-slug}/{product-slug}" — the canonical ID.
	Path        string  `json:"path"                    kit:"id" table:"path"`
	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"`
	Description string  `json:"description,omitempty"            table:"-"`
	Rating      float64 `json:"rating,omitempty"                 table:"rating"`
	ReviewCount int     `json:"review_count,omitempty"           table:"reviews"`
	FetchedAt   string  `json:"fetched_at,omitempty"             table:"fetched_at"`
}

Product is one FPT Shop product.

type Review

type Review struct {
	ID           string `json:"id"                    kit:"id" table:"id"`
	ProductPath  string `json:"product_path"                    table:"product_path"`
	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 from the FPT Shop API.

Jump to

Keyboard shortcuts

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