mirror of
https://github.com/yusing/godoxy.git
synced 2025-05-20 04:42:33 +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 (
|
||||
"encoding/json"
|
||||
"slices"
|
||||
"strings"
|
||||
|
||||
"github.com/yusing/go-proxy/internal/utils/strutils/ansi"
|
||||
|
@ -89,10 +90,8 @@ func (err *withSubject) Error() string {
|
|||
|
||||
// MarshalJSON implements the json.Marshaler interface.
|
||||
func (err *withSubject) MarshalJSON() ([]byte, error) {
|
||||
subjects := make([]string, len(err.Subjects))
|
||||
for i, s := range err.Subjects {
|
||||
subjects[len(err.Subjects)-i-1] = s
|
||||
}
|
||||
subjects := slices.Clone(err.Subjects)
|
||||
slices.Reverse(subjects)
|
||||
|
||||
reversed := map[string]any{
|
||||
"subjects": subjects,
|
||||
|
|
Loading…
Add table
Reference in a new issue