本文整理匯總了Golang中github.com/go-swagger/go-swagger/httpkit/client.New函數的典型用法代碼示例。如果您正苦於以下問題:Golang New函數的具體用法?Golang New怎麽用?Golang New使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了New函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: NewHTTPClient
// NewHTTPClient creates a new task tracker HTTP client.
func NewHTTPClient(formats strfmt.Registry) *TaskTracker {
if formats == nil {
formats = strfmt.Default
}
transport := httptransport.New("localhost:8322", "/", []string{"https", "http"})
return New(transport, formats)
}
示例2: NewHTTPClient
// NewHTTPClient creates a new bill forward HTTP client.
func NewHTTPClient(formats strfmt.Registry) *BillForward {
if formats == nil {
formats = strfmt.Default
}
transport := httptransport.New("localhost:8080", "/", []string{"https"})
return New(transport, formats)
}
示例3: NewHTTPClient
// NewHTTPClient creates a new client HTTP client.
func NewHTTPClient(formats strfmt.Registry) *Client {
if formats == nil {
formats = strfmt.Default
}
transport := httptransport.New("quay.io", "/", []string{"https"})
return New(transport, formats)
}
示例4: NewHTTPClient
// NewHTTPClient creates a new workflow manager HTTP client.
func NewHTTPClient(formats strfmt.Registry) *WorkflowManager {
if formats == nil {
formats = strfmt.Default
}
transport := httptransport.New("localhost", "/", []string{"http"})
return New(transport, formats)
}
示例5: NewHTTPClient
// NewHTTPClient creates a new todo list HTTP client.
func NewHTTPClient(formats strfmt.Registry) *TodoList {
if formats == nil {
formats = strfmt.Default
}
transport := httptransport.New("localhost", "/", []string{"http", "https"})
return New(transport, formats)
}
示例6: CreateImageStore
// CreateImageStore creates an image store
func CreateImageStore(storename string) error {
defer trace.End(trace.Begin(storename))
transport := httptransport.New(options.host, "/", []string{"http"})
client := apiclient.New(transport, nil)
log.Debugf("Creating a store from input %s", storename)
body := &models.ImageStore{Name: storename}
_, err := client.Storage.CreateImageStore(
storage.NewCreateImageStoreParamsWithContext(ctx).WithBody(body),
)
if _, ok := err.(*storage.CreateImageStoreConflict); ok {
log.Debugf("Store already exists")
return nil
}
if err != nil {
log.Debugf("Creating a store failed: %s", err)
return err
}
log.Debugf("Created a store %#v", body)
return nil
}
示例7: NewHTTPClient
// NewHTTPClient creates a new a to do list application HTTP client.
func NewHTTPClient(formats strfmt.Registry) *AToDoListApplication {
if formats == nil {
formats = strfmt.Default
}
transport := httptransport.New("localhost", "/", []string{"http"})
return New(transport, formats)
}
示例8: main
func main() {
transport := httpclient.New("api-sandbox.billforward.net:443", "/v1", []string{"https"})
transport.DefaultAuthentication = httpclient.BearerToken(os.Getenv("BILLFORWARD_API_KEY"))
// Only necessary for the PDF response, but here in case someone needs it
transport.Consumers["application/pdf"] = httpkit.ConsumerFunc(func(r io.Reader, data interface{}) error {
f := data.(*httpkit.File)
b, err := ioutil.ReadAll(r)
if err != nil {
return err
}
f.Data = &ReadWrapper{bytes.NewReader(b)}
return nil
})
bfClient := client.New(transport, nil)
acctsResp, err := bfClient.Accounts.GetAllAccounts(accounts.NewGetAllAccountsParams())
if err != nil {
log.Fatal(err)
}
for i, acct := range acctsResp.Payload.Results {
log.Printf("account %d: %+v\n", i, acct)
log.Printf("profile %d: %+v\n", i, acct.Profile)
}
}
示例9: SetupConfig
func SetupConfig() {
var conf goStashRestClientConfig
ParseJsonFileStripComments("./config.json", &conf)
validateRequiredField("host", &conf.Host)
validateRequiredField("username", &conf.Username)
if &conf.Password == nil || len(conf.Password) == 0 {
fmt.Printf("Enter your password for %s: ", conf.Username)
bytePassword, err := terminal.ReadPassword(0)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
fmt.Println()
conf.Password = string(bytePassword)
}
validateRequiredField("password", &conf.Password)
doc, err := spec.New(apiclient.SwaggerJSON, "")
if err != nil {
panic(err)
}
transport := httptransport.New(doc)
transport.Host = conf.Host
fmt.Println("using host", conf.Host)
// Helpful to debug
// transport.Debug = true
// Assumes basic auth. TODO enable the config.json to take different mechanisms, OR integrate with swagger spec file what it says is supported.
transport.DefaultAuthentication = httptransport.BasicAuth(conf.Username, conf.Password)
apiclient.Default.SetTransport(transport)
}
示例10: ListImages
// ListImages lists the images from given image store
func ListImages(host, storename string, images []*ImageWithMeta) (map[string]*models.Image, error) {
defer trace.End(trace.Begin(storename))
transport := httptransport.New(host, "/", []string{"http"})
client := apiclient.New(transport, nil)
ids := make([]string, len(images))
for i := range images {
ids = append(ids, images[i].ID)
}
imageList, err := client.Storage.ListImages(
storage.NewListImagesParamsWithContext(ctx).WithStoreName(storename).WithIds(ids),
)
if err != nil {
return nil, err
}
existingImages := make(map[string]*models.Image)
for i := range imageList.Payload {
v := imageList.Payload[i]
existingImages[v.ID] = v
}
return existingImages, nil
}
示例11: NewHTTPClient
// NewHTTPClient creates a new simple to do list HTTP client.
func NewHTTPClient(formats strfmt.Registry) *SimpleToDoList {
swaggerSpec, err := spec.New(SwaggerJSON, "")
if err != nil {
// the swagger spec is valid because it was used to generated this code.
panic(err)
}
if formats == nil {
formats = strfmt.Default
}
return New(httptransport.New(swaggerSpec), formats)
}
示例12: GetSwaggerClient
func GetSwaggerClient(apiURL string) (*apiclient.WorkflowManager, error) {
urlDet, err := url.Parse(apiURL)
if err != nil {
return nil, err
}
// create the transport
transport := httptransport.New(urlDet.Host, "", []string{urlDet.Scheme})
apiClient := apiclient.Default
apiClient.SetTransport(transport)
return apiClient, nil
}
示例13: PingPortLayer
// PingPortLayer calls the _ping endpoint of the portlayer
func PingPortLayer(host string) (bool, error) {
defer trace.End(trace.Begin(host))
transport := httptransport.New(host, "/", []string{"http"})
client := apiclient.New(transport, nil)
ok, err := client.Misc.Ping(misc.NewPingParamsWithContext(ctx))
if err != nil {
return false, err
}
return ok.Payload == "OK", nil
}
示例14: Init
func Init(portLayerAddr, product string, config *config.VirtualContainerHostConfigSpec, insecureRegs []url.URL) error {
_, _, err := net.SplitHostPort(portLayerAddr)
if err != nil {
return err
}
vchConfig = config
productName = product
if config != nil {
if config.Version != nil {
productVersion = config.Version.ShortVersion()
}
if productVersion == "" {
portLayerName = product + " Backend Engine"
} else {
portLayerName = product + " " + productVersion + " Backend Engine"
}
} else {
portLayerName = product + " Backend Engine"
}
t := httptransport.New(portLayerAddr, "/", []string{"http"})
portLayerClient = client.New(t, nil)
portLayerServerAddr = portLayerAddr
// block indefinitely while waiting on the portlayer to respond to pings
// the vic-machine installer timeout will intervene if this blocks for too long
pingPortLayer()
if err := hydrateCaches(); err != nil {
return err
}
log.Info("Creating image store")
if err := createImageStore(); err != nil {
log.Errorf("Failed to create image store")
return err
}
serviceOptions := registry.ServiceOptions{}
for _, r := range insecureRegs {
insecureRegistries = append(insecureRegistries, r.Path)
}
if len(insecureRegistries) > 0 {
serviceOptions.InsecureRegistries = insecureRegistries
}
log.Debugf("New registry service with options %#v", serviceOptions)
RegistryService = registry.NewService(serviceOptions)
return nil
}
示例15: createNewAttachClientWithTimeouts
func (c *ContainerProxy) createNewAttachClientWithTimeouts(connectTimeout, responseTimeout, responseHeaderTimeout time.Duration) (*client.PortLayer, *httpclient.Transport) {
runtime := httptransport.New(c.portlayerAddr, "/", []string{"http"})
transport := &httpclient.Transport{
ConnectTimeout: connectTimeout,
ResponseHeaderTimeout: responseHeaderTimeout,
RequestTimeout: responseTimeout,
}
runtime.Transport = transport
plClient := client.New(runtime, nil)
runtime.Consumers["application/octet-stream"] = httpkit.ByteStreamConsumer()
runtime.Producers["application/octet-stream"] = httpkit.ByteStreamProducer()
return plClient, transport
}