cancel
Showing results for 
Search instead for 
Did you mean: 

How to match types with a Model + returning a list of objects (JSON)

Occasional Visitor

How to match types with a Model + returning a list of objects (JSON)

For the love of God, can someone please help me? I've spent hours on this and don't know what's wrong.

 

So, TLDR: I'm calling some GETs, webscraping for info (4 pieces of info: company, location, title, url), storing it in structs and trying to create a JSON array of objects to return to the user on a POST request (/get_jobs). 

 

In the handler, configureAPI is killing me. I basically take the params from operations.myFileHere and pass it into my function (it's just a list of strings/URLs), but the return/response type is killing me. WithPayload is taking in []*PostGetJobsOKBodyItems0. I called my struct in my file after this name (it's some generated one). And I return a list of pointers to structs but it still isn't happy....

 

How do I match the type of a model? Or how do I get the return type correct so that I can call WithPayload and it will all be good to go? 

 

Please assist...

 

Thanks!

 

Some code below:

 

 
	api.PostGetJobsHandler = operations.PostGetJobsHandlerFunc(

		func(params operations.PostGetJobsParams) middleware.Responder {

		list := params.ListOfUrls
		response := project.Main(list)

		//struc := &operations.PostGetJobsOK{response}

		return operations.NewPostGetJobsOK().WithPayload(?????)
	})
 
 
func Main(vals []string) []*PostGetJobsOKBodyItems0 {

	var list []*PostGetJobsOKBodyItems0

	for _, element := range vals {

		company, job, location := get(string(element))

		jobPosting := &PostGetJobsOKBodyItems0 {
			Title: job,
			Location: location,
			Company: company,
			Url: element,
		}

		fmt.Println(reflect.TypeOf(jobPosting))
		fmt.Println(reflect.TypeOf(*jobPosting))

		list = append(list, jobPosting)
type PostGetJobsOKBodyItems0 struct {
	Title string `json:"title"`
	Location string `json:"location"`
	Company string `json:"company"`
	Url string `json:"url"`
}
      responses:
        200:
          description: OK
          schema:
            type: array
            items:
              type: object
              properties:
                title:
                  type: string
                location:
                  type: string
                company:
                  type: string
                url:
                  type: string


Operations.responses:

type PostGetJobsOK struct {

	/*
	  In: Body
	*/
	Payload []*PostGetJobsOKBodyItems0 `json:"body,omitempty"`
}

New Here?
Join us and watch the welcome video:
Watch the new Interview