Skip to content

Commit

Permalink
package gripmock/json
Browse files Browse the repository at this point in the history
  • Loading branch information
rez1dent3 committed Jul 7, 2024
1 parent f1a1ccb commit 4658c5a
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 24 deletions.
11 changes: 10 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/bavix/gripmock

go 1.22.2
go 1.22.5

require (
github.com/bavix/features v1.0.0
Expand All @@ -15,6 +15,7 @@ require (
github.com/gorilla/mux v1.8.1
github.com/gripmock/environment v1.0.2
github.com/gripmock/grpc-interceptors v1.0.2
github.com/gripmock/json v1.0.0
github.com/gripmock/shutdown v1.0.0
github.com/gripmock/stuber v1.0.1
github.com/jhump/protoreflect v1.16.0
Expand All @@ -36,23 +37,31 @@ require (
require (
github.com/apapsch/go-jsonmerge/v2 v2.0.0 // indirect
github.com/bufbuild/protocompile v0.14.0 // indirect
github.com/bytedance/sonic v1.11.9 // indirect
github.com/bytedance/sonic/loader v0.1.1 // indirect
github.com/caarlos0/env/v10 v10.0.0 // indirect
github.com/cenkalti/backoff/v4 v4.3.0 // indirect
github.com/cloudwego/base64x v0.1.4 // indirect
github.com/cloudwego/iasm v0.2.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/fatih/color v1.17.0 // indirect
github.com/felixge/httpsnoop v1.0.4 // indirect
github.com/go-logr/logr v1.4.2 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/goccy/go-json v0.10.3 // indirect
github.com/golang/protobuf v1.5.4 // indirect
github.com/gripmock/deeply v1.0.9 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.20.0 // indirect
github.com/klauspost/cpuid/v2 v2.2.5 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.28.0 // indirect
go.opentelemetry.io/otel/metric v1.28.0 // indirect
go.opentelemetry.io/otel/trace v1.28.0 // indirect
go.opentelemetry.io/proto/otlp v1.3.1 // indirect
golang.org/x/arch v0.4.0 // indirect
golang.org/x/exp v0.0.0-20240613232115-7f521ea00fb8 // indirect
golang.org/x/net v0.27.0 // indirect
golang.org/x/sys v0.22.0 // indirect
Expand Down
30 changes: 30 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,18 @@ github.com/bavix/gripmock/protogen v0.0.0-20240706201937-fc1e72a8ad5f/go.mod h1:
github.com/bmatcuk/doublestar v1.1.1/go.mod h1:UD6OnuiIn0yFxxA2le/rnRU1G4RaI4UvFv1sNto9p6w=
github.com/bufbuild/protocompile v0.14.0 h1:z3DW4IvXE5G/uTOnSQn+qwQQxvhckkTWLS/0No/o7KU=
github.com/bufbuild/protocompile v0.14.0/go.mod h1:N6J1NYzkspJo3ZwyL4Xjvli86XOj1xq4qAasUFxGups=
github.com/bytedance/sonic v1.11.9 h1:LFHENlIY/SLzDWverzdOvgMztTxcfcF+cqNsz9pK5zg=
github.com/bytedance/sonic v1.11.9/go.mod h1:LysEHSvpvDySVdC2f87zGWf6CIKJcAvqab1ZaiQtds4=
github.com/bytedance/sonic/loader v0.1.1 h1:c+e5Pt1k/cy5wMveRDyk2X4B9hF4g7an8N3zCYjJFNM=
github.com/bytedance/sonic/loader v0.1.1/go.mod h1:ncP89zfokxS5LZrJxl5z0UJcsk4M4yY2JpfqGeCtNLU=
github.com/caarlos0/env/v10 v10.0.0 h1:yIHUBZGsyqCnpTkbjk8asUlx6RFhhEs+h7TOBdgdzXA=
github.com/caarlos0/env/v10 v10.0.0/go.mod h1:ZfulV76NvVPw3tm591U4SwL3Xx9ldzBP9aGxzeN7G18=
github.com/cenkalti/backoff/v4 v4.3.0 h1:MyRJ/UdXutAwSAT+s3wNd7MfTIcy71VQueUuFK343L8=
github.com/cenkalti/backoff/v4 v4.3.0/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyYozVcomhLiZE=
github.com/cloudwego/base64x v0.1.4 h1:jwCgWpFanWmN8xoIUHa2rtzmkd5J2plF/dnLS6Xd/0Y=
github.com/cloudwego/base64x v0.1.4/go.mod h1:0zlkT4Wn5C6NdauXdJRhSKRlJvmclQ1hhJgA0rcu/8w=
github.com/cloudwego/iasm v0.2.0 h1:1KNIy1I1H9hNNFEEH3DVnI4UujN+1zjpuk6gwHLTssg=
github.com/cloudwego/iasm v0.2.0/go.mod h1:8rXZaNYT2n95jn+zTI1sDr+IgcD2GVs0nlbbQPiEFhY=
github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc=
github.com/cristalhq/base64 v0.1.2 h1:edsefYyYDiac7Ytdh2xdaiiSSJzcI2f0yIkdGEf1qY0=
github.com/cristalhq/base64 v0.1.2/go.mod h1:sy4+2Hale2KbtSqkzpdMeYTP/IrB+HCvxVHWsh2VSYk=
Expand All @@ -39,6 +47,8 @@ github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJn
github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY=
github.com/go-playground/validator/v10 v10.14.1 h1:9c50NUPC30zyuKprjL3vNZ0m5oG+jU0zvx4AqHGnv4k=
github.com/go-playground/validator/v10 v10.14.1/go.mod h1:9iXMNT7sEkjXb0I+enO7QXmzG6QCsPWY4zveKFVRSyU=
github.com/goccy/go-json v0.10.3 h1:KZ5WoDbxAIgm2HNbYckL0se1fHD6rz5j4ywS6ebzDqA=
github.com/goccy/go-json v0.10.3/go.mod h1:oq7eo15ShAhp70Anwd5lgX2pLfOS3QCiwU/PULtXL6M=
github.com/goccy/go-yaml v1.11.3 h1:B3W9IdWbvrUu2OYQGwvU1nZtvMQJPBKgBUuweJjLj6I=
github.com/goccy/go-yaml v1.11.3/go.mod h1:wKnAMd44+9JAAnGQpWVEgBzGt3YuTaQ4uXoHvE4m7WU=
github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
Expand All @@ -62,6 +72,8 @@ github.com/gripmock/environment v1.0.2 h1:gDOmlDV6Tceq2SvH/MIEDksky6NCkte101iR+k
github.com/gripmock/environment v1.0.2/go.mod h1:nzBAHAw6/OYsng65X5q6HVmTmKtlvTHVdI/0OK1GGgQ=
github.com/gripmock/grpc-interceptors v1.0.2 h1:wNmecrDlubuSXhJyJNfTM9ydPcY6w4Pz55HNoSrWRnc=
github.com/gripmock/grpc-interceptors v1.0.2/go.mod h1:Bzh5pbb+sSC1vPmKTcEqg1jUUJFMAobQOuSKSXpMBMM=
github.com/gripmock/json v1.0.0 h1:JUUC134nr4TcO9m9x9pYl8/vlKy9xwwR/gKRDZerR48=
github.com/gripmock/json v1.0.0/go.mod h1:4fPOnjtJDFW4fHzrePmnerxgg/ofUs6wfvuGdQEo/uU=
github.com/gripmock/shutdown v1.0.0 h1:ESDCCBeNHazgAstCpIskaORNWH3b+P03a2gznW+8IFY=
github.com/gripmock/shutdown v1.0.0/go.mod h1:YwyI7uYgIPPdR9k8QNHwzDI2mQNpUSu+WT9mvqVoty4=
github.com/gripmock/stuber v1.0.1 h1:Wml8OxiISjpxuBCztzLc60jbeU+kpgh7HLbbjrkCwGo=
Expand All @@ -71,6 +83,10 @@ github.com/grpc-ecosystem/grpc-gateway/v2 v2.20.0/go.mod h1:P+Lt/0by1T8bfcF3z737
github.com/jhump/protoreflect v1.16.0 h1:54fZg+49widqXYQ0b+usAFHbMkBGR4PpXrsHc8+TBDg=
github.com/jhump/protoreflect v1.16.0/go.mod h1:oYPd7nPvcBw/5wlDfm/AVmU9zH9BgqGCI469pGxfj/8=
github.com/juju/gnuflag v0.0.0-20171113085948-2ce1bb71843d/go.mod h1:2PavIy+JPciBPrBUjwbNvtwB6RQlve+hkpll6QSNmOE=
github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg=
github.com/klauspost/cpuid/v2 v2.2.5 h1:0E5MSMDEoAulmXNFquVs//DdoomxaoTY1kUhbc/qbZg=
github.com/klauspost/cpuid/v2 v2.2.5/go.mod h1:Lcz8mBdAVJIBVzewtcLocK12l3Y+JytZYpaMropDUws=
github.com/knz/go-libedit v1.10.1/go.mod h1:MZTVkCWyz0oBc7JOWP3wNAzd002ZbM/5hgShxwh4x8M=
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
Expand All @@ -96,9 +112,17 @@ github.com/rs/zerolog v1.33.0 h1:1cU2KZkvPxNyfgEmhHAz/1A9Bz+llsdYzklWFzgp0r8=
github.com/rs/zerolog v1.33.0/go.mod h1:/7mN4D5sKwJLZQ2b/znpjC3/GQWY/xaDXUM0kKWRHss=
github.com/spkg/bom v0.0.0-20160624110644-59b7046e48ad/go.mod h1:qLr4V1qq6nMqFKkMo8ZTx3f+BZEkzsRUY10Xsm2mwU0=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/twitchyliquid64/golang-asm v0.15.1 h1:SU5vSMR7hnwNxj24w34ZyCi/FmDZTkS4MhqMhdFk5YI=
github.com/twitchyliquid64/golang-asm v0.15.1/go.mod h1:a1lVb/DtPvCB8fslRZhAngC2+aY1QWCk3Cedj/Gdt08=
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
go.opentelemetry.io/contrib/instrumentation/github.com/gorilla/mux/otelmux v0.53.0 h1:KHTx4DmXkuhl/a4/jU5eDMrPuxulzd7m8nusORJ64Fc=
go.opentelemetry.io/contrib/instrumentation/github.com/gorilla/mux/otelmux v0.53.0/go.mod h1:Orsflew5fQlsj8qLxP5A9Y38PGaRxXs93TGaDHDwGT0=
Expand All @@ -122,6 +146,9 @@ go.opentelemetry.io/proto/otlp v1.3.1 h1:TrMUixzpM0yuc/znrFTP9MMRh8trP93mkCiDVeX
go.opentelemetry.io/proto/otlp v1.3.1/go.mod h1:0X1WI4de4ZsLrrJNLAQbFeLCm3T7yBkR0XqQ7niQU+8=
go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto=
go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE=
golang.org/x/arch v0.0.0-20210923205945-b76863e36670/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8=
golang.org/x/arch v0.4.0 h1:A8WCeEWhLwPBKNbFi5Wv5UTCBx5zzubnXDlMOFAzFMc=
golang.org/x/arch v0.4.0/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/crypto v0.13.0/go.mod h1:y6Z2r+Rw4iayiXXAIxJIDAJ1zMW4yaTpebo8fPOliYc=
Expand Down Expand Up @@ -198,5 +225,8 @@ google.golang.org/protobuf v1.34.2/go.mod h1:qYOHts0dSfpeUzUFpOMr/WGzszTmLH+DiWn
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
nullprogram.com/x/optparse v1.0.0/go.mod h1:KdyPE+Igbe0jQUrVfMqDMeJQIJZEuyV7pjYmp6pbG50=
rsc.io/pdf v0.1.1/go.mod h1:n8OzWcQ6Sp37PL01nO98y4iUCRdTGarVfzxY20ICaU4=
24 changes: 12 additions & 12 deletions internal/app/rest_server.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package app

import (
"encoding/json"
"errors"
"fmt"
"io"
Expand All @@ -14,6 +13,7 @@ import (
"time"

"github.com/google/uuid"
"github.com/gripmock/json"
"github.com/gripmock/stuber"
"golang.org/x/text/cases"
"golang.org/x/text/language"
Expand Down Expand Up @@ -86,7 +86,7 @@ func (h *RestServer) ServicesList(w http.ResponseWriter, r *http.Request) {
}
}

if err := json.NewEncoder(w).Encode(results); err != nil {
if err := json.Encode(w, results); err != nil {
h.responseError(err, w)
}
}
Expand All @@ -105,13 +105,13 @@ func (h *RestServer) ServiceMethodsList(w http.ResponseWriter, r *http.Request,
}
}

if err := json.NewEncoder(w).Encode(results); err != nil {
if err := json.Encode(w, results); err != nil {
h.responseError(err, w)
}
}

func (h *RestServer) Liveness(w http.ResponseWriter, _ *http.Request) {
if err := json.NewEncoder(w).Encode(rest.MessageOK{Message: "ok", Time: time.Now()}); err != nil {
if err := json.Encode(w, rest.MessageOK{Message: "ok", Time: time.Now()}); err != nil {
h.responseError(err, w)
}
}
Expand All @@ -125,7 +125,7 @@ func (h *RestServer) Readiness(w http.ResponseWriter, _ *http.Request) {

w.Header().Set("Content-Type", "application/json")

if err := json.NewEncoder(w).Encode(rest.MessageOK{Message: "ok", Time: time.Now()}); err != nil {
if err := json.Encode(w, rest.MessageOK{Message: "ok", Time: time.Now()}); err != nil {
w.WriteHeader(http.StatusServiceUnavailable)
}
}
Expand Down Expand Up @@ -158,7 +158,7 @@ func (h *RestServer) AddStub(w http.ResponseWriter, r *http.Request) {
}
}

if err := json.NewEncoder(w).Encode(h.stuber.PutMany(inputs...)); err != nil {
if err := json.Encode(w, h.stuber.PutMany(inputs...)); err != nil {
h.responseError(err, w)

return
Expand Down Expand Up @@ -200,23 +200,23 @@ func (h *RestServer) BatchStubsDelete(w http.ResponseWriter, r *http.Request) {
func (h *RestServer) ListUsedStubs(w http.ResponseWriter, _ *http.Request) {
w.Header().Set("Content-Type", "application/json")

if err := json.NewEncoder(w).Encode(h.stuber.Used()); err != nil {
if err := json.Encode(w, h.stuber.Used()); err != nil {
h.responseError(err, w)
}
}

func (h *RestServer) ListUnusedStubs(w http.ResponseWriter, _ *http.Request) {
w.Header().Set("Content-Type", "application/json")

if err := json.NewEncoder(w).Encode(h.stuber.Unused()); err != nil {
if err := json.Encode(w, h.stuber.Unused()); err != nil {
h.responseError(err, w)
}
}

func (h *RestServer) ListStubs(w http.ResponseWriter, _ *http.Request) {
w.Header().Set("Content-Type", "application/json")

if err := json.NewEncoder(w).Encode(h.stuber.All()); err != nil {
if err := json.Encode(w, h.stuber.All()); err != nil {
h.responseError(err, w)
}
}
Expand Down Expand Up @@ -254,7 +254,7 @@ func (h *RestServer) SearchStubs(w http.ResponseWriter, r *http.Request) {
return
}

if err := json.NewEncoder(w).Encode(result.Found().Output); err != nil {
if err := json.Encode(w, result.Found().Output); err != nil {
h.responseError(err, w)
}
}
Expand All @@ -267,7 +267,7 @@ func (h *RestServer) FindByID(w http.ResponseWriter, _ *http.Request, uuid rest.
return
}

if err := json.NewEncoder(w).Encode(stub); err != nil {
if err := json.Encode(w, stub); err != nil {
h.responseError(err, w)
}
}
Expand All @@ -279,7 +279,7 @@ func (h *RestServer) responseError(err error, w http.ResponseWriter) {
}

func (h *RestServer) writeResponseError(err error, w http.ResponseWriter) {
if err := json.NewEncoder(w).Encode(map[string]string{
if err := json.Encode(w, map[string]string{
"error": err.Error(),
}); err != nil {
h.responseError(err, w)
Expand Down
2 changes: 1 addition & 1 deletion internal/app/storage.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package app

import (
"encoding/json"
"fmt"

"github.com/gripmock/json"
"github.com/gripmock/stuber"
)

Expand Down
11 changes: 5 additions & 6 deletions pkg/jsondecoder/decode.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ package jsondecoder

import (
"bytes"
"encoding/json"
stdjson "encoding/json"

"github.com/gripmock/json"
)

const minJSONLength = 2
Expand Down Expand Up @@ -36,16 +38,13 @@ func UnmarshalSlice(data []byte, v interface{}) error {
input := bytes.TrimSpace(data)

if len(input) < minJSONLength {
return &json.SyntaxError{}
return &stdjson.SyntaxError{}
}

// If the input is not a JSON array, wrap it in an array
if len(input) > 0 && input[0] == '{' && input[len(input)-1] == '}' {
input = append(append([]byte{'['}, input...), ']')
}

decoder := json.NewDecoder(bytes.NewReader(input))
decoder.UseNumber()

return decoder.Decode(v)
return json.Decode(bytes.NewReader(input), v)
}
9 changes: 5 additions & 4 deletions pkg/yaml2json/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ package yaml2json

import (
"bytes"
"encoding/json"
"text/template"

"github.com/cristalhq/base64"
"github.com/google/uuid"
"github.com/gripmock/json"
)

type engine struct{}
Expand Down Expand Up @@ -50,12 +50,13 @@ func (e *engine) uuid2int64(str string) string {
"low": low,
}

int64JSON, err := json.Marshal(int64Data)
if err != nil {
var buffer bytes.Buffer

if err := json.Encode(&buffer, int64Data); err != nil {
return ""
}

return string(int64JSON)
return buffer.String()
}

// uuid2base64 converts a UUID string to a base64 string.
Expand Down

0 comments on commit 4658c5a

Please sign in to comment.