Skip to content

Commit

Permalink
新增 EndWithJSON
Browse files Browse the repository at this point in the history
  • Loading branch information
eaglexiang committed Dec 13, 2024
1 parent c11b9be commit b664e0f
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
10 changes: 10 additions & 0 deletions costwhere.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ package costwhere

import (
"context"
"encoding/json"

"github.com/pkg/errors"
)

func Init(ctx context.Context, topic string) (newCtx context.Context, s *CostWhere) {
Expand All @@ -27,6 +30,13 @@ func newCostWhere(root *StackLayer) *CostWhere {
return s
}

func (s *CostWhere) EndWithJSON() (j []byte, err error) {
stacks := s.End()
j, err = json.Marshal(stacks)
err = errors.WithStack(err)
return
}

func (s *CostWhere) End() (stacks []string) {
s.Root.Stop()
stacks = s.Root.Format("")
Expand Down
5 changes: 4 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ module github.com/eaglexiang/costwhere-go

go 1.21

require github.com/samber/lo v1.47.0
require (
github.com/pkg/errors v0.9.1
github.com/samber/lo v1.47.0
)

require golang.org/x/text v0.16.0 // indirect
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/samber/lo v1.47.0 h1:z7RynLwP5nbyRscyvcD043DWYoOcYRv3mV8lBeqOCLc=
github.com/samber/lo v1.47.0/go.mod h1:RmDH9Ct32Qy3gduHQuKJ3gW1fMHAnE/fAzQuf6He5cU=
golang.org/x/text v0.16.0 h1:a94ExnEXNtEwYLGJSIUxnWoxoRz/ZcCsV63ROupILh4=
Expand Down

0 comments on commit b664e0f

Please sign in to comment.