本文整理汇总了Golang中github.com/cloudfoundry-incubator/cf_http.NewClient函数的典型用法代码示例。如果您正苦于以下问题:Golang NewClient函数的具体用法?Golang NewClient怎么用?Golang NewClient使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewClient函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Run
func (p *Processor) Run(signals <-chan os.Signal, ready chan<- struct{}) error {
close(ready)
httpClient := cf_http.NewClient()
httpClient.Transport = &http.Transport{
Proxy: http.ProxyFromEnvironment,
Dial: (&net.Dialer{
Timeout: 10 * time.Second,
KeepAlive: 30 * time.Second,
}).Dial,
TLSHandshakeTimeout: 10 * time.Second,
TLSClientConfig: &tls.Config{
InsecureSkipVerify: p.skipCertVerify,
MinVersion: tls.VersionTLS10,
},
}
timer := p.clock.NewTimer(p.pollingInterval)
stop := p.sync(signals, httpClient)
for {
if stop {
return nil
}
select {
case <-signals:
return nil
case <-timer.C():
stop = p.sync(signals, httpClient)
timer.Reset(p.pollingInterval)
}
}
}
示例2: initializeServer
func initializeServer(logger lager.Logger) ifrit.Runner {
if *staticDirectory == "" {
logger.Fatal("static-directory-missing", nil)
}
transport := &http.Transport{
Proxy: http.ProxyFromEnvironment,
Dial: (&net.Dialer{
Timeout: ccUploadDialTimeout,
KeepAlive: ccUploadKeepAlive,
}).Dial,
TLSClientConfig: &tls.Config{
InsecureSkipVerify: *skipCertVerify,
},
TLSHandshakeTimeout: ccUploadTLSHandshakeTimeout,
}
pollerHttpClient := cf_http.NewClient()
pollerHttpClient.Transport = transport
fileServerHandler, err := handlers.New(*staticDirectory, logger)
if err != nil {
logger.Error("router-building-failed", err)
os.Exit(1)
}
return http_server.New(*serverAddress, fileServerHandler)
}
示例3: NewUaaKeyFetcher
func NewUaaKeyFetcher(logger lager.Logger, uaaGetKeyEndpoint string) UaaKeyFetcher {
return &uaaKeyFetcher{
uaaGetKeyEndpoint: uaaGetKeyEndpoint,
httpClient: cf_http.NewClient(),
logger: logger,
}
}
示例4: NewETCDMetrics
func NewETCDMetrics(logger lager.Logger, etcdOptions *ETCDOptions) (*ETCDMetrics, error) {
var tlsConfig *tls.Config
if etcdOptions.CertFile != "" && etcdOptions.KeyFile != "" {
var err error
tlsConfig, err = cf_http.NewTLSConfig(etcdOptions.CertFile, etcdOptions.KeyFile, etcdOptions.CAFile)
if err != nil {
return nil, err
}
tlsConfig.ClientSessionCache = tls.NewLRUClientSessionCache(etcdOptions.ClientSessionCacheSize)
}
client := cf_http.NewClient()
client.CheckRedirect = func(*http.Request, []*http.Request) error {
return errRedirected
}
if tr, ok := client.Transport.(*http.Transport); ok {
tr.TLSClientConfig = tlsConfig
} else {
return nil, errors.New("Invalid transport")
}
return &ETCDMetrics{
logger: logger,
etcdCluster: etcdOptions.ClusterUrls,
client: client,
}, nil
}
示例5: initializeServer
func initializeServer(logger lager.Logger) ifrit.Runner {
transport := &http.Transport{
Proxy: http.ProxyFromEnvironment,
Dial: (&net.Dialer{
Timeout: ccUploadDialTimeout,
KeepAlive: ccUploadKeepAlive,
}).Dial,
TLSClientConfig: &tls.Config{
InsecureSkipVerify: *skipCertVerify,
},
TLSHandshakeTimeout: ccUploadTLSHandshakeTimeout,
}
pollerHttpClient := cf_http.NewClient()
pollerHttpClient.Transport = transport
uploader := ccclient.NewUploader(logger, &http.Client{Transport: transport})
poller := ccclient.NewPoller(logger, pollerHttpClient, *ccJobPollingInterval)
ccUploaderHandler, err := handlers.New(uploader, poller, logger)
if err != nil {
logger.Error("router-building-failed", err)
os.Exit(1)
}
return http_server.New(*serverAddress, ccUploaderHandler)
}
示例6: NewClient
func NewClient(url string) Client {
return &client{
httpClient: cf_http.NewClient(),
streamingHTTPClient: cf_http.NewStreamingClient(),
reqGen: rata.NewRequestGenerator(url, Routes),
}
}
示例7: newTaskWorker
func newTaskWorker(taskQueue <-chan models.Task, receptorBBS bbs.ReceptorBBS, logger lager.Logger) *taskWorker {
return &taskWorker{
taskQueue: taskQueue,
receptorBBS: receptorBBS,
logger: logger,
httpClient: cf_http.NewClient(),
}
}
示例8: newTaskWorker
func newTaskWorker(taskQueue <-chan *models.Task, taskdb bbs.Client, logger lager.Logger) *taskWorker {
return &taskWorker{
taskQueue: taskQueue,
taskdb: taskdb,
logger: logger,
httpClient: cf_http.NewClient(),
}
}
示例9: New
func New(logger lager.Logger, maxWorkers int, cbHandler CompletedTaskHandler) *TaskCompletionWorkPool {
if cbHandler == nil {
panic("callbackHandler cannot be nil")
}
return &TaskCompletionWorkPool{
logger: logger,
maxWorkers: maxWorkers,
callbackHandler: cbHandler,
httpClient: cf_http.NewClient(),
}
}
示例10: initializeEtcdDB
func initializeEtcdDB(
logger lager.Logger,
cryptor encryption.Cryptor,
storeClient etcddb.StoreClient,
cbClient taskworkpool.TaskCompletionClient,
serviceClient bbs.ServiceClient,
) *etcddb.ETCDDB {
return etcddb.NewETCD(
format.ENCRYPTED_PROTO,
*convergenceWorkers,
*updateWorkers,
cryptor,
storeClient,
initializeAuctioneerClient(logger),
serviceClient,
clock.NewClock(),
rep.NewClientFactory(cf_http.NewClient(), cf_http.NewClient()),
cbClient,
)
}
示例11: NewDiegoExecutor
func NewDiegoExecutor() *DiegoExecutor {
ip, _ := localip.LocalIP()
address := fmt.Sprintf("http://%s:%v", ip, 1800)
repClientFactory := rep.NewClientFactory(cf_http.NewClient())
cellClient := repClientFactory.CreateClient(address)
return &DiegoExecutor{
cellClient: cellClient,
taskStateMap: map[string]mesos.TaskState{},
}
}
示例12: initializeAuctionRunner
func initializeAuctionRunner(logger lager.Logger, cellStateTimeout time.Duration, bbsClient bbs.Client, serviceClient bbs.ServiceClient) auctiontypes.AuctionRunner {
httpClient := cf_http.NewClient()
stateClient := cf_http.NewCustomTimeoutClient(cellStateTimeout)
repClientFactory := rep.NewClientFactory(httpClient, stateClient)
delegate := auctionrunnerdelegate.New(repClientFactory, bbsClient, serviceClient, logger)
metricEmitter := auctionmetricemitterdelegate.New()
workPool, err := workpool.NewWorkPool(*auctionRunnerWorkers)
if err != nil {
logger.Fatal("failed-to-construct-auction-runner-workpool", err, lager.Data{"num-workers": *auctionRunnerWorkers}) // should never happen
}
return auctionrunner.New(
delegate,
metricEmitter,
clock.NewClock(),
workPool,
logger,
)
}
示例13:
fakeServer.Close()
})
Describe("HandleCompletedTask", func() {
var (
callbackURL string
taskDB *dbfakes.FakeTaskDB
statusCodes chan int
reqCount chan struct{}
task *models.Task
httpClient *http.Client
)
BeforeEach(func() {
httpClient = cf_http.NewClient()
statusCodes = make(chan int)
reqCount = make(chan struct{})
fakeServer.RouteToHandler("POST", "/the-callback/url", func(w http.ResponseWriter, req *http.Request) {
w.WriteHeader(<-statusCodes)
})
callbackURL = fakeServer.URL() + "/the-callback/url"
taskDB = new(dbfakes.FakeTaskDB)
taskDB.ResolvingTaskReturns(nil)
taskDB.DeleteTaskReturns(nil)
})
simulateTaskCompleting := func(signals <-chan os.Signal, ready chan<- struct{}) error {
close(ready)
示例14:
)
var _ = Describe("CfHttp", func() {
var timeout time.Duration
BeforeEach(func() {
timeout = 1 * time.Second
})
JustBeforeEach(func() {
cf_http.Initialize(timeout)
})
Describe("NewClient", func() {
It("returns an http client", func() {
client := cf_http.NewClient()
Expect(client.Timeout).To(Equal(timeout))
transport := client.Transport.(*http.Transport)
Expect(transport.Dial).NotTo(BeNil())
Expect(transport.DisableKeepAlives).To(BeFalse())
})
})
Describe("NewCustomTimeoutClient", func() {
It("returns an http client with specified timeout", func() {
client := cf_http.NewCustomTimeoutClient(5 * time.Second)
Expect(client.Timeout).To(Equal(5 * time.Second))
transport := client.Transport.(*http.Transport)
Expect(transport.Dial).NotTo(BeNil())
Expect(transport.DisableKeepAlives).To(BeFalse())
})
示例15:
"github.com/cloudfoundry-incubator/bbs/models"
"github.com/cloudfoundry-incubator/cf_http"
"github.com/cloudfoundry-incubator/rep"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/onsi/gomega/ghttp"
)
var _ = Describe("Client", func() {
var fakeServer *ghttp.Server
var client rep.Client
BeforeEach(func() {
fakeServer = ghttp.NewServer()
client = rep.NewClient(cf_http.NewClient(), fakeServer.URL())
})
AfterEach(func() {
fakeServer.Close()
})
Describe("StopLRPInstance", func() {
const cellAddr = "cell.example.com"
var stopErr error
var actualLRP = models.ActualLRP{
ActualLRPKey: models.NewActualLRPKey("some-process-guid", 2, "test-domain"),
ActualLRPInstanceKey: models.NewActualLRPInstanceKey("some-instance-guid", "some-cell-id"),
}
JustBeforeEach(func() {