Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: use json2 #59

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Dockerfile.server
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:1.18 as builder
FROM golang:1.21 as builder

WORKDIR /workspace
# Copy the Go Modules manifests
Expand All @@ -12,7 +12,7 @@ COPY . .

# Build
RUN GOOS=linux CGO_ENABLED=1 GOARCH=amd64 \
go build -v -x -o bin/sqlite-rest ./
go build -trimpath -v -x -o bin/sqlite-rest ./

FROM docker.io/library/debian:stable-slim

Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ go 1.21
require (
github.com/go-chi/chi/v5 v5.0.10
github.com/go-chi/cors v1.2.1
github.com/go-json-experiment/json v0.0.0-20230922184908-dc36ffcf8533
github.com/go-logr/logr v1.2.4
github.com/go-logr/zapr v1.2.4
github.com/golang-jwt/jwt v3.2.2+incompatible
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ github.com/go-chi/chi/v5 v5.0.10 h1:rLz5avzKpjqxrYwXNfmjkrYYXOyLJd37pz53UFHC6vk=
github.com/go-chi/chi/v5 v5.0.10/go.mod h1:DslCQbL2OYiznFReuXYUmQ2hGd1aDpCnlMNITLSKoi8=
github.com/go-chi/cors v1.2.1 h1:xEC8UT3Rlp2QuWNEr4Fs/c2EAGVKBwy/1vHx3bppil4=
github.com/go-chi/cors v1.2.1/go.mod h1:sSbTewc+6wYHBBCW7ytsFSn836hqM7JxpglAy2Vzc58=
github.com/go-json-experiment/json v0.0.0-20230922184908-dc36ffcf8533 h1:1SRqDZauC9fz6vMIDLCUOULPNfOnZ0rmvZo8quraoy4=
github.com/go-json-experiment/json v0.0.0-20230922184908-dc36ffcf8533/go.mod h1:6daplAwHHGbUGib4990V3Il26O0OC4aRyvewaaAihaA=
github.com/go-logr/logr v1.2.0/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
github.com/go-logr/logr v1.2.4 h1:g01GSCwiDw2xSZfjJ2/T9M+S6pFdcNtFYsp+Y43HYDQ=
github.com/go-logr/logr v1.2.4/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
Expand Down
5 changes: 2 additions & 3 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package main

import (
"context"
"encoding/json"
"errors"
"fmt"
"net/http"
Expand All @@ -14,6 +13,7 @@ import (
"github.com/go-chi/chi/v5"
"github.com/go-chi/chi/v5/middleware"
"github.com/go-chi/cors"
"github.com/go-json-experiment/json"
"github.com/go-logr/logr"
"github.com/jmoiron/sqlx"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -151,8 +151,7 @@ func (server *dbServer) responseError(w http.ResponseWriter, err error) {
func (server *dbServer) responseData(w http.ResponseWriter, data interface{}, statusCode int) {
w.WriteHeader(statusCode)

enc := json.NewEncoder(w)
if encodeErr := enc.Encode(data); encodeErr != nil {
if encodeErr := json.MarshalWrite(w, data); encodeErr != nil {
server.logger.Error(encodeErr, "failed to write response")
w.WriteHeader(http.StatusInternalServerError)
return
Expand Down
Loading