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

Add SQLite3 support #157

Merged
merged 6 commits into from
May 16, 2023
Merged
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
2 changes: 1 addition & 1 deletion .sonarcloud.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
sonar.exclusions=**/*.gen.go, **/*.sql.go
sonar.cpd.exclusions=**/*_test.go
sonar.cpd.exclusions=**/*_test.go, **/sqlite/*.go, **/postgres/*.go
8 changes: 4 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,11 @@ go_path := PATH="$(go_bin_dir):$(PATH)"
oapi_codegen_version = 1.12.4
oapi_codegen_dir = $(build_dir)/protoc/$(protoc_version):q

server_sqlc_config_file = $(DIR)/pkg/server/datastore/sqlc.yaml
server_sqlc_config_file = $(DIR)/pkg/server/db/sqlc.yaml

sqlc_dir = $(build_dir)/sqlc/$(sqlc_version)
sqlc_bin = $(sqlc_dir)/sqlc
sqlc_version = 1.17.0
sqlc_version = 1.18.0
ifeq ($(os1),windows)
sqlc_url = https://github.com/kyleconroy/sqlc/releases/download/v${sqlc_version}/sqlc_${sqlc_version}_windows_amd64.zip
else ifeq ($(os1),darwin)
Expand Down Expand Up @@ -206,9 +206,9 @@ help:
.PHONY: generate-sqlc-server generete-spec

# Run sqlc to generate sql code
generate-sqlc-server: install-sqlc run-sqlc-server
generate-sqlc-code: install-sqlc run-generate-sqlc

run-sqlc-server:
run-generate-sqlc:
$(sqlc_bin) generate --file $(server_sqlc_config_file)

# Run oapi-codegen to generate api code
Expand Down
5 changes: 3 additions & 2 deletions cmd/harvester/cli/run_test.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package cli

import (
"github.com/spf13/cobra"
"github.com/stretchr/testify/assert"
"os"
"testing"

"github.com/spf13/cobra"
"github.com/stretchr/testify/assert"
)

func TestLoadConfig(t *testing.T) {
Expand Down
12 changes: 3 additions & 9 deletions cmd/server/cli/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ type serverConfig struct {
ListenPort int `hcl:"listen_port,optional"`
SocketPath string `hcl:"socket_path,optional"`
LogLevel string `hcl:"log_level,optional"`
DBConnString string `hcl:"db_conn_string"`
}

// providersBlock holds the Providers HCL block body.
Expand Down Expand Up @@ -76,8 +75,6 @@ func NewServerConfig(c *Config) (*server.Config, error) {

sc.LocalAddress = socketAddr

sc.DBConnString = c.Server.DBConnString

logLevel, err := logrus.ParseLevel(c.Server.LogLevel)
if err != nil {
return nil, fmt.Errorf("failed to parse log level: %v", err)
Expand All @@ -86,12 +83,9 @@ func NewServerConfig(c *Config) (*server.Config, error) {
logger.SetLevel(logLevel)
sc.Logger = logger.WithField(telemetry.SubsystemName, telemetry.Server)

// TODO: eventually providers section will be required
if c.Providers != nil {
sc.ProvidersConfig, err = catalog.ProvidersConfigsFromHCLBody(c.Providers.Body)
if err != nil {
return nil, fmt.Errorf("failed to parse providers configuration: %w", err)
}
sc.ProvidersConfig, err = catalog.ProvidersConfigsFromHCLBody(c.Providers.Body)
if err != nil {
return nil, fmt.Errorf("failed to parse providers configuration: %w", err)
}

return sc, nil
Expand Down
39 changes: 9 additions & 30 deletions cmd/server/cli/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,11 @@ import (
"bytes"
"errors"
"io"
"strings"
"testing"

"github.com/hashicorp/hcl/v2"
"github.com/hashicorp/hcl/v2/gohcl"
"github.com/hashicorp/hcl/v2/hclsyntax"
"github.com/sirupsen/logrus"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
Expand All @@ -19,15 +17,20 @@ var hclConfigWithProviders = `server {
listen_address = "127.0.0.1"
listen_port = "2222"
socket_path = "/tmp/api.sock"
db_conn_string = "test_conn_string"
log_level = "DEBUG"
}

providers {
x509ca "disk" {
Datastore "sqlite3" {
connection_string = "./datastore.sqlite3"
}

X509CA "disk" {
key_file_path = "./root_ca.key"
cert_file_path = "./root_ca.crt"
}

KeyManager "memory" {}
}
`

Expand All @@ -37,26 +40,6 @@ func (fakeReader) Read(p []byte) (n int, err error) {
return 0, errors.New("error from fake reader")
}

func TestNewServerConfig(t *testing.T) {
config := Config{Server: &serverConfig{
ListenAddress: "localhost",
ListenPort: 8000,
SocketPath: "/example",
LogLevel: "INFO",
DBConnString: "postgresql://postgres:postgres@localhost:5432/galadriel",
}}

sc, err := NewServerConfig(&config)
if err != nil {
t.Fatal(err)
}

assert.Equal(t, "127.0.0.1", sc.TCPAddress.IP.String())
assert.Equal(t, config.Server.ListenPort, sc.TCPAddress.Port)
assert.Equal(t, config.Server.SocketPath, sc.LocalAddress.String())
assert.Equal(t, strings.ToLower(config.Server.LogLevel), logrus.GetLevel().String())
}

func TestNew(t *testing.T) {
tests := []struct {
name string
Expand All @@ -73,22 +56,18 @@ func TestNew(t *testing.T) {
ListenPort: 2222,
SocketPath: "/tmp/api.sock",
LogLevel: "DEBUG",
DBConnString: "test_conn_string",
},
},
},
{
name: "defaults",
config: bytes.NewBuffer([]byte(`server {
db_conn_string = "test_conn_string"
}`)),
name: "defaults",
config: bytes.NewBuffer([]byte(`server {}`)),
expected: &Config{
Server: &serverConfig{
ListenAddress: defaultAddress,
ListenPort: defaultPort,
SocketPath: defaultSocketPath,
LogLevel: defaultLogLevel,
DBConnString: "test_conn_string",
},
},
},
Expand Down
9 changes: 7 additions & 2 deletions cmd/server/util/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const (
)

var (
createTrustDomainURL = fmt.Sprintf(localURL, "createTrustDomain")
createTrustDomainURL = fmt.Sprintf(localURL, "trust-domain")
listTrustDomainsURL = fmt.Sprintf(localURL, "listTrustDomains")
createRelationshipURL = fmt.Sprintf(localURL, "createRelationship")
listRelationshipsURL = fmt.Sprintf(localURL, "listRelationships")
Expand Down Expand Up @@ -63,7 +63,12 @@ func (c serverClient) CreateTrustDomain(m *entity.TrustDomain) error {
return err
}

r, err := c.client.Post(createTrustDomainURL, contentType, bytes.NewReader(trustDomainBytes))
req, err := http.NewRequest(http.MethodPut, createTrustDomainURL, bytes.NewReader(trustDomainBytes))
if err != nil {
return err
}
req.Header.Set("Content-Type", "application/json")
r, err := c.client.Do(req)
if err != nil {
return err
}
Expand Down
14 changes: 11 additions & 3 deletions conf/server/server.conf
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,20 @@ server {

# log_level: Sets the logging level <DEBUG|INFO|WARN|ERROR>. Default: INFO.
log_level = "DEBUG"

# db_conn_string: postgres database connection string.
db_conn_string = "postgresql://postgres:postgres@localhost:5432/galadriel"
}

providers {
# datastore: <sqlite3|postgres>
Datastore "sqlite3" {
# connection_string: database connection string.
connection_string = "./datastore.sqlite3"
}

#Datastore "postgres" {
# # connection_string: database connection string.
# connection_string = "postgresql://postgres:postgres@localhost:5432/galadriel"
#}

# X509CA "disk": Uses a ROOT CA loaded from disk to issue X509 certificates.
X509CA "disk" {
# Path to the root CA private key file. PEM format.
Expand Down
14 changes: 12 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,12 @@ require (
github.com/golang-jwt/jwt/v4 v4.5.0
github.com/golang-migrate/migrate/v4 v4.15.2
github.com/google/uuid v1.3.0
github.com/hashicorp/hcl v1.0.0
github.com/hashicorp/hcl/v2 v2.16.2
github.com/jackc/pgerrcode v0.0.0-20220416144525-469b46aa5efa
github.com/jackc/pgtype v1.14.0
github.com/jackc/pgx/v5 v5.3.1
github.com/jmhodges/clock v1.2.0
github.com/labstack/echo/v4 v4.10.2
github.com/mattn/go-sqlite3 v1.14.16
github.com/ory/dockertest/v3 v3.10.0
github.com/pkg/errors v0.9.1
github.com/sirupsen/logrus v1.9.0
Expand Down Expand Up @@ -62,6 +61,7 @@ require (
github.com/jackc/pgproto3/v2 v2.3.1 // indirect
github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 // indirect
github.com/labstack/gommon v0.4.0 // indirect
github.com/lib/pq v1.10.2 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
Expand All @@ -76,6 +76,7 @@ require (
github.com/opencontainers/runc v1.1.5 // indirect
github.com/perimeterx/marshmallow v1.1.4 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/remyoudompheng/bigfft v0.0.0-20200410134404-eec4a21b6bb0 // indirect
github.com/rogpeppe/go-internal v1.8.0 // indirect
github.com/valyala/bytebufferpool v1.0.0 // indirect
github.com/valyala/fasttemplate v1.2.2 // indirect
Expand All @@ -95,4 +96,13 @@ require (
google.golang.org/protobuf v1.30.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
modernc.org/cc/v3 v3.32.4 // indirect
modernc.org/ccgo/v3 v3.9.2 // indirect
modernc.org/libc v1.9.5 // indirect
modernc.org/mathutil v1.2.2 // indirect
modernc.org/memory v1.0.4 // indirect
modernc.org/opt v0.1.1 // indirect
modernc.org/sqlite v1.10.6 // indirect
modernc.org/strutil v1.1.0 // indirect
modernc.org/token v1.0.0 // indirect
)
20 changes: 17 additions & 3 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,7 @@ github.com/docker/libtrust v0.0.0-20150114040149-fa567046d9b1/go.mod h1:cyGadeNE
github.com/docker/spdystream v0.0.0-20160310174837-449fdfce4d96/go.mod h1:Qh8CwZgvJUkLughtfhJv5dyTYa91l1fOUCrgjqmcifM=
github.com/docopt/docopt-go v0.0.0-20180111231733-ee0de3bc6815/go.mod h1:WwZ+bS3ebgob9U8Nd0kOddGdZWjyMGR8Wziv+TBNwSE=
github.com/dustin/go-humanize v0.0.0-20171111073723-bb3d318650d4/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk=
github.com/dustin/go-humanize v1.0.0 h1:VSnTsYCnlFHaM2/igO1h6X3HA71jcobQuxemgkq4zYo=
github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk=
github.com/edsrzf/mmap-go v0.0.0-20170320065105-0bce6a688712/go.mod h1:YO35OhQPt3KJa3ryjFM5Bs14WD66h8eGKpfaBNrHW5M=
github.com/elazarl/goproxy v0.0.0-20180725130230-947c36da3153/go.mod h1:/Zj4wYkgs4iZTTu3o/KG3Itv/qCCa8VVMlb3i9OVuzc=
Expand Down Expand Up @@ -673,7 +674,6 @@ github.com/hashicorp/go-uuid v1.0.1/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/b
github.com/hashicorp/go.net v0.0.1/go.mod h1:hjKkEWcCURg++eb33jQU7oqQcI9XDCnUzHA0oac0k90=
github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4=
github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ=
github.com/hashicorp/hcl/v2 v2.16.2 h1:mpkHZh/Tv+xet3sy3F9Ld4FyI2tUpWe9x3XtPx9f1a0=
github.com/hashicorp/hcl/v2 v2.16.2/go.mod h1:JRmR89jycNkrrqnMmvPDMd56n1rQJ2Q6KocSLCMCXng=
Expand Down Expand Up @@ -715,8 +715,6 @@ github.com/jackc/pgconn v1.9.0/go.mod h1:YctiPyvzfU11JFxoXokUOOKQXQmDMoJL9vJzHH8
github.com/jackc/pgconn v1.9.1-0.20210724152538-d89c8390a530 h1:dUJ578zuPEsXjtzOfEF0q9zDAfljJ9oFnTHcQaNkccw=
github.com/jackc/pgconn v1.9.1-0.20210724152538-d89c8390a530/go.mod h1:4z2w8XhRbP1hYxkpTuBjTS3ne3J48K83+u0zoyvg2pI=
github.com/jackc/pgerrcode v0.0.0-20201024163028-a0d42d470451/go.mod h1:a/s9Lp5W7n/DD0VrVoyJ00FbP2ytTPDVOivvn2bMlds=
github.com/jackc/pgerrcode v0.0.0-20220416144525-469b46aa5efa h1:s+4MhCQ6YrzisK6hFJUX53drDT4UsSW3DEhKn0ifuHw=
github.com/jackc/pgerrcode v0.0.0-20220416144525-469b46aa5efa/go.mod h1:a/s9Lp5W7n/DD0VrVoyJ00FbP2ytTPDVOivvn2bMlds=
github.com/jackc/pgio v1.0.0 h1:g12B9UwVnzGhueNavwioyEEpAmqMe1E/BN9ES+8ovkE=
github.com/jackc/pgio v1.0.0/go.mod h1:oP+2QK2wFfUWgr+gxjoBH9KGBb31Eio69xUb0w5bYf8=
github.com/jackc/pgmock v0.0.0-20190831213851-13a1b77aafa2/go.mod h1:fGZlG77KXmcq05nJLRkk0+p82V8B8Dw8KN2/V9c/OAE=
Expand Down Expand Up @@ -801,6 +799,7 @@ github.com/k0kubun/pp v2.3.0+incompatible/go.mod h1:GWse8YhT0p8pT4ir3ZgBbfZild3t
github.com/kardianos/osext v0.0.0-20190222173326-2bc1f35cddc0/go.mod h1:1NbS8ALrpOvjt0rHPNLyCIeMtbizbir8U//inJ+zuB8=
github.com/karrick/godirwalk v1.8.0/go.mod h1:H5KPZjojv4lE+QYImBI8xVtrBRgYrIVsaRPx4tDPEn4=
github.com/karrick/godirwalk v1.10.3/go.mod h1:RoGL9dQei4vP9ilrpETWE8CLOZ1kiN0LhBygSwrAsHA=
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 h1:Z9n2FFNUXsshfwJMBgNA0RU6/i7WVaAegv3PtuIHPMs=
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51/go.mod h1:CzGEWj7cYgsdH8dAjBGEr58BoE7ScuLd+fwFZ44+/x8=
github.com/kisielk/errcheck v1.1.0/go.mod h1:EZBBE59ingxPouuu3KfxchcWSUPOHkagtvWXihfKN4Q=
github.com/kisielk/errcheck v1.2.0/go.mod h1:/BMXB+zMLi60iA8Vv6Ksmxu/1UDYcXs4uQLJ+jE2L00=
Expand Down Expand Up @@ -882,6 +881,8 @@ github.com/mattn/go-shellwords v1.0.12/go.mod h1:EZzvwXDESEeg03EKmM+RmDnNOPKG4lL
github.com/mattn/go-sqlite3 v1.9.0/go.mod h1:FPy6KqzDD04eiIsT53CuJW3U88zkxoIYsOqkbpncsNc=
github.com/mattn/go-sqlite3 v1.14.6/go.mod h1:NyWgC/yNuGj7Q9rpYnZvas74GogHl5/Z4A/KQRfk6bU=
github.com/mattn/go-sqlite3 v1.14.10/go.mod h1:NyWgC/yNuGj7Q9rpYnZvas74GogHl5/Z4A/KQRfk6bU=
github.com/mattn/go-sqlite3 v1.14.16 h1:yOQRA0RpS5PFz/oikGwBEqvAWhWg5ufRz4ETLjwpU1Y=
github.com/mattn/go-sqlite3 v1.14.16/go.mod h1:2eHXhiwb8IkHr+BDWZGa96P6+rkvnG63S2DGjv9HUNg=
github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0=
github.com/matttproud/golang_protobuf_extensions v1.0.2-0.20181231171920-c182affec369/go.mod h1:BSXmuO+STAnVfrANrmjBb36TMTDstsz7MSK+HVaYKv4=
github.com/maxbrunsfeld/counterfeiter/v6 v6.2.2/go.mod h1:eD9eIE7cdwcMi9rYluz88Jz2VyhSmden33/aXg4oVIY=
Expand Down Expand Up @@ -1053,6 +1054,7 @@ github.com/prometheus/procfs v0.6.0/go.mod h1:cz+aTbrPOrUb4q7XlbU9ygM+/jj0fzG6c1
github.com/prometheus/procfs v0.7.3/go.mod h1:cz+aTbrPOrUb4q7XlbU9ygM+/jj0fzG6c1xBZuNvfVA=
github.com/prometheus/tsdb v0.7.1/go.mod h1:qhTCs0VvXwvX/y3TZrWD7rabWM+ijKTux40TwIPHuXU=
github.com/remyoudompheng/bigfft v0.0.0-20190728182440-6a916e37a237/go.mod h1:qqbHyh8v60DhA7CoWK5oRCqLrMHRGoxYCSS9EjAz6Eo=
github.com/remyoudompheng/bigfft v0.0.0-20200410134404-eec4a21b6bb0 h1:OdAsTTz6OkFY5QxjkYwrChwuRruF69c169dPK26NUlk=
github.com/remyoudompheng/bigfft v0.0.0-20200410134404-eec4a21b6bb0/go.mod h1:qqbHyh8v60DhA7CoWK5oRCqLrMHRGoxYCSS9EjAz6Eo=
github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg=
github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ=
Expand Down Expand Up @@ -1956,29 +1958,41 @@ k8s.io/utils v0.0.0-20201110183641-67b214c5f920/go.mod h1:jPW/WVKK9YHAvNhRxK0md/
k8s.io/utils v0.0.0-20210819203725-bdf08cb9a70a/go.mod h1:jPW/WVKK9YHAvNhRxK0md/EJ228hCsBRufyofKtW8HA=
k8s.io/utils v0.0.0-20210930125809-cb0fa318a74b/go.mod h1:jPW/WVKK9YHAvNhRxK0md/EJ228hCsBRufyofKtW8HA=
modernc.org/b v1.0.0/go.mod h1:uZWcZfRj1BpYzfN9JTerzlNUnnPsV9O2ZA8JsRcubNg=
modernc.org/cc/v3 v3.32.4 h1:1ScT6MCQRWwvwVdERhGPsPq0f55J1/pFEOCiqM7zc78=
modernc.org/cc/v3 v3.32.4/go.mod h1:0R6jl1aZlIl2avnYfbfHBS1QB6/f+16mihBObaBC878=
modernc.org/ccgo/v3 v3.9.2 h1:mOLFgduk60HFuPmxSix3AluTEh7zhozkby+e1VDo/ro=
modernc.org/ccgo/v3 v3.9.2/go.mod h1:gnJpy6NIVqkETT+L5zPsQFj7L2kkhfPMzOghRNv/CFo=
modernc.org/db v1.0.0/go.mod h1:kYD/cO29L/29RM0hXYl4i3+Q5VojL31kTUVpVJDw0s8=
modernc.org/file v1.0.0/go.mod h1:uqEokAEn1u6e+J45e54dsEA/pw4o7zLrA2GwyntZzjw=
modernc.org/fileutil v1.0.0/go.mod h1:JHsWpkrk/CnVV1H/eGlFf85BEpfkrp56ro8nojIq9Q8=
modernc.org/golex v1.0.0/go.mod h1:b/QX9oBD/LhixY6NDh+IdGv17hgB+51fET1i2kPSmvk=
modernc.org/httpfs v1.0.6 h1:AAgIpFZRXuYnkjftxTAZwMIiwEqAfk8aVB2/oA6nAeM=
modernc.org/httpfs v1.0.6/go.mod h1:7dosgurJGp0sPaRanU53W4xZYKh14wfzX420oZADeHM=
modernc.org/internal v1.0.0/go.mod h1:VUD/+JAkhCpvkUitlEOnhpVxCgsBI90oTzSCRcqQVSM=
modernc.org/libc v1.7.13-0.20210308123627-12f642a52bb8/go.mod h1:U1eq8YWr/Kc1RWCMFUWEdkTg8OTcfLw2kY8EDwl039w=
modernc.org/libc v1.9.5 h1:zv111ldxmP7DJ5mOIqzRbza7ZDl3kh4ncKfASB2jIYY=
modernc.org/libc v1.9.5/go.mod h1:U1eq8YWr/Kc1RWCMFUWEdkTg8OTcfLw2kY8EDwl039w=
modernc.org/lldb v1.0.0/go.mod h1:jcRvJGWfCGodDZz8BPwiKMJxGJngQ/5DrRapkQnLob8=
modernc.org/mathutil v1.0.0/go.mod h1:wU0vUrJsVWBZ4P6e7xtFJEhFSNsfRLJ8H458uRjg03k=
modernc.org/mathutil v1.1.1/go.mod h1:mZW8CKdRPY1v87qxC/wUdX5O1qDzXMP5TH3wjfpga6E=
modernc.org/mathutil v1.2.2 h1:+yFk8hBprV+4c0U9GjFtL+dV3N8hOJ8JCituQcMShFY=
modernc.org/mathutil v1.2.2/go.mod h1:mZW8CKdRPY1v87qxC/wUdX5O1qDzXMP5TH3wjfpga6E=
modernc.org/memory v1.0.4 h1:utMBrFcpnQDdNsmM6asmyH/FM9TqLPS7XF7otpJmrwM=
modernc.org/memory v1.0.4/go.mod h1:nV2OApxradM3/OVbs2/0OsP6nPfakXpi50C7dcoHXlc=
modernc.org/opt v0.1.1 h1:/0RX92k9vwVeDXj+Xn23DKp2VJubL7k8qNffND6qn3A=
modernc.org/opt v0.1.1/go.mod h1:WdSiB5evDcignE70guQKxYUl14mgWtbClRi5wmkkTX0=
modernc.org/ql v1.0.0/go.mod h1:xGVyrLIatPcO2C1JvI/Co8c0sr6y91HKFNy4pt9JXEY=
modernc.org/sortutil v1.1.0/go.mod h1:ZyL98OQHJgH9IEfN71VsamvJgrtRX9Dj2gX+vH86L1k=
modernc.org/sqlite v1.10.6 h1:iNDTQbULcm0IJAqrzCm2JcCqxaKRS94rJ5/clBMRmc8=
modernc.org/sqlite v1.10.6/go.mod h1:Z9FEjUtZP4qFEg6/SiADg9XCER7aYy9a/j7Pg9P7CPs=
modernc.org/strutil v1.1.0 h1:+1/yCzZxY2pZwwrsbH+4T7BQMoLQ9QiBshRC9eicYsc=
modernc.org/strutil v1.1.0/go.mod h1:lstksw84oURvj9y3tn8lGvRxyRC1S2+g5uuIzNfIOBs=
modernc.org/tcl v1.5.2 h1:sYNjGr4zK6cDH74USl8wVJRrvDX6UOLpG0j4lFvR0W0=
modernc.org/tcl v1.5.2/go.mod h1:pmJYOLgpiys3oI4AeAafkcUfE+TKKilminxNyU/+Zlo=
modernc.org/token v1.0.0 h1:a0jaWiNMDhDUtqOj09wvjWWAqd3q7WpBulmL9H2egsk=
modernc.org/token v1.0.0/go.mod h1:UGzOrNV1mAFSEB63lOFHIpNRUVMvYTc6yu1SMY/XTDM=
modernc.org/z v1.0.1-0.20210308123920-1f282aa71362/go.mod h1:8/SRk5C/HgiQWCgXdfpb+1RvhORdkz5sw72d3jjtyqA=
modernc.org/z v1.0.1 h1:WyIDpEpAIx4Hel6q/Pcgj/VhaQV5XPJ2I6ryIYbjnpc=
modernc.org/z v1.0.1/go.mod h1:8/SRk5C/HgiQWCgXdfpb+1RvhORdkz5sw72d3jjtyqA=
modernc.org/zappy v1.0.0/go.mod h1:hHe+oGahLVII/aTTyWK/b53VDHMAGCBYYeZ9sn83HC4=
rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8=
Expand Down
11 changes: 5 additions & 6 deletions pkg/common/http/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,26 @@ package http
import (
"errors"
"fmt"
"net/http"

"github.com/labstack/echo/v4"
)

// WriteResponse parses a struct into a json and writes in the response
func WriteResponse(ctx echo.Context, body interface{}) error {
func WriteResponse(ctx echo.Context, code int, body interface{}) error {
if body == nil {
return errors.New("body is required")
}

if err := ctx.JSON(http.StatusOK, body); err != nil {
if err := ctx.JSON(code, body); err != nil {
return fmt.Errorf("failed to write response body: %v", err)
}

return nil
}

// BodylessResponse wraps error echo body-less responses.
func BodylessResponse(ctx echo.Context) error {
if err := ctx.NoContent(http.StatusOK); err != nil {
// BodilessResponse wraps error echo body-less responses.
func BodilessResponse(ctx echo.Context, code int) error {
if err := ctx.NoContent(code); err != nil {
return fmt.Errorf("failed to respond without body: %v", err)
}

Expand Down
Loading