Documentation
¶
Index ¶
- func JSON(w http.ResponseWriter, code int, data any)
- func NewPullJobWriter(w http.ResponseWriter) *pullJobWriter
- func SendErrorAsInStreamResponse(w http.ResponseWriter, code int, err error) error
- func SendErrorResponse(w http.ResponseWriter, code int, err error)
- func Status(w http.ResponseWriter, code int)
- type Error
- type StreamResponse
- type StreamWriter
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func JSON ¶
func JSON(w http.ResponseWriter, code int, data any)
JSON writes data as JSON object(s) to response with the supplied HTTP status code.
func NewPullJobWriter ¶
func NewPullJobWriter(w http.ResponseWriter) *pullJobWriter
NewPullJobWriter is an extension of StreamWriter that sends image pull status updates from nerdctl to http response as a JSON stream. It ensures that the image is resolved before writing anything to the response body, so that any resolver errors can be sent to the client directly with an appropriate status code.
func SendErrorAsInStreamResponse ¶
func SendErrorAsInStreamResponse(w http.ResponseWriter, code int, err error) error
SendErrorAsInStreamResponse sends a status code and a json-formatted error message in stream response.
func SendErrorResponse ¶
func SendErrorResponse(w http.ResponseWriter, code int, err error)
SendErrorResponse sends a status code and a json-formatted error message (if any).
func Status ¶
func Status(w http.ResponseWriter, code int)
Status writes the supplied HTTP status code to response header.
Types ¶
type Error ¶
type Error struct {
Message string `json:"message"`
}
Error implements the error structure used in Docker Engine API.
func NewErrorFromMsg ¶
type StreamResponse ¶
type StreamResponse struct { Stream string `json:"stream,omitempty"` // TODO: Status string `json:"status,omitempty"` // TODO: Progress *JSONProgress `json:"progressDetail,omitempty"` // TODO: ProgressMessage string `json:"progress,omitempty"` // deprecated // TODO: ID string `json:"id,omitempty"` // TODO: From string `json:"from,omitempty"` // TODO: Time int64 `json:"time,omitempty"` // TODO: TimeNano int64 `json:"timeNano,omitempty"` Error *jsonmessage.JSONError `json:"errorDetail,omitempty"` ErrorMessage string `json:"error,omitempty"` // deprecated // Aux contains out-of-band data, such as digests for push signing and image id after building. Aux *json.RawMessage `json:"aux,omitempty"` }
StreamResponse holds the stream and error messages, if any, for events and status updates.
From https://github.com/moby/moby/blob/v24.0.4/pkg/jsonmessage/jsonmessage.go#L145-L158
type StreamWriter ¶
type StreamWriter struct {
// contains filtered or unexported fields
}
StreamWriter allows to write stdout, stderr output as json steaming data in http response. This struct implements the Write() function defined in Writer interface which allows StreamWriter to capture the output of stdout and stderr and send it to json stream as per docker api spec.
func NewStreamWriter ¶
func NewStreamWriter(w http.ResponseWriter) *StreamWriter
NewStreamWriter creates a new StreamWriter.
func (*StreamWriter) Write ¶
func (sw *StreamWriter) Write(b []byte) (n int, err error)
Write function is implementation of Writer interface. This function converts the stdout and stderr output into json stream and send it though http response.
func (*StreamWriter) WriteAux ¶
func (sw *StreamWriter) WriteAux(data []byte) error
WriteAux sends raw data as a Docker-compatible auxiliary response, such as digests for pushed image or image id after building.
func (*StreamWriter) WriteError ¶
func (sw *StreamWriter) WriteError(code int, err error) error
WriteError sends a Docker-compatible error message and status code as a JSON stream to the http responseWriter. If header is not already set, it will set the header and send error message as a response.Error.