getNamed displays the search expression or constraint json for the requested alias.
(ctx context.Context, name string)
| 952 | |
| 953 | // getNamed displays the search expression or constraint json for the requested alias. |
| 954 | func (h *Handler) getNamed(ctx context.Context, name string) (string, error) { |
| 955 | if h.fetcher == nil { |
| 956 | return "", fmt.Errorf("GetNamed functionality not available") |
| 957 | } |
| 958 | sr, err := h.Query(ctx, NamedSearch(name)) |
| 959 | if err != nil { |
| 960 | return "", err |
| 961 | } |
| 962 | |
| 963 | if len(sr.Blobs) < 1 { |
| 964 | return "", fmt.Errorf("No named search found for: %s", name) |
| 965 | } |
| 966 | permaRef := sr.Blobs[0].Blob |
| 967 | substRefS := sr.Describe.Meta.Get(permaRef).Permanode.Attr.Get("camliContent") |
| 968 | br, ok := blob.Parse(substRefS) |
| 969 | if !ok { |
| 970 | return "", fmt.Errorf("Invalid blob ref: %s", substRefS) |
| 971 | } |
| 972 | |
| 973 | reader, _, err := h.fetcher.Fetch(ctx, br) |
| 974 | if err != nil { |
| 975 | return "", err |
| 976 | } |
| 977 | result, err := io.ReadAll(reader) |
| 978 | if err != nil { |
| 979 | return "", err |
| 980 | } |
| 981 | return string(result), nil |
| 982 | } |
| 983 | |
| 984 | // NamedSearch returns a *SearchQuery to find the permanode of the search alias "name". |
| 985 | func NamedSearch(name string) *SearchQuery { |
no test coverage detected