feat: non null slice on parser result
All checks were successful
build / build (push) Successful in 1m26s
build / trigger-build-image (push) Successful in 6s

This commit is contained in:
张泊明518370910136 2024-10-01 04:16:11 -04:00
parent 2029cc8ae9
commit 18b7193bc0
GPG Key ID: D47306D7062CDA9D

View File

@ -1,6 +1,7 @@
package stage
import (
"encoding/json"
"fmt"
"strconv"
@ -162,8 +163,17 @@ type ParserResult struct {
Comment string `json:"comment"`
}
type StageResult struct {
Name string `json:"name"`
Results []ParserResult `json:"results"`
ForceQuit bool `json:"force_quit"`
type NonNullSlice[T any] []T
func (s NonNullSlice[T]) MarshalJSON() ([]byte, error) {
if len(s) == 0 {
return []byte("[]"), nil
}
return json.Marshal([]T(s))
}
type StageResult struct {
Name string `json:"name"`
Results NonNullSlice[ParserResult] `json:"results"`
ForceQuit bool `json:"force_quit"`
}