harness-drone/handler/api/template/find.go

34 lines
832 B
Go
Raw Permalink Normal View History

2021-05-19 13:18:24 +00:00
// Copyright 2019 Drone.IO Inc. All rights reserved.
// Use of this source code is governed by the Drone Non-Commercial License
// that can be found in the LICENSE file.
// +build !oss
package template
import (
2021-06-01 09:29:58 +00:00
"net/http"
2021-05-19 13:18:24 +00:00
"github.com/drone/drone/core"
"github.com/drone/drone/handler/api/render"
2021-06-02 13:11:18 +00:00
2021-05-19 13:18:24 +00:00
"github.com/go-chi/chi"
)
// HandleFind returns an http.HandlerFunc that writes json-encoded
// template details to the the response body.
func HandleFind(templateStore core.TemplateStore) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var (
name = chi.URLParam(r, "name")
namespace = chi.URLParam(r, "namespace")
2021-05-19 13:18:24 +00:00
)
template, err := templateStore.FindName(r.Context(), name, namespace)
2021-05-19 13:18:24 +00:00
if err != nil {
render.NotFound(w, err)
return
}
render.JSON(w, template, 200)
}
}