MCPcopy Index your code
hub / github.com/coder/coder / templateExamples

Method templateExamples

coderd/templates.go:949–967  ·  view source on GitHub ↗

@Summary Get template examples @ID get-template-examples @Security CoderSessionToken @Produce json @Tags Templates @Success 200 {array} codersdk.TemplateExample @Router /api/v2/templates/examples [get]

(rw http.ResponseWriter, r *http.Request)

Source from the content-addressed store, hash-verified

947// @Success 200 {array} codersdk.TemplateExample
948// @Router /api/v2/templates/examples [get]
949func (api *API) templateExamples(rw http.ResponseWriter, r *http.Request) {
950 ctx := r.Context()
951
952 if !api.Authorize(r, policy.ActionRead, rbac.ResourceTemplate.AnyOrganization()) {
953 httpapi.ResourceNotFound(rw)
954 return
955 }
956
957 ex, err := examples.List()
958 if err != nil {
959 httpapi.Write(ctx, rw, http.StatusInternalServerError, codersdk.Response{
960 Message: "Internal error fetching examples.",
961 Detail: err.Error(),
962 })
963 return
964 }
965
966 httpapi.Write(ctx, rw, http.StatusOK, ex)
967}
968
969func (api *API) convertTemplates(templates []database.Template) []codersdk.Template {
970 apiTemplates := make([]codersdk.Template, 0, len(templates))

Callers

nothing calls this directly

Calls 7

AuthorizeMethod · 0.95
ResourceNotFoundFunction · 0.92
ListFunction · 0.92
WriteFunction · 0.92
AnyOrganizationMethod · 0.80
ContextMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected