Ejemplo n.º 1
0
func SearchJSON(ctx *middleware.Context) {
	q := ctx.QueryEscape("q")
	pinfos, err := models.SearchPkgInfo(7, q)
	if err != nil {
		log.ErrorD(4, "SearchPkgInfo '%s': %v", q, err)
		return
	}

	results := make([]*searchResult, len(pinfos))
	for i := range pinfos {
		results[i] = &searchResult{
			Title:       pinfos[i].ImportPath,
			Description: pinfos[i].Synopsis,
		}
	}

	ctx.JSON(200, map[string]interface{}{
		"results": results,
	})
}