Using more modern features of Go, such as:
- conditional assignment -> built-in min or max in go1.21,
- sort.Slice -> slices.Sort in go1.21,
- loop assign map -> maps.Copy in go1.21,
- []byte(fmt.Sprintf...) -> fmt.Appendf(nil,...) in go1.19,
- strings.HasPrefix / strings.TrimPrefix -> strings.CutPrefix in go1.20
Signed-off-by: JUN JIE NAN <nanjunjie@gmail.com>
For use in both LXD server and in the LXD client for passing an HTTP status code in an error to the caller.
This can be used in the LXD server to alter the HTTP status code returned to clients if an error occurs,
and in the LXD client it can be used to propagate the HTTP status code returned from the server to the user
so they can handle errors by inspecting the status code rather than inspecting the error message itself
which may change over time.
Signed-off-by: Thomas Parrott <thomas.parrott@canonical.com>