// compensationSearch searches for job on compensation.
func compensationSearch(w io.Writer, projectID, companyName string) (*talent.SearchJobsResponse, error) {
ctx := context.Background()
client, err := google.DefaultClient(ctx, talent.CloudPlatformScope)
if err != nil {
return nil, fmt.Errorf("google.DefaultClient: %w", err)
}
// Create the jobs service client.
service, err := talent.New(client)
if err != nil {
return nil, fmt.Errorf("talent.New: %w", err)
}
jobQuery := &talent.JobQuery{
CompensationFilter: &talent.CompensationFilter{
Type: "UNIT_AND_AMOUNT",
Units: []string{"HOURLY"},
Range: &talent.CompensationRange{
MaxCompensation: &talent.Money{
Units: 15,
CurrencyCode: "USD",
},
MinCompensation: &talent.Money{
Units: 10,
CurrencyCode: "USD",
Nanos: 500000000,
},
},
},
}
if companyName != "" {
jobQuery.CompanyNames = []string{companyName}
}
parent := "projects/" + projectID
req := &talent.SearchJobsRequest{
// Make sure to set the RequestMetadata the same as the associated
// search request.
RequestMetadata: &talent.RequestMetadata{
// Make sure to hash your userID.
UserId: "HashedUsrId",
// Make sure to hash the sessionID.
SessionId: "HashedSessionId",
// Domain of the website where the search is conducted.
Domain: "www.googlesample.com",
},
// Set the actual search term as defined in the jobQuery.
JobQuery: jobQuery,
// Set the search mode to a regular search.
SearchMode: "JOB_SEARCH",
}
resp, err := service.Projects.Jobs.Search(parent, req).Do()
if err != nil {
return nil, fmt.Errorf("failed to search for jobs with compensation: %w", err)
}
fmt.Fprintln(w, "Jobs:")
for _, j := range resp.MatchingJobs {
fmt.Fprintf(w, "\t%q\n", j.Job.Name)
}
return resp, nil
}