Files
skillshare/internal/server/handler_search.go
T
Willie 092fb14f8a feat: add web dashboard with embedded React SPA (skillshare ui)
Single-binary web UI for visual skill management — React 19 + Vite
frontend embedded via go:embed, Go net/http REST API backend (30+
endpoints). Includes dashboard, skills browser, targets, sync, collect,
search, install, config editor, backup/restore, and git sync pages.

Also adds Bitbucket/GitLab URL parsing for install, git operations
library, skill version checking, CI frontend build steps, Docker
sandbox support, and website docs for the ui command.
2026-02-08 05:08:30 +08:00

53 lines
1.1 KiB
Go

package server
import (
"net/http"
"strconv"
"skillshare/internal/search"
)
func (s *Server) handleSearch(w http.ResponseWriter, r *http.Request) {
query := r.URL.Query().Get("q")
if query == "" {
writeError(w, http.StatusBadRequest, "query parameter 'q' is required")
return
}
limit := 20
if l := r.URL.Query().Get("limit"); l != "" {
if parsed, err := strconv.Atoi(l); err == nil {
limit = parsed
}
}
results, err := search.Search(query, limit)
if err != nil {
writeError(w, http.StatusInternalServerError, err.Error())
return
}
type resultItem struct {
Name string `json:"name"`
Description string `json:"description"`
Source string `json:"source"`
Stars int `json:"stars"`
Owner string `json:"owner"`
Repo string `json:"repo"`
}
items := make([]resultItem, 0, len(results))
for _, r := range results {
items = append(items, resultItem{
Name: r.Name,
Description: r.Description,
Source: r.Source,
Stars: r.Stars,
Owner: r.Owner,
Repo: r.Repo,
})
}
writeJSON(w, map[string]any{"results": items})
}