-
Notifications
You must be signed in to change notification settings - Fork 1
/
types.go
111 lines (95 loc) · 2.07 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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
package esiapi
import (
"strconv"
"sync"
"time"
)
// An inventory type
type MarketType struct {
Name string
Id int
}
// A collection of inventory types
type MarketTypes struct {
Types []*MarketType
byName map[string]*MarketType
byId map[int]*MarketType
m sync.Mutex
}
func (r *MarketTypes) ByName(name string) *MarketType {
if r.byName == nil {
r.m.Lock()
defer r.m.Unlock()
r.byName = make(map[string]*MarketType)
for _, mtype := range r.Types {
r.byName[mtype.Name] = mtype
}
}
return r.byName[name]
}
func (r *MarketTypes) ById(id int) *MarketType {
if r.byId == nil {
r.m.Lock()
defer r.m.Unlock()
r.byId = make(map[int]*MarketType)
for _, mtype := range r.Types {
r.byId[mtype.Id] = mtype
}
}
return r.byId[id]
}
// Build a new MarketTypes structure
func newMarketTypes() *MarketTypes {
return &MarketTypes{Types: make([]*MarketType, 0)}
}
// A station
type Station struct {
Name string `json:"name"`
Id int `json:"id"`
SolarSystem int `json:"solarsystem"`
}
type MarketOrder struct {
Bid bool
Duration int
Href string
Id int
Issued time.Time
Station Station
MinVolume int
VolumeEntered int
Price float64
Range string
Type MarketType
Volume int
}
const (
RangeSolarsystem = 0
RangeRegion = 65535
RangeStation = -1
)
// Numericrange returns the classical numeric range key
// based on the string input/
func (order *MarketOrder) NumericRange() int {
orderRange := 0
if order.Range == "solarsystem" {
orderRange = RangeSolarsystem
} else if order.Range == "region" {
orderRange = RangeRegion
} else if order.Range == "station" {
orderRange = RangeStation
} else {
or, _ := strconv.ParseInt(order.Range, 10, 64)
orderRange = int(or)
}
return orderRange
}
type MarketOrders struct {
RegionId int
Type *MarketType
Orders []*MarketOrder
Fetched time.Time
}
// Make a new MarketOrders structure
func NewMarketOrders() *MarketOrders {
return &MarketOrders{Orders: make([]*MarketOrder, 0)}
}