Beispiel #1
0
func (repo CloudControllerRouteRepository) CreateInSpace(host, path, domainGuid, spaceGuid string) (createdRoute models.Route, apiErr error) {
	data := fmt.Sprintf(`{"host":"%s","path":"%s","domain_guid":"%s","space_guid":"%s"}`, host, path, domainGuid, spaceGuid)

	resource := new(resources.RouteResource)
	apiErr = repo.gateway.CreateResource(repo.config.ApiEndpoint(), "/v2/routes?inline-relations-depth=1", strings.NewReader(data), resource)
	if apiErr != nil {
		return
	}

	createdRoute = resource.ToModel()
	return
}
Beispiel #2
0
func (repo CloudControllerRouteRepository) CreateInSpace(host, path, domainGUID, spaceGUID string, port int, randomPort bool) (models.Route, error) {
	path = normalizedPath(path)

	body := struct {
		Host       string `json:"host,omitempty"`
		Path       string `json:"path,omitempty"`
		Port       int    `json:"port,omitempty"`
		DomainGUID string `json:"domain_guid"`
		SpaceGUID  string `json:"space_guid"`
	}{host, path, port, domainGUID, spaceGUID}

	data, err := json.Marshal(body)
	if err != nil {
		return models.Route{}, err
	}

	q := struct {
		GeneratePort         bool `url:"generate_port,omitempty"`
		InlineRelationsDepth int  `url:"inline-relations-depth"`
	}{randomPort, 1}

	opt, _ := query.Values(q)
	uriFragment := "/v2/routes?" + opt.Encode()

	resource := new(resources.RouteResource)
	err = repo.gateway.CreateResource(
		repo.config.APIEndpoint(),
		uriFragment,
		bytes.NewReader(data),
		resource,
	)
	if err != nil {
		return models.Route{}, err
	}

	return resource.ToModel(), nil
}