Documentation
¶
Overview ¶
EVE Online API downloader/cacher.
Begin by initializing the default client.
NewClient(NilCache)
Create a new request for the API page needed.
req := NewRequest("eve/ConquerableStationList.xml.aspx")
Set any options you may need, including keyid/vcode.
req.Set("keyid", "1234")
req.Set("vcode", "abcd")
req.Set("charactername", "innominate")
req.Set("characterid", fmt.Sprintf("%d", 123))
Get your response.
resp, err := req.Do() xml := resp.Data
Index ¶
- Variables
- func MakeID() string
- func SQLCacher(db *sql.DB) (*sqlCache, error)
- func SetMaxIdleConns(maxIdleConns int)
- func SetTimeout(timeout time.Duration)
- func SynthesizeAPIError(code int, text string, expiresIn time.Duration) []byte
- type APIError
- type CacheEntry
- type Cacher
- type Client
- type DiskCache
- type Request
- type Response
Constants ¶
This section is empty.
Variables ¶
var ( ErrCannotConnect = fmt.Errorf("Error connecting to API.") ErrNetwork = fmt.Errorf("Network error.") ErrHTTP = fmt.Errorf("HTTP error.") ErrForbidden = fmt.Errorf("HTTP Forbidden, invalid API provided.") ErrUnknown = fmt.Errorf("Unknown Error.") ErrXML = fmt.Errorf("Malformed XML Detected") ErrTime = fmt.Errorf("Malformed cache directive.") )
var DefaultBaseURL = "https://api.eveonline.com/"
Default BaseURL for new clients, change as necessary. Must contain trailing slash or bad things happen.
var DefaultUserAgent = "go apicache by Innominate(github.com/inominate/apicache)"
var NilCache = new(nilCache)
Fake Cacher, does nothing but can serve as a stand-in for testing.
Functions ¶
func SQLCacher ¶
SQL Database Cacher Must be passed an existing database handle, returns a cacher which can be used with NewClient(). Will create its own table if necessary.
func SetMaxIdleConns ¶
func SetMaxIdleConns(maxIdleConns int)
Set max idle conns for the default client
Types ¶
type APIError ¶
API Error Type, hopefully contains the error code and some useful information. This is CCP so nothing is guaranteed.
type CacheEntry ¶
type Cacher ¶
type Cacher interface {
Store(cacheTag string, httpCode int, data []byte, expires time.Time) error
Get(cacheTag string) (int, []byte, time.Time, error)
}
Cachers MUST be safe for concurrent use.
type Client ¶
type Client struct {
// Base URL, defaults to CCPs api but can be changed to a proxy
BaseURL string
//Alternate user agent to use.
UserAgent string
// Default three retries, can be changed at will.
Retries int
sync.RWMutex
// contains filtered or unexported fields
}
API Client structure. Must be created using NewClient() function.
func NewClient ¶
Create a new API Client. The first time this is called will become the default client. Requires a cacher.
func (*Client) Do ¶
Perform a request, usually called by the request itself. User friendly error is enclosed in the response, returned error should be for internal use only.
func (*Client) SetMaxIdleConns ¶
func (*Client) SetTimeout ¶
Set timeout for each API request.
type DiskCache ¶
func NewDiskCache ¶
type Request ¶
type Request struct {
// Override the CCP requested expiration time, will not reduce existing cache
// duration, see Force below. Zero value indicates this field should be
// ignored
// Intended use is to force longer cache timers to align dependent calls.
// e.g. Pull starbase and locations APIs in sync with assets.
Expires time.Time
// Force pull despite cache, use at own risk.
Force bool
// Do not cache this request, use at own risk.
NoCache bool
// contains filtered or unexported fields
}
API Request structure for making requests.
func (*Request) Do ¶
Perform a request. User friendly error is enclosed in the response, returned error should be for internal use only.
type Response ¶
type Response struct {
// Raw XML data
Data []byte
// Signals if we used the cache or not
FromCache bool
// Data expiration time
Expires time.Time
// true if an error occured due to invalid API rather than server problems
Invalidate bool
// Contains API Error if one occured
Error APIError
//Pass on CCP's HTTP code because why not?
HTTPCode int
}
Data structure returned from the API.