feat(server): 初始化HTTP服务器并添加产品数据结构
- 创建基础HTTP服务器,监听localhost:5000 - 实现StringHandle结构体处理HTTP请求 - 添加请求日志打印功能 - 忽略/favicon.ico请求并返回404状态 - 定义Product结构体及示例数据 - 实现产品税费计算和折扣应用方法
This commit is contained in:
31
24-httpserver/httpserver/product.go
Normal file
31
24-httpserver/httpserver/product.go
Normal file
@@ -0,0 +1,31 @@
|
||||
package main
|
||||
|
||||
type Product struct {
|
||||
Name, Category string
|
||||
Price float64
|
||||
}
|
||||
|
||||
var Kayak = Product{
|
||||
Name: "Kayak",
|
||||
Category: "Watersports",
|
||||
Price: 279,
|
||||
}
|
||||
|
||||
var ProductList = []Product{
|
||||
{"Kayak", "Watersports", 279},
|
||||
{"LifeJacket", "Watersports", 49.95},
|
||||
{"Soccer Ball", "Soccer", 19.50},
|
||||
{"Corner Flags", "Soccer", 34.95},
|
||||
{"Stadium", "Soccer", 79500},
|
||||
{"Thinking Cap", "Chess", 16},
|
||||
{"Unsteady Chair", "Chess", 75},
|
||||
{"Bling-Bling King", "Chess", 1200},
|
||||
}
|
||||
|
||||
func (p *Product) AddTax() float64 {
|
||||
return p.Price * 1.2
|
||||
}
|
||||
|
||||
func (p *Product) ApplyDiscount(amount float64) float64 {
|
||||
return p.Price - amount
|
||||
}
|
||||
Reference in New Issue
Block a user