-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtypes.go
97 lines (80 loc) · 2.42 KB
/
types.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
package main
import (
"fmt"
"strings"
)
type Metadata struct {
BuildNumber int `json:"id" db:"build_number"`
}
type Ingredient struct {
ID int `db:"id"`
ItemID int `json:"item_id" db:"item_id"`
Count int `json:"count" db:"count"`
RecipeID int `db:"recipe_id"`
}
type Recipe struct {
ID int `json:"id" db:"id"`
Type string `json:"type" db:"type"`
OutputItemID int `json:"output_item_id" db:"output_item_id"`
OutputItemCount int `json:"output_item_count" db:"output_item_count"`
Disciplines StringSlice `json:"disciplines" db:"disciplines"` // TODO: Define a StringSlice type?
MinRating int `json:"min_rating" db:"min_rating"`
Flags StringSlice `json:"flags" db:"flags"`
Ingredients []Ingredient `json:"ingredients"`
}
type Currency struct {
ID int `json:"id" db:"id"`
Name string `json:"name" db:"name"`
Description string `json:"description" db:"description"`
}
type WalletCurrency struct {
CurrencyID int `json:"id"`
Value int `json:"value"`
}
type MerchantItem struct {
ItemID int
Price WalletCurrency
}
type TradingPostPrice struct {
Quantity int `json:"quantity"`
UnitPrice int `json:"unit_price"`
}
type ItemPrice struct {
ID int `json:"id"`
Buys TradingPostPrice `json:"buys"`
Sells TradingPostPrice `json:"sells"`
}
func (tpPrice TradingPostPrice) String() string {
goldAmount := tpPrice.UnitPrice / 10000
silverAmount := (tpPrice.UnitPrice % 10000) / 100
copperAmount := tpPrice.UnitPrice % 100
priceString := fmt.Sprintf("%dg %ds %dc", goldAmount, silverAmount, copperAmount)
return fmt.Sprintf("Price: %s, Orders: %d", priceString, tpPrice.Quantity)
}
type RecipeIds []int
type Item struct {
Name string `json:"name" db:"name"`
Type string `json:"type" db:"type"`
Rarity string `json:"rarity" db:"rarity"`
VendorValue int `json:"vendor_value" db:"vendor_value"`
Flags StringSlice `json:"flags" db:"flags"`
ID int `json:"id" db:"id"`
}
type StringSlice []string
func (s *StringSlice) Scan(value interface{}) error {
if value == nil {
*s = nil
return nil
}
str, ok := value.(string)
if !ok {
return fmt.Errorf("unexpected type for StringSlice: %T", value)
}
*s = strings.Split(str, ",")
return nil
}
type RecipeProfit struct {
RecipeID int
OutputItemID int
ProfitMargin float64
}