import (
"context"
"fmt"
"io"
talent "cloud.google.com/go/talent/apiv4beta1"
"cloud.google.com/go/talent/apiv4beta1/talentpb"
)
// createJob create a job as given.
func createJob(w io.Writer, projectID, companyID, requisitionID, title, URI, description, address1, address2, languageCode string) (*talentpb.Job, error) {
ctx := context.Background()
// Initialize a jobService client.
c, err := talent.NewJobClient(ctx)
if err != nil {
return nil, fmt.Errorf("talent.NewJobClient: %w", err)
}
defer c.Close()
jobToCreate := &talentpb.Job{
Company: fmt.Sprintf("projects/%s/companies/%s", projectID, companyID),
RequisitionId: requisitionID,
Title: title,
ApplicationInfo: &talentpb.Job_ApplicationInfo{
Uris: []string{URI},
},
Description: description,
Addresses: []string{address1, address2},
LanguageCode: languageCode,
}
// Construct a createJob request.
req := &talentpb.CreateJobRequest{
Parent: fmt.Sprintf("projects/%s", projectID),
Job: jobToCreate,
}
resp, err := c.CreateJob(ctx, req)
if err != nil {
return nil, fmt.Errorf("CreateJob: %w", err)
}
fmt.Fprintf(w, "Created job: %q\n", resp.GetName())
return resp, nil
}