mirror of
https://github.com/harness/drone.git
synced 2025-05-04 06:29:59 +00:00
This commit contains the following: - Improve and simplify error handling (remove unnecessary wrappers, make it feel like go) - Add extra validation for path creation and resource moving (path has to be within same top space, no top space alias allowed) - Add access logging for rest api and git api
29 lines
659 B
Go
29 lines
659 B
Go
package platform
|
|
|
|
import (
|
|
"encoding/json"
|
|
"net/http"
|
|
|
|
"github.com/harness/gitness/internal/api/render"
|
|
)
|
|
|
|
// RenderResource is a helper function that renders a single
|
|
// resource, wrapped in the harness payload envelope.
|
|
func RenderResource(w http.ResponseWriter, code int, v interface{}) {
|
|
payload := new(wrapper)
|
|
payload.Status = "SUCCESS"
|
|
payload.Data, _ = json.Marshal(v)
|
|
if code > 399 {
|
|
payload.Status = "ERROR"
|
|
} else if code > 299 {
|
|
payload.Status = "FAILURE"
|
|
}
|
|
render.JSON(w, code, payload)
|
|
}
|
|
|
|
// wrapper defines the payload wrapper.
|
|
type wrapper struct {
|
|
Status string `json:"status"`
|
|
Data json.RawMessage `json:"data"`
|
|
}
|