1
0
mirror of https://github.com/lxc/incus.git synced 2026-02-05 18:45:46 +01:00

8 Commits

Author SHA1 Message Date
JUN JIE NAN
ac3082a4f6 shared/api: Simplify code by using modern constructs
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>
2025-05-17 12:32:29 -04:00
Thomas Parrott
a574978054 Replace interface{} with any
Go 1.18 has a new data type called `any` that represents `interface{}` in a clearer way/

Signed-off-by: Thomas Parrott <thomas.parrott@canonical.com>
2022-03-30 16:41:04 +01:00
Thomas Parrott
6b03d1651e shared/api/error: Update StatusErrorf to not parse format to fmt.Sprintf if no replacement arguments
Allows passing a simple message and not have it parsed for format replacements.

Signed-off-by: Thomas Parrott <thomas.parrott@canonical.com>
2021-11-05 13:16:28 +00:00
Thomas Parrott
b5cf08b2dc shared/api/error: Adds StatusErrorCheck helper function
Signed-off-by: Thomas Parrott <thomas.parrott@canonical.com>
2021-10-08 13:24:41 +01:00
Thomas Parrott
8a98613286 shared/api/error: Improve argument name in StatusErrorMatch
Signed-off-by: Thomas Parrott <thomas.parrott@canonical.com>
2021-10-08 13:24:41 +01:00
Thomas Parrott
4d8e741448 shared/api/error: Adds StatusErrorMatch helper function
Signed-off-by: Thomas Parrott <thomas.parrott@canonical.com>
2021-08-27 10:14:42 +01:00
Thomas Parrott
9338ccddc4 shared/api/error: Removes pointer receivers from StatusError functions
This was causing complexity when using errors.As() as it required a pointer to a pointer.

Signed-off-by: Thomas Parrott <thomas.parrott@canonical.com>
2021-08-27 10:11:47 +01:00
Thomas Parrott
54be3103a4 shared/api/error: Adds StatusError type
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>
2021-08-19 14:29:08 +01:00