mirror of
https://github.com/yusing/godoxy.git
synced 2025-05-20 12:42:34 +02:00
refactor(gperr): simplify JSON marshaling in withSubject by using slices package for cloning and reversing subjects
This commit is contained in:
parent
fb217cf80e
commit
4d030d2e16
1 changed files with 3 additions and 4 deletions
|
@ -2,6 +2,7 @@ package gperr
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"slices"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/yusing/go-proxy/internal/utils/strutils/ansi"
|
"github.com/yusing/go-proxy/internal/utils/strutils/ansi"
|
||||||
|
@ -89,10 +90,8 @@ func (err *withSubject) Error() string {
|
||||||
|
|
||||||
// MarshalJSON implements the json.Marshaler interface.
|
// MarshalJSON implements the json.Marshaler interface.
|
||||||
func (err *withSubject) MarshalJSON() ([]byte, error) {
|
func (err *withSubject) MarshalJSON() ([]byte, error) {
|
||||||
subjects := make([]string, len(err.Subjects))
|
subjects := slices.Clone(err.Subjects)
|
||||||
for i, s := range err.Subjects {
|
slices.Reverse(subjects)
|
||||||
subjects[len(err.Subjects)-i-1] = s
|
|
||||||
}
|
|
||||||
|
|
||||||
reversed := map[string]any{
|
reversed := map[string]any{
|
||||||
"subjects": subjects,
|
"subjects": subjects,
|
||||||
|
|
Loading…
Add table
Reference in a new issue