func (cs *StarterClient) CreateWorkspace(ctx context.Context, workspace WorkspaceRequest) (*WorkspaceResponse, error) {
	body, err := json.Marshal(&workspace)
	if err != nil {
		log.Error(ctx, map[string]interface{}{
			"workspace_id": workspace.ID,
			"err":          err,
		}, "failed to create request object")
		return nil, err
	}

	req, err := http.NewRequest("POST", cs.targetURL("workspace"), bytes.NewReader(body))
	if err != nil {
		return nil, err
	}
	cs.setHeaders(ctx, req)

	if log.IsDebug() {
		b, _ := httputil.DumpRequest(req, true)
		log.Debug(ctx, map[string]interface{}{
			"request": string(b),
		}, "request object")
	}

	resp, err := cs.client.Do(req)
	if err != nil {
		return nil, err
	}

	defer resp.Body.Close()

	if resp.StatusCode != http.StatusCreated && resp.StatusCode != http.StatusOK {
		workspaceErr := WorkspaceError{}
		err = json.NewDecoder(resp.Body).Decode(&workspaceErr)
		if err != nil {
			log.Error(ctx, map[string]interface{}{
				"workspace_id": workspace.ID,
				"err":          err,
			}, "failed to decode error response from create workspace for repository")
			return nil, err
		}
		log.Error(ctx, map[string]interface{}{
			"workspace_id": workspace.ID,
			"err":          workspaceErr.String(),
		}, "failed to execute create workspace for repository")
		return nil, &workspaceErr
	}

	workspaceResp := WorkspaceResponse{}
	err = json.NewDecoder(resp.Body).Decode(&workspaceResp)
	if err != nil {
		log.Error(ctx, map[string]interface{}{
			"workspace_id": workspace.ID,
			"err":          err,
		}, "failed to decode response from create workspace for repository")
		return nil, err
	}
	return &workspaceResp, nil
}
// CreateWorkspace creates a new Che Workspace based on a repository
CreateWorkspace creates a new Che Workspace based on a repository
// CreateWorkspace creates a new Che Workspace based on a repository
func (cs *StarterClient) CreateWorkspace(ctx context.Context, workspace WorkspaceRequest) (*WorkspaceResponse, error) {
	body, err := json.Marshal(&workspace)
	if err != nil {
		log.Error(ctx, map[string]interface{}{
			"workspace_id": workspace.ID,
			"err":          err,
		}, "failed to create request object")
		return nil, err
	}
	req, err := http.NewRequest("POST", cs.targetURL("workspace"), bytes.NewReader(body))
	if err != nil {
		return nil, err
	}
	cs.setHeaders(ctx, req)
	if log.IsDebug() {
		b, _ := httputil.DumpRequest(req, true)
		log.Debug(ctx, map[string]interface{}{
			"request": string(b),
		}, "request object")
	}
	resp, err := cs.client.Do(req)
	if err != nil {
		return nil, err
	}
	defer resp.Body.Close()
	if resp.StatusCode != http.StatusCreated && resp.StatusCode != http.StatusOK {
		workspaceErr := WorkspaceError{}
		err = json.NewDecoder(resp.Body).Decode(&workspaceErr)
		if err != nil {
			log.Error(ctx, map[string]interface{}{
				"workspace_id": workspace.ID,
				"err":          err,
			}, "failed to decode error response from create workspace for repository")
			return nil, err
		}
		log.Error(ctx, map[string]interface{}{
			"workspace_id": workspace.ID,
			"err":          workspaceErr.String(),
		}, "failed to execute create workspace for repository")
		return nil, &workspaceErr
	}
	workspaceResp := WorkspaceResponse{}
	err = json.NewDecoder(resp.Body).Decode(&workspaceResp)
	if err != nil {
		log.Error(ctx, map[string]interface{}{
			"workspace_id": workspace.ID,
			"err":          err,
		}, "failed to decode response from create workspace for repository")
		return nil, err
	}
	return &workspaceResp, nil
}
func ( cs * StarterClient ) CreateWorkspace ( ctx context . Context , workspace WorkspaceRequest ) ( * WorkspaceResponse , error ) { body , err := json . Marshal ( & workspace ) if err != nil { log . Error ( ctx , map [ string ] interface { } { " " : workspace . ID , " " : err , } , " " ) return nil , err } req , err := http . NewRequest ( " " , cs . targetURL ( " " ) , bytes . NewReader ( body ) ) if err != nil { return nil , err } cs . setHeaders ( ctx , req ) if log . IsDebug ( ) { b , _ := httputil . DumpRequest ( req , true ) log . Debug ( ctx , map [ string ] interface { } { " " : string ( b ) , } , " " ) } resp , err := cs . client . Do ( req ) if err != nil { return nil , err } defer resp . Body . Close ( ) if resp . StatusCode != http . StatusCreated && resp . StatusCode != http . StatusOK { workspaceErr := WorkspaceError { } err = json . NewDecoder ( resp . Body ) . Decode ( & workspaceErr ) if err != nil { log . Error ( ctx , map [ string ] interface { } { " " : workspace . ID , " " : err , } , " " ) return nil , err } log . Error ( ctx , map [ string ] interface { } { " " : workspace . ID , " " : workspaceErr . String ( ) , } , " " ) return nil , & workspaceErr } workspaceResp := WorkspaceResponse { } err = json . NewDecoder ( resp . Body ) . Decode ( & workspaceResp ) if err != nil { log . Error ( ctx , map [ string ] interface { } { " " : workspace . ID , " " : err , } , " " ) return nil , err } return & workspaceResp , nil }
CreateWorkspace creates a new Che Workspace based on a repository
CreateWorkspace creates a new Che Workspace based on a repository