Skip to content

Commit f79f639

Browse files
committed
feat: use json2
1 parent 8be29da commit f79f639

File tree

3 files changed

+5
-3
lines changed

3 files changed

+5
-3
lines changed

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ go 1.21
55
require (
66
github.com/go-chi/chi/v5 v5.0.10
77
github.com/go-chi/cors v1.2.1
8+
github.com/go-json-experiment/json v0.0.0-20230922184908-dc36ffcf8533
89
github.com/go-logr/logr v1.2.4
910
github.com/go-logr/zapr v1.2.4
1011
github.com/golang-jwt/jwt v3.2.2+incompatible

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ github.com/go-chi/chi/v5 v5.0.10 h1:rLz5avzKpjqxrYwXNfmjkrYYXOyLJd37pz53UFHC6vk=
1111
github.com/go-chi/chi/v5 v5.0.10/go.mod h1:DslCQbL2OYiznFReuXYUmQ2hGd1aDpCnlMNITLSKoi8=
1212
github.com/go-chi/cors v1.2.1 h1:xEC8UT3Rlp2QuWNEr4Fs/c2EAGVKBwy/1vHx3bppil4=
1313
github.com/go-chi/cors v1.2.1/go.mod h1:sSbTewc+6wYHBBCW7ytsFSn836hqM7JxpglAy2Vzc58=
14+
github.com/go-json-experiment/json v0.0.0-20230922184908-dc36ffcf8533 h1:1SRqDZauC9fz6vMIDLCUOULPNfOnZ0rmvZo8quraoy4=
15+
github.com/go-json-experiment/json v0.0.0-20230922184908-dc36ffcf8533/go.mod h1:6daplAwHHGbUGib4990V3Il26O0OC4aRyvewaaAihaA=
1416
github.com/go-logr/logr v1.2.0/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
1517
github.com/go-logr/logr v1.2.4 h1:g01GSCwiDw2xSZfjJ2/T9M+S6pFdcNtFYsp+Y43HYDQ=
1618
github.com/go-logr/logr v1.2.4/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=

server.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package main
22

33
import (
44
"context"
5-
"encoding/json"
65
"errors"
76
"fmt"
87
"net/http"
@@ -14,6 +13,7 @@ import (
1413
"github.com/go-chi/chi/v5"
1514
"github.com/go-chi/chi/v5/middleware"
1615
"github.com/go-chi/cors"
16+
"github.com/go-json-experiment/json"
1717
"github.com/go-logr/logr"
1818
"github.com/jmoiron/sqlx"
1919
"github.com/spf13/cobra"
@@ -151,8 +151,7 @@ func (server *dbServer) responseError(w http.ResponseWriter, err error) {
151151
func (server *dbServer) responseData(w http.ResponseWriter, data interface{}, statusCode int) {
152152
w.WriteHeader(statusCode)
153153

154-
enc := json.NewEncoder(w)
155-
if encodeErr := enc.Encode(data); encodeErr != nil {
154+
if encodeErr := json.MarshalWrite(w, data); encodeErr != nil {
156155
server.logger.Error(encodeErr, "failed to write response")
157156
w.WriteHeader(http.StatusInternalServerError)
158157
return

0 commit comments

Comments
 (0)