Skip to content

Commit

Permalink
Using jaeger and adding timeout to request
Browse files Browse the repository at this point in the history
  • Loading branch information
Andre Hahn committed Jun 14, 2018
1 parent 41f83fc commit dc086e7
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
4 changes: 3 additions & 1 deletion Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 9 additions & 3 deletions lib/lib.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ import (
"net/http"
"strings"
"sync"
"time"

"github.com/spf13/viper"
ehttp "github.com/topfreegames/extensions/http"
)

// Khan is a struct that represents a khan API application
Expand All @@ -28,17 +30,21 @@ var (
once sync.Once
)

func getHTTPClient() *http.Client {
func getHTTPClient(timeoutMs int) *http.Client {
once.Do(func() {
client = &http.Client{}
client = &http.Client{
Timeout: time.Duration(timeoutMs) * time.Millisecond,
}
ehttp.Instrument(client)
})
return client
}

// NewKhan returns a new khan API application
func NewKhan(config *viper.Viper) KhanInterface {
config.SetDefault("khan.timeout", 1000)
k := &Khan{
httpClient: getHTTPClient(),
httpClient: getHTTPClient(config.GetInt("khan.timeout")),
Config: config,
url: config.GetString("khan.url"),
user: config.GetString("khan.user"),
Expand Down

0 comments on commit dc086e7

Please sign in to comment.