Add httpcache to respect the caching headers in the ESI responses
This commit is contained in:
parent
03a5644474
commit
66cac0a23e
2 changed files with 28 additions and 4 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -16,6 +16,7 @@ vendor/
|
||||||
*.log
|
*.log
|
||||||
cache.db
|
cache.db
|
||||||
configuration.toml
|
configuration.toml
|
||||||
|
cache.ldb
|
||||||
|
|
||||||
swagger_linux_amd64
|
swagger_linux_amd64
|
||||||
eve-goclient
|
eve-goclient
|
||||||
|
|
31
main.go
31
main.go
|
@ -1,6 +1,7 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"crypto/tls"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"sort"
|
"sort"
|
||||||
"time"
|
"time"
|
||||||
|
@ -20,6 +21,8 @@ import (
|
||||||
|
|
||||||
"github.com/BurntSushi/toml"
|
"github.com/BurntSushi/toml"
|
||||||
"github.com/go-openapi/strfmt"
|
"github.com/go-openapi/strfmt"
|
||||||
|
"github.com/gregjones/httpcache"
|
||||||
|
"github.com/gregjones/httpcache/leveldbcache"
|
||||||
"github.com/leekchan/accounting"
|
"github.com/leekchan/accounting"
|
||||||
"github.com/logrusorgru/aurora"
|
"github.com/logrusorgru/aurora"
|
||||||
|
|
||||||
|
@ -74,8 +77,9 @@ var (
|
||||||
|
|
||||||
defaultDateFormat = "_2 Jan 2006, 15:04"
|
defaultDateFormat = "_2 Jan 2006, 15:04"
|
||||||
|
|
||||||
cfgFilePath = flag.String("config", "configuration.toml", "Path to the configuration file.")
|
cfgFilePath = flag.String("config", "configuration.toml", "Path to the configuration file.")
|
||||||
cacheDBPath = flag.String("cache", "cache.db", "Path to the cache sqlite database.")
|
cacheDBPath = flag.String("cache", "cache.db", "Path to the cache sqlite database.")
|
||||||
|
insecureFlag = flag.Bool("insecure", false, "Do not check the HTTPS certificate")
|
||||||
)
|
)
|
||||||
|
|
||||||
var ctx = context.Background()
|
var ctx = context.Background()
|
||||||
|
@ -105,12 +109,31 @@ func main() {
|
||||||
cToken = getNewAuthorizationToken()
|
cToken = getNewAuthorizationToken()
|
||||||
}
|
}
|
||||||
|
|
||||||
client := googleOauthConfig.Client(oauth2.NoContext, cToken)
|
ldb, ldbErr := leveldbcache.New("cache.ldb")
|
||||||
|
if ldbErr != nil {
|
||||||
|
fmt.Println("Unable to initialize the LevelDB cache.")
|
||||||
|
log.Fatal(ldbErr)
|
||||||
|
}
|
||||||
|
cachingTransport := httpcache.NewTransport(ldb)
|
||||||
|
|
||||||
|
if *insecureFlag {
|
||||||
|
proxiedTransport := &http.Transport{
|
||||||
|
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
|
||||||
|
Proxy: http.ProxyFromEnvironment,
|
||||||
|
}
|
||||||
|
cachingTransport.Transport = proxiedTransport
|
||||||
|
}
|
||||||
|
|
||||||
|
cachingClient := &http.Client{Transport: cachingTransport}
|
||||||
|
|
||||||
|
ctx := context.WithValue(context.TODO(), oauth2.HTTPClient, cachingClient)
|
||||||
|
client := googleOauthConfig.Client(ctx, cToken)
|
||||||
|
|
||||||
m, err := getCharacterInfo(client)
|
m, err := getCharacterInfo(client)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
log.Println(err)
|
||||||
cToken = getNewAuthorizationToken()
|
cToken = getNewAuthorizationToken()
|
||||||
client = googleOauthConfig.Client(oauth2.NoContext, cToken)
|
client = googleOauthConfig.Client(ctx, cToken)
|
||||||
m, err = getCharacterInfo(client)
|
m, err = getCharacterInfo(client)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
|
|
Reference in a new issue