本文整理汇总了Golang中cf/net.ApiResponse类的典型用法代码示例。如果您正苦于以下问题:Golang ApiResponse类的具体用法?Golang ApiResponse怎么用?Golang ApiResponse使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ApiResponse类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: domain
func (cmd *Push) domain(c *cli.Context, domainName string) (domain cf.Domain) {
var apiResponse net.ApiResponse
if domainName != "" {
domain, apiResponse = cmd.domainRepo.FindByNameInCurrentSpace(domainName)
if apiResponse.IsNotSuccessful() {
cmd.ui.Failed(apiResponse.Message)
}
} else {
stopChan := make(chan bool, 1)
domainsChan, statusChan := cmd.domainRepo.ListDomainsForOrg(cmd.config.OrganizationFields.Guid, stopChan)
for domainsChunk := range domainsChan {
for _, d := range domainsChunk {
if d.Shared {
domain = d
stopChan <- true
break
}
}
}
apiResponse, ok := <-statusChan
if (domain.Guid == "") && ok && apiResponse.IsNotSuccessful() {
cmd.ui.Failed(apiResponse.Message)
} else if domain.Guid == "" {
cmd.ui.Failed("No default domain exists")
}
}
return
}
示例2: CreateRoute
func (cmd *CreateRoute) CreateRoute(hostName string, domain cf.Domain, space cf.Space) (route cf.Route, apiResponse net.ApiResponse) {
routeToCreate := cf.Route{Host: hostName, Domain: domain}
cmd.ui.Say("Creating route %s for org %s / space %s as %s...",
terminal.EntityNameColor(routeToCreate.URL()),
terminal.EntityNameColor(cmd.config.Organization.Name),
terminal.EntityNameColor(space.Name),
terminal.EntityNameColor(cmd.config.Username()),
)
route, apiResponse = cmd.routeRepo.CreateInSpace(routeToCreate, domain, space)
if apiResponse.IsNotSuccessful() {
var findApiResponse net.ApiResponse
route, findApiResponse = cmd.routeRepo.FindByHostAndDomain(hostName, domain.Name)
if findApiResponse.IsNotSuccessful() ||
route.Space.Guid != space.Guid ||
route.Domain.Guid != domain.Guid ||
route.Host != hostName {
return
}
apiResponse = net.NewSuccessfulApiResponse()
cmd.ui.Ok()
cmd.ui.Warn("Route %s already exists", route.URL())
return
}
cmd.ui.Ok()
return
}
示例3: CreateRoute
func (cmd *CreateRoute) CreateRoute(hostName string, domain models.DomainFields, space models.SpaceFields) (route models.Route, apiResponse net.ApiResponse) {
cmd.ui.Say("Creating route %s for org %s / space %s as %s...",
terminal.EntityNameColor(domain.UrlForHost(hostName)),
terminal.EntityNameColor(cmd.config.OrganizationFields().Name),
terminal.EntityNameColor(space.Name),
terminal.EntityNameColor(cmd.config.Username()),
)
route, apiResponse = cmd.routeRepo.CreateInSpace(hostName, domain.Guid, space.Guid)
if apiResponse.IsNotSuccessful() {
var findApiResponse net.ApiResponse
route, findApiResponse = cmd.routeRepo.FindByHostAndDomain(hostName, domain.Name)
if findApiResponse.IsNotSuccessful() ||
route.Space.Guid != space.Guid ||
route.Domain.Guid != domain.Guid {
return
}
apiResponse = net.NewSuccessfulApiResponse()
cmd.ui.Ok()
cmd.ui.Warn("Route %s already exists", route.URL())
return
}
cmd.ui.Ok()
return
}
示例4: Run
func (cmd Push) Run(c *cli.Context) {
var (
apiResponse net.ApiResponse
)
if len(c.Args()) != 1 {
cmd.ui.FailWithUsage(c, "push")
return
}
app, didCreate := cmd.getApp(c)
domain := cmd.domain(c)
hostName := cmd.hostName(app, c)
cmd.bindAppToRoute(app, domain, hostName, didCreate, c)
cmd.ui.Say("Uploading %s...", terminal.EntityNameColor(app.Name))
dir := cmd.path(c)
apiResponse = cmd.appBitsRepo.UploadApp(app, dir)
if apiResponse.IsNotSuccessful() {
cmd.ui.Failed(apiResponse.Message)
return
}
cmd.ui.Ok()
cmd.ui.Say("")
cmd.restart(app, c)
}
示例5: Run
func (cmd MarketplaceServices) Run(c *cli.Context) {
var (
serviceOfferings models.ServiceOfferings
apiResponse net.ApiResponse
)
if cmd.config.HasSpace() {
cmd.ui.Say("Getting services from marketplace in org %s / space %s as %s...",
terminal.EntityNameColor(cmd.config.OrganizationFields().Name),
terminal.EntityNameColor(cmd.config.SpaceFields().Name),
terminal.EntityNameColor(cmd.config.Username()),
)
serviceOfferings, apiResponse = cmd.serviceRepo.GetServiceOfferingsForSpace(cmd.config.SpaceFields().Guid)
} else if !cmd.config.IsLoggedIn() {
cmd.ui.Say("Getting all services from marketplace...")
serviceOfferings, apiResponse = cmd.serviceRepo.GetAllServiceOfferings()
} else {
cmd.ui.Failed("Cannot list marketplace services without a targetted space")
}
if apiResponse.IsNotSuccessful() {
cmd.ui.Failed(apiResponse.Message)
return
}
cmd.ui.Ok()
cmd.ui.Say("")
if len(serviceOfferings) == 0 {
cmd.ui.Say("No service offerings found")
return
}
table := [][]string{
[]string{"service", "plans", "description"},
}
sort.Sort(serviceOfferings)
for _, offering := range serviceOfferings {
planNames := ""
for _, plan := range offering.Plans {
if plan.Name == "" {
continue
}
planNames = planNames + ", " + plan.Name
}
planNames = strings.TrimPrefix(planNames, ", ")
table = append(table, []string{
offering.Label,
planNames,
offering.Description,
})
}
cmd.ui.DisplayTable(table)
return
}
示例6: updateApp
func (cmd *Push) updateApp(app models.Application, appParams models.AppParams) (updatedApp models.Application) {
cmd.ui.Say("Updating app %s in org %s / space %s as %s...",
terminal.EntityNameColor(app.Name),
terminal.EntityNameColor(cmd.config.OrganizationFields().Name),
terminal.EntityNameColor(cmd.config.SpaceFields().Name),
terminal.EntityNameColor(cmd.config.Username()),
)
if appParams.EnvironmentVars != nil {
for key, val := range app.EnvironmentVars {
if _, ok := (*appParams.EnvironmentVars)[key]; !ok {
(*appParams.EnvironmentVars)[key] = val
}
}
}
var apiResponse net.ApiResponse
updatedApp, apiResponse = cmd.appRepo.Update(app.Guid, appParams)
if apiResponse.IsNotSuccessful() {
cmd.ui.Failed(apiResponse.Message)
return
}
cmd.ui.Ok()
cmd.ui.Say("")
return
}
示例7: domain
func (cmd *Push) domain(c *cli.Context, domainName string) (domain cf.Domain) {
var apiResponse net.ApiResponse
if domainName != "" {
domain, apiResponse = cmd.domainRepo.FindByNameInCurrentSpace(domainName)
if apiResponse.IsNotSuccessful() {
cmd.ui.Failed(apiResponse.Message)
}
return
}
apiResponse = cmd.domainRepo.ListSharedDomains(api.ListDomainsCallback(func(domains []cf.Domain) bool {
domain = domains[0]
return false
}))
if apiResponse.IsNotSuccessful() {
cmd.ui.Failed(apiResponse.Message)
}
if domain.Guid == "" {
cmd.ui.Failed("No default domain exists")
}
return
}
示例8: Execute
func (req *domainApiRequirement) Execute() bool {
var apiResponse net.ApiResponse
req.domain, apiResponse = req.domainRepo.FindByNameInOrg(req.name, req.config.OrganizationFields().Guid)
if apiResponse.IsNotSuccessful() {
req.ui.Failed(apiResponse.Message)
return false
}
return true
}
示例9: Execute
func (req *serviceInstanceApiRequirement) Execute() (success bool) {
var apiResponse net.ApiResponse
req.serviceInstance, apiResponse = req.serviceRepo.FindInstanceByName(req.name)
if apiResponse.IsNotSuccessful() {
req.ui.Failed(apiResponse.Message)
return false
}
return true
}
示例10: Execute
func (req *applicationApiRequirement) Execute() (success bool) {
var apiResponse net.ApiResponse
req.application, apiResponse = req.appRepo.Read(req.name)
if apiResponse.IsNotSuccessful() {
req.ui.Failed(apiResponse.Message)
return false
}
return true
}
示例11: Execute
func (req *domainApiRequirement) Execute() bool {
var apiResponse net.ApiResponse
req.domain, apiResponse = req.domainRepo.FindByNameInCurrentSpace(req.name)
if apiResponse.IsNotSuccessful() {
req.ui.Failed(apiResponse.Message)
return false
}
return true
}
示例12: Execute
func (req *userApiRequirement) Execute() (success bool) {
var apiResponse net.ApiResponse
req.user, apiResponse = req.userRepo.FindByUsername(req.username)
if apiResponse.IsNotSuccessful() {
req.ui.Failed(apiResponse.Message)
return false
}
return true
}
示例13: Execute
func (req *buildpackApiRequirement) Execute() (success bool) {
var apiResponse net.ApiResponse
req.buildpack, apiResponse = req.buildpackRepo.FindByName(req.name)
if apiResponse.IsNotSuccessful() {
req.ui.Failed(apiResponse.Message)
return false
}
return true
}
示例14: Execute
func (req *organizationApiRequirement) Execute() (success bool) {
var apiResponse net.ApiResponse
req.org, apiResponse = req.orgRepo.FindByName(req.name)
if apiResponse.IsNotSuccessful() {
req.ui.Failed(apiResponse.Message)
return false
}
return true
}
示例15: setSpace
func (cmd Login) setSpace(c *cli.Context, userChanged bool) (err error) {
spaceName := c.String("s")
if spaceName == "" {
// If user is changing, clear the space
if userChanged {
cmd.config.SetSpaceFields(models.SpaceFields{})
}
// Reuse space in config
if cmd.config.HasSpace() && !userChanged {
return
}
var availableSpaces []models.Space
apiResponse := cmd.spaceRepo.ListSpaces(func(space models.Space) bool {
availableSpaces = append(availableSpaces, space)
return (len(availableSpaces) < maxChoices)
})
if apiResponse.IsNotSuccessful() {
err = errors.New(fmt.Sprintf("Error finding available spaces\n%s", apiResponse.Message))
cmd.ui.Failed(err.Error())
return
}
// Target only space if possible
if len(availableSpaces) == 1 {
return cmd.targetSpace(availableSpaces[0])
}
spaceName = cmd.promptForSpaceName(availableSpaces)
}
if spaceName == "" {
cmd.ui.Say("")
err = errors.New(userSkippedInput)
return
}
var space models.Space
var apiResponse net.ApiResponse
space, apiResponse = cmd.spaceRepo.FindByName(spaceName)
if apiResponse.IsNotSuccessful() {
err = errors.New(fmt.Sprintf("Error finding space %s\n%s", terminal.EntityNameColor(spaceName), apiResponse.Message))
cmd.ui.Failed(err.Error())
return
}
err = cmd.targetSpace(space)
return
}