Documentation
¶
Overview ¶
Package model encapsulates the persistence layer and higher level functionality in a MOTKI application.
This package is responsible for retrieving data from third-party sources, storing it, manipulating it, etc. Most data is stored in the application's database and all remote calls are throttled. Types are normalized in this package to provide a uniform interface as well as augmentation of the raw data.
Using This Package ¶
This package is meant for use by both the client and server portions of the MOTKI protocol. All Manager types, however, cannot be used by the client as they require a direct database connection.
Generally, this package should be used over the evedb, eveapi, and evemarketer packages.
Index ¶
- Constants
- Variables
- func APIScopesForRole(r Role) []string
- type Alliance
- type Asset
- type AssetManager
- func (m *AssetManager) GetAssetSystem(a *Asset) (*evedb.System, error)
- func (m *AssetManager) GetCorporationAsset(ctx context.Context, corpID int, itemID int) (res *Asset, err error)
- func (m *AssetManager) GetCorporationAssets(ctx context.Context, corpID int) (res []*Asset, err error)
- func (m *AssetManager) GetCorporationAssetsByTypeAndLocationID(ctx context.Context, corpID, typeID, locationID int) (res []*Asset, err error)
- type Authorization
- type Blueprint
- type BlueprintKind
- type BlueprintManager
- type Character
- type CharacterManager
- type CorpManager
- func (m *CorpManager) FetchCorporationDetail(ctx context.Context) (*CorporationDetail, error)
- func (m *CorpManager) GetAlliance(allianceID int) (*Alliance, error)
- func (m *CorpManager) GetCorporation(corporationID int) (*Corporation, error)
- func (m *CorpManager) GetCorporationAuthorization(corpID int) (*Authorization, error)
- func (m *CorpManager) GetCorporationConfig(corpID int) (*CorporationConfig, error)
- func (m *CorpManager) GetCorporationDetail(corpID int) (*CorporationDetail, error)
- func (m *CorpManager) GetCorporationsOptedIn() ([]int, error)
- func (m *CorpManager) SaveCorporationConfig(corpID int, detail *CorporationConfig) error
- type Corporation
- type CorporationConfig
- type CorporationDetail
- type CorporationStructure
- type Divisions
- type IndustryJob
- type IndustryManager
- type InventoryItem
- type InventoryManager
- func (m *InventoryManager) GetCorporationInventory(ctx context.Context, corpID int) (items []*InventoryItem, err error)
- func (m *InventoryManager) NewInventoryItem(ctx context.Context, corpID, typeID, locationID int) (*InventoryItem, error)
- func (m *InventoryManager) SaveInventoryItem(ctx context.Context, item *InventoryItem) error
- type Location
- type LocationManager
- type MailManager
- type MailingListSubscriber
- type Manager
- type MarketManager
- func (m *MarketManager) GetCorporationOrder(ctx context.Context, corpID, orderID int) (*MarketOrder, error)
- func (m *MarketManager) GetCorporationOrders(ctx context.Context, corpID int) (orders []*MarketOrder, err error)
- func (m *MarketManager) GetMarketPrice(typeID int) (*MarketPrice, error)
- func (m *MarketManager) GetMarketPrices(typeID int, typeIDs ...int) ([]*MarketPrice, error)
- func (m *MarketManager) GetMarketStat(typeID int, typeIDs ...int) ([]*MarketStat, error)
- func (m *MarketManager) GetMarketStatRegion(regionID int, typeID int, typeIDs ...int) ([]*MarketStat, error)
- func (m *MarketManager) GetMarketStatSystem(systemID int, typeID int, typeIDs ...int) ([]*MarketStat, error)
- type MarketOrder
- type MarketPrice
- type MarketStat
- type OrderState
- type Product
- type ProductKind
- type ProductManager
- func (m *ProductManager) GetAllProducts(corpID int) ([]*Product, error)
- func (m *ProductManager) GetProduct(corpID int, productID int) (*Product, error)
- func (m *ProductManager) NewProduct(corpID int, typeID int) (*Product, error)
- func (m *ProductManager) SaveProduct(product *Product) error
- func (m *ProductManager) UpdateProductMarketPrices(ctx context.Context, product *Product, regionID int) error
- func (m *ProductManager) UpdateProductMarketPricesRecursive(product *Product, regionID int) error
- type ReinforceHour
- type ReinforceWindow
- type Role
- type StatView
- type Structure
- type StructureManager
- type User
- type UserManager
- func (m *UserManager) AuthenticateUser(name, password string) (*User, string, error)
- func (m *UserManager) CreateUserVerificationHash(user *User) ([]byte, error)
- func (m *UserManager) GetAuthorization(user *User, role Role) (*Authorization, error)
- func (m *UserManager) GetUserBySessionKey(key string) (*User, error)
- func (m *UserManager) NewUser(name, email, password string) (*User, error)
- func (m *UserManager) RemoveAuthorization(user *User, role Role) error
- func (m *UserManager) SaveAuthorization(u *User, r Role, characterID int, tok *oauth2.Token) error
- func (m *UserManager) VerifyUserEmail(email string, hash []byte) (bool, error)
Constants ¶
const ( OrderStateOpen OrderState = "open" OrderStateExpired = "expired" OrderStateCancelled = "cancelled" )
Variables ¶
var ( ErrUserExists = errors.New("user already exists") ErrMissingField = errors.New("missing field") )
var ErrCorpNotRegistered = errors.New("ceo or director is not registered for the given corporation")
Functions ¶
func APIScopesForRole ¶
Types ¶
type Asset ¶
type Asset struct { ItemID int `json:"item_id"` LocationID int `json:"location_id"` LocationType string `json:"location_type"` LocationFlag string `json:"location_flag"` TypeID int `json:"type_id"` Quantity int `json:"quantity"` Singleton bool `json:"singleton"` // contains filtered or unexported fields }
type AssetManager ¶
type AssetManager struct {
// contains filtered or unexported fields
}
func (*AssetManager) GetAssetSystem ¶
func (m *AssetManager) GetAssetSystem(a *Asset) (*evedb.System, error)
func (*AssetManager) GetCorporationAsset ¶
func (*AssetManager) GetCorporationAssets ¶
func (*AssetManager) GetCorporationAssetsByTypeAndLocationID ¶
func (m *AssetManager) GetCorporationAssetsByTypeAndLocationID(ctx context.Context, corpID, typeID, locationID int) (res []*Asset, err error)
GetCorporationAssetsByTypeAndLocationID queries the database to find any assets with the given type and location.
This method will not fetch assets from the API.
type Authorization ¶
type Authorization struct { UserID int `json:"user_id"` CharacterID int `json:"character_id"` CorporationID int `json:"corporation_id"` Role Role `json:"role"` Token *oauth2.Token `json:"token"` // contains filtered or unexported fields }
func (*Authorization) Context ¶
func (a *Authorization) Context() context.Context
type Blueprint ¶
type Blueprint struct { ItemID int `json:"item_id"` LocationID int `json:"location_id"` LocationFlag string `json:"location_flag"` TypeID int `json:"type_id"` TimeEfficiency int `json:"time_efficiency"` MaterialEfficiency int `json:"material_efficiency"` Kind BlueprintKind `json:"kind"` Quantity int `json:"quantity"` // -1 = infinite runs (a BPO) Runs int `json:"runs"` }
type BlueprintKind ¶
type BlueprintKind string
var ( BlueprintOriginal BlueprintKind = "bpo" BlueprintCopy BlueprintKind = "bpc" )
type BlueprintManager ¶
type BlueprintManager struct {
// contains filtered or unexported fields
}
func (*BlueprintManager) GetCorporationBlueprints ¶
type Character ¶
type Character struct { CharacterID int `json:"character_id"` Name string `json:"name"` BloodlineID int `json:"bloodline_id"` RaceID int `json:"race_id"` AncestryID int `json:"ancestry_id"` CorporationID int `json:"corporation_id"` AllianceID int `json:"alliance_id"` BirthDate time.Time `json:"birth_date"` Description string `json:"description"` }
type CharacterManager ¶
type CharacterManager struct {
// contains filtered or unexported fields
}
func (*CharacterManager) GetCharacter ¶
func (m *CharacterManager) GetCharacter(characterID int) (*Character, error)
type CorpManager ¶
type CorpManager struct {
// contains filtered or unexported fields
}
func (*CorpManager) FetchCorporationDetail ¶
func (m *CorpManager) FetchCorporationDetail(ctx context.Context) (*CorporationDetail, error)
func (*CorpManager) GetAlliance ¶
func (m *CorpManager) GetAlliance(allianceID int) (*Alliance, error)
func (*CorpManager) GetCorporation ¶
func (m *CorpManager) GetCorporation(corporationID int) (*Corporation, error)
func (*CorpManager) GetCorporationAuthorization ¶
func (m *CorpManager) GetCorporationAuthorization(corpID int) (*Authorization, error)
func (*CorpManager) GetCorporationConfig ¶
func (m *CorpManager) GetCorporationConfig(corpID int) (*CorporationConfig, error)
func (*CorpManager) GetCorporationDetail ¶
func (m *CorpManager) GetCorporationDetail(corpID int) (*CorporationDetail, error)
func (*CorpManager) GetCorporationsOptedIn ¶
func (m *CorpManager) GetCorporationsOptedIn() ([]int, error)
func (*CorpManager) SaveCorporationConfig ¶
func (m *CorpManager) SaveCorporationConfig(corpID int, detail *CorporationConfig) error
type Corporation ¶
type CorporationConfig ¶
type CorporationDetail ¶
type CorporationDetail struct { CorporationID int `json:"corporation_id"` CEOID int `json:"ceoid"` CEOName string `json:"ceo_name"` StationID int `json:"station_id"` StationName string `json:"station_name"` FactionID int `json:"faction_id"` MemberCount int `json:"member_count"` Wallets Divisions `json:"wallets"` Hangars Divisions `json:"hangars"` }
type CorporationStructure ¶
type CorporationStructure struct { Structure ProfileID int64 `json:"profile_id"` Services []string `json:"services"` FuelExpires time.Time `json:"fuel_expires"` StateStart time.Time `json:"state_start"` StateEnd time.Time `json:"state_end"` UnanchorsAt time.Time `json:"unanchors_at"` State string `json:"state"` CurrReinforceWindow ReinforceWindow `json:"curr_reinforce_window"` NextReinforceWindow ReinforceWindow `json:"next_reinforce_window"` }
A CorporationStructure contains additional, sensitive information about a citadel.
type IndustryJob ¶
type IndustryJob struct { JobID int `json:"job_id"` InstallerID int `json:"installer_id"` FacilityID int `json:"facility_id"` LocationID int `json:"location_id"` ActivityID int `json:"activity_id"` BlueprintID int `json:"blueprint_id"` BlueprintTypeID int `json:"blueprint_type_id"` BlueprintLocationID int `json:"blueprint_location_id"` OutputLocationID int `json:"output_location_id"` ProductTypeID int `json:"product_type_id"` Runs int `json:"runs"` Cost decimal.Decimal `json:"cost"` LicensedRuns int `json:"licensed_runs"` Probability decimal.Decimal `json:"probability"` Status string `json:"status"` StartDate time.Time `json:"start_date"` EndDate time.Time `json:"end_date"` PauseDate time.Time `json:"pause_date"` CompletedDate time.Time `json:"completed_date"` CompletedCharacterID int `json:"completed_character_id"` SuccessfulRuns int `json:"successful_runs"` }
type IndustryManager ¶
type IndustryManager struct {
// contains filtered or unexported fields
}
func (*IndustryManager) GetCorporationIndustryJobs ¶
func (m *IndustryManager) GetCorporationIndustryJobs(ctx context.Context, corpID int) (jobs []*IndustryJob, err error)
type InventoryItem ¶
type InventoryManager ¶
type InventoryManager struct {
// contains filtered or unexported fields
}
func (*InventoryManager) GetCorporationInventory ¶
func (m *InventoryManager) GetCorporationInventory(ctx context.Context, corpID int) (items []*InventoryItem, err error)
func (*InventoryManager) NewInventoryItem ¶
func (m *InventoryManager) NewInventoryItem(ctx context.Context, corpID, typeID, locationID int) (*InventoryItem, error)
func (*InventoryManager) SaveInventoryItem ¶
func (m *InventoryManager) SaveInventoryItem(ctx context.Context, item *InventoryItem) error
type Location ¶
type Location struct { // The original LocationID this location represents. LocationID int `json:"location_id"` // The solar system this location is found in. System *evedb.System `json:"system"` // The constellation this location is found in. Constellation *evedb.Constellation `json:"constellation"` // The region this location is found in. Region *evedb.Region `json:"region"` // The NPC station at this location. May be nil. Station *evedb.Station `json:"station"` // The player-owned structure at this location. May be nil. Structure *Structure `json:"structure"` // contains filtered or unexported fields }
Location describes a station, structure, or solar system in the EVE universe.
This is a basic abstraction over the loosely defined "location ID" found in various API responses. A Location may represent an NPC station, a player-owned Citadel, or simply a solar system.
Any Location will contain, at a minimum, System, Constellation, and Region info. Station and Structure may be nil if the location is only as specific as a solar system. Otherwise, Station OR Structure will be populated, but never both.
func (Location) IsCitadel ¶
IsCitadel returns true if the location is a player-controlled citadel.
Use this method to determine if a location represents a player-controlled structure.
func (Location) IsStation ¶
IsStation returns true if the location is a NPC station.
Use this method to determine if a location represents a NPC station.
func (Location) IsSystem ¶
IsSystem returns true if the location does not contain station or citadel information.
Use this method to determine if a location is neither a station nor structure. In other words, this method returns true if the location is strictly just a solar system.
type LocationManager ¶
type LocationManager struct {
// contains filtered or unexported fields
}
func (*LocationManager) GetLocation ¶
GetLocation attempts to resolve the given location.
func (*LocationManager) QueryLocations ¶
type MailManager ¶
type MailManager struct {
// contains filtered or unexported fields
}
func (*MailManager) AddToMailingList ¶
func (m *MailManager) AddToMailingList(key string, rec MailingListSubscriber) error
func (*MailManager) GetMailingList ¶
func (m *MailManager) GetMailingList(key string) ([]*MailingListSubscriber, error)
type MailingListSubscriber ¶
type Manager ¶
type Manager struct { *AssetManager *BlueprintManager *CharacterManager *CorpManager *IndustryManager *InventoryManager *LocationManager *MailManager *MarketManager *ProductManager *StructureManager *UserManager // contains filtered or unexported fields }
A Manager handles loading and saving of data.
Most data is stored in the configured database and only fetched from external sites when necessary.
func NewManager ¶
func NewManager(pool *db.ConnPool, evedb *evedb.EveDB, api *eveapi.EveAPI, ec *evemarketer.EveMarketer) *Manager
NewManager creates a new Manager, ready for use.
type MarketManager ¶
type MarketManager struct {
// contains filtered or unexported fields
}
func (*MarketManager) GetCorporationOrder ¶
func (m *MarketManager) GetCorporationOrder(ctx context.Context, corpID, orderID int) (*MarketOrder, error)
func (*MarketManager) GetCorporationOrders ¶
func (m *MarketManager) GetCorporationOrders(ctx context.Context, corpID int) (orders []*MarketOrder, err error)
func (*MarketManager) GetMarketPrice ¶
func (m *MarketManager) GetMarketPrice(typeID int) (*MarketPrice, error)
func (*MarketManager) GetMarketPrices ¶
func (m *MarketManager) GetMarketPrices(typeID int, typeIDs ...int) ([]*MarketPrice, error)
func (*MarketManager) GetMarketStat ¶
func (m *MarketManager) GetMarketStat(typeID int, typeIDs ...int) ([]*MarketStat, error)
GetMarketStat gets market information for the given types.
Multiple typeIDs may be specified, but the method signature requires at least the first is given.
func (*MarketManager) GetMarketStatRegion ¶
func (m *MarketManager) GetMarketStatRegion(regionID int, typeID int, typeIDs ...int) ([]*MarketStat, error)
GetMarketStatRegion gets market information for the given region and types.
Multiple typeIDs may be specified, but the method signature requires at least the first is given.
func (*MarketManager) GetMarketStatSystem ¶
func (m *MarketManager) GetMarketStatSystem(systemID int, typeID int, typeIDs ...int) ([]*MarketStat, error)
GetMarketStatSystem gets market information for the given system and types.
Multiple typeIDs may be specified, but the method signature requires at least the first is given.
type MarketOrder ¶
type MarketOrder struct { OrderID int `json:"order_id"` CharID int `json:"char_id"` LocationID int `json:"location_id"` TypeID int `json:"type_id"` VolEntered int `json:"vol_entered"` VolRemaining int `json:"vol_remaining"` MinVolume int `json:"min_volume"` OrderState OrderState `json:"order_state"` Range string `json:"range"` AccountKey int `json:"account_key"` Duration int `json:"duration"` Escrow decimal.Decimal `json:"escrow"` Price decimal.Decimal `json:"price"` Bid bool `json:"bid"` Issued time.Time `json:"issued"` }
type MarketPrice ¶
type MarketPrice struct { TypeID int `json:"type_id"` Avg decimal.Decimal `json:"avg"` Base decimal.Decimal `json:"base"` }
A MarketPrice is a universal average price for a given item.
type MarketStat ¶
type MarketStat struct { Kind evemarketer.StatKind `json:"kind"` TypeID int `json:"type_id"` Volume int `json:"volume"` WAvg decimal.Decimal `json:"w_avg"` Avg decimal.Decimal `json:"avg"` Variance decimal.Decimal `json:"variance"` StdDev decimal.Decimal `json:"std_dev"` Median decimal.Decimal `json:"median"` FivePercent decimal.Decimal `json:"five_percent"` Max decimal.Decimal `json:"max"` Min decimal.Decimal `json:"min"` Timestamp time.Time `json:"timestamp"` }
MarketStat is region-specific price information for the given type.
func (MarketStat) View ¶
func (m MarketStat) View() StatView
type OrderState ¶
type OrderState string
One of: open, expired, cancelled
func (*OrderState) Scan ¶
func (r *OrderState) Scan(src interface{}) error
type Product ¶
type Product struct { ProductID int `json:"product_id"` TypeID int `json:"type_id"` Materials []*Product `json:"materials"` Quantity int `json:"quantity"` MarketPrice decimal.Decimal `json:"market_price"` MarketRegionID int `json:"market_region_id"` MaterialEfficiency decimal.Decimal `json:"material_efficiency"` BatchSize int `json:"batch_size"` Kind ProductKind `json:"kind"` ParentID int `json:"parent_id"` CorporationID int `json:"corporation_id"` }
Product represents one part of a production chain.
type ProductKind ¶
type ProductKind string
ProductKind describes the way a product is acquired.
const ( ProductBuy ProductKind = "buy" ProductBuild ProductKind = "build" )
type ProductManager ¶
type ProductManager struct {
// contains filtered or unexported fields
}
func (*ProductManager) GetAllProducts ¶
func (m *ProductManager) GetAllProducts(corpID int) ([]*Product, error)
GetAllProducts returns all production chains associated with the given corporation.
func (*ProductManager) GetProduct ¶
func (m *ProductManager) GetProduct(corpID int, productID int) (*Product, error)
GetProduct returns a production chain for the given corporation and root product.
func (*ProductManager) NewProduct ¶
func (m *ProductManager) NewProduct(corpID int, typeID int) (*Product, error)
NewProduct creates a new production chain for the given corporation and type.
func (*ProductManager) SaveProduct ¶
func (m *ProductManager) SaveProduct(product *Product) error
SaveProduct saves the given production chain in the database.
This function automatically handles both inserting and updating.
func (*ProductManager) UpdateProductMarketPrices ¶
func (m *ProductManager) UpdateProductMarketPrices(ctx context.Context, product *Product, regionID int) error
UpdateProductMarketPrices fetches the latest market data for the production chain in the specified region.
This method updates the Product's regionID. To avoid this behavior, pass the current regionID in.
err := m.UpdateProductMarketPrices(prod, prod.RegionID)
func (*ProductManager) UpdateProductMarketPricesRecursive ¶
func (m *ProductManager) UpdateProductMarketPricesRecursive(product *Product, regionID int) error
type ReinforceHour ¶
type ReinforceHour int
func (ReinforceHour) String ¶
func (h ReinforceHour) String() string
type ReinforceWindow ¶
type ReinforceWindow struct { Weekday time.Weekday `json:"weekday"` Hour ReinforceHour `json:"hour"` EffectiveAt time.Time `json:"effective_at"` }
func (*ReinforceWindow) Scan ¶
func (h *ReinforceWindow) Scan(src interface{}) error
func (ReinforceWindow) String ¶
func (h ReinforceWindow) String() string
type StatView ¶
type StatView struct { Kind string `json:"kind"` TypeID int `json:"type_id"` Volume int `json:"volume"` WAvg float64 `json:"w_avg"` Avg float64 `json:"avg"` Variance float64 `json:"variance"` StdDev float64 `json:"std_dev"` Median float64 `json:"median"` FivePercent float64 `json:"five_percent"` Max float64 `json:"max"` Min float64 `json:"min"` Timestamp time.Time `json:"timestamp"` // contains filtered or unexported fields }
type Structure ¶
type Structure struct { StructureID int64 `json:"structure_id"` Name string `json:"name"` SystemID int64 `json:"system_id"` TypeID int64 `json:"type_id"` }
A Structure is a player-owned citadel.
type StructureManager ¶
type StructureManager struct {
// contains filtered or unexported fields
}
func (*StructureManager) GetCorporationStructures ¶
func (m *StructureManager) GetCorporationStructures(ctx context.Context, corpID int) ([]*CorporationStructure, error)
func (*StructureManager) GetStructure ¶
type UserManager ¶
type UserManager struct {
// contains filtered or unexported fields
}
func (*UserManager) AuthenticateUser ¶
func (m *UserManager) AuthenticateUser(name, password string) (*User, string, error)
func (*UserManager) CreateUserVerificationHash ¶
func (m *UserManager) CreateUserVerificationHash(user *User) ([]byte, error)
func (*UserManager) GetAuthorization ¶
func (m *UserManager) GetAuthorization(user *User, role Role) (*Authorization, error)
func (*UserManager) GetUserBySessionKey ¶
func (m *UserManager) GetUserBySessionKey(key string) (*User, error)
func (*UserManager) NewUser ¶
func (m *UserManager) NewUser(name, email, password string) (*User, error)
func (*UserManager) RemoveAuthorization ¶
func (m *UserManager) RemoveAuthorization(user *User, role Role) error
func (*UserManager) SaveAuthorization ¶
func (*UserManager) VerifyUserEmail ¶
func (m *UserManager) VerifyUserEmail(email string, hash []byte) (bool, error)