Exemplo n.º 1
0
func (h *QueryHandler) RESTOpts(opts map[string]string) {
	indexTypes := []string(nil)
	for indexType, t := range cbgt.PIndexImplTypes {
		if t.QuerySamples != nil {
			s := "For index type ```" + indexType + "```:\n\n"

			for _, sample := range t.QuerySamples() {
				if sample.Text != "" {
					s = s + sample.Text + "\n\n"
				}

				if sample.JSON != nil {
					s = s + "    " +
						cbgt.IndentJSON(sample.JSON, "    ", "  ") +
						"\n"
				}
			}

			indexTypes = append(indexTypes, s)
		}
	}
	sort.Strings(indexTypes)

	opts["param: indexName"] =
		"required, string, URL path parameter\n\n" +
			"The name of the index to be queried."
	opts[""] =
		"The request's POST body depends on the index type:\n\n" +
			strings.Join(indexTypes, "\n")
}
Exemplo n.º 2
0
func (h *CreateIndexHandler) RESTOpts(opts map[string]string) {
	indexTypes := []string(nil)
	for indexType, t := range cbgt.PIndexImplTypes {
		indexTypes = append(indexTypes,
			"```"+indexType+"```: "+
				strings.Split(t.Description, " - ")[1])
	}
	sort.Strings(indexTypes)

	indexParams := []string(nil)
	for _, indexDesc := range indexTypes {
		indexType := strings.Split(indexDesc, "```")[1]
		t := cbgt.PIndexImplTypes[indexType]
		if t.StartSample != nil {
			indexParams = append(indexParams,
				"For indexType ```"+indexType+"```"+
					", an example indexParams JSON:\n\n    "+
					cbgt.IndentJSON(t.StartSample, "    ", "  "))
		} else {
			indexParams = append(indexParams,
				"For indexType ```"+indexType+"```"+
					", the indexParams can be null.")
		}
	}

	sourceTypes := []string(nil)
	for sourceType, t := range cbgt.FeedTypes {
		if t.Public {
			sourceTypes = append(sourceTypes,
				"```"+sourceType+"```: "+
					strings.Split(t.Description, " - ")[1])
		}
	}
	sort.Strings(sourceTypes)

	sourceParams := []string(nil)
	for _, sourceDesc := range sourceTypes {
		sourceType := strings.Split(sourceDesc, "```")[1]
		t := cbgt.FeedTypes[sourceType]
		if t.StartSample != nil {
			sourceParams = append(sourceParams,
				"For sourceType ```"+sourceType+"```"+
					", an example sourceParams JSON:\n\n    "+
					cbgt.IndentJSON(t.StartSample, "    ", "  "))
		} else {
			sourceParams = append(sourceParams,
				"For sourceType ```"+sourceType+"```"+
					", the sourceParams can be null.")
		}
	}

	opts["param: indexName"] =
		"required, string, URL path parameter\n\n" +
			"The name of the to-be-created/updated index definition,\n" +
			"validated with the regular expression of ```" +
			cbgt.INDEX_NAME_REGEXP + "```."
	opts["param: indexType"] =
		"required, string, form parameter\n\n" +
			"Supported indexType's:\n\n* " +
			strings.Join(indexTypes, "\n* ")
	opts["param: indexParams"] =
		"optional (depends on the value of the indexType)," +
			" string (JSON), form parameter\n\n" +
			strings.Join(indexParams, "\n\n")
	opts["param: sourceType"] =
		"required, string, form parameter\n\n" +
			"Supported sourceType's:\n\n* " +
			strings.Join(sourceTypes, "\n* ")
	opts["param: sourceName"] =
		"optional, string, form parameter"
	opts["param: sourceUUID"] =
		"optional, string, form parameter"
	opts["param: sourceParams"] =
		"optional (depends on the value of the sourceType)," +
			" string (JSON), form parameter\n\n" +
			strings.Join(sourceParams, "\n\n")
	opts["param: planParams"] =
		"optional, string (JSON), form parameter"
	opts["param: prevIndexUUID"] =
		"optional, string, form parameter\n\n" +
			"Intended for clients that want to check that they are not " +
			"overwriting the index definition updates of concurrent clients."
	opts["result on error"] =
		`non-200 HTTP error code`
	opts["result on success"] =
		`HTTP 200 with body JSON of {"status": "ok"}` // TODO: Revisit 200 code.
}