Skip to content

Commit

Permalink
Merge pull request #50 from bavix/json-ints-fix
Browse files Browse the repository at this point in the history
sdk fix
  • Loading branch information
rez1dent3 committed Oct 2, 2023
2 parents d0cbaa4 + 4e74a08 commit c6476e9
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 10 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ intgr-test: build
# before: go install github.com/deepmap/oapi-codegen/cmd/oapi-codegen@latest
gen:
oapi-codegen -generate gorilla,types -package rest ./api/openapi/api.yaml > internal/domain/rest/api.gen.go
oapi-codegen -generate client,types -package sdk ./api/openapi/api.yaml > pkg/sdk/api.gen.go
oapi-codegen -generate client,types -package sdk ./api/openapi/api.yaml | sed -e 's/json\.Marshal/Marshal/g' -e 's/json\.Unmarshal/Unmarshal/g' > pkg/sdk/api.gen.go
18 changes: 9 additions & 9 deletions pkg/sdk/api.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 22 additions & 0 deletions pkg/sdk/json.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package sdk

import (
"bytes"

fastjson "encoding/json"
)

func Marshal(v any) ([]byte, error) {
return fastjson.Marshal(v)
}

func Unmarshal(data []byte, v any) error {
decoder := fastjson.NewDecoder(bytes.NewReader(data))
decoder.UseNumber()

if err := decoder.Decode(&v); err != nil {
return err
}

return nil
}

0 comments on commit c6476e9

Please sign in to comment.