Skip to content

Commit 8617985

Browse files
authored
Merge pull request #2 from jsightapi/task/SERV-83
Make gogetable
2 parents 3f332dd + 99ccf44 commit 8617985

File tree

283 files changed

+44933
-42
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

283 files changed

+44933
-42
lines changed

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,3 @@
22
*.iml
33
.env
44
/jsight-server
5-

.golangci.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ linters-settings:
3636
gocyclo:
3737
min-complexity: 15
3838
goimports:
39-
local-prefixes: github.com/golangci/golangci-lint
39+
local-prefixes: github.com/jsightapi/jsight-server
4040
gomnd:
4141
# List of enabled checks, see https://github.com/tommy-muehle/go-mnd/#checks for description.
4242
checks:
@@ -98,7 +98,7 @@ linters:
9898
- gocritic
9999
- gocyclo
100100
- gofmt
101-
# - goimports
101+
- goimports
102102
- gomnd
103103
- goprintffuncname
104104
- gosec
@@ -156,4 +156,4 @@ run:
156156
- test/testdata_etc
157157
- internal/cache
158158
- internal/renameio
159-
- internal/robustio
159+
- internal/robustio

Dockerfile

Lines changed: 4 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,14 @@
11
FROM golang:1.17-alpine as builder
22

3-
RUN apk add --no-cache git
4-
ARG GITHUB_TOKEN
5-
# Install jschema library dependency
6-
ARG JSCHEMA_BRANCH
7-
WORKDIR /go/src/j/schema
8-
RUN git clone -b ${JSCHEMA_BRANCH} --depth 1 \
9-
https://${GITHUB_TOKEN}@github.com/jsightapi/jsight-schema-go-library.git . \
10-
&& git branch --show-current \
11-
&& git show -s
12-
13-
# Install japi library dependency
14-
ARG JAPI_BRANCH
15-
WORKDIR /go/src/j/japi
16-
RUN git clone -b ${JAPI_BRANCH} --depth 1 \
17-
https://${GITHUB_TOKEN}@github.com/jsightapi/jsight-api-go-library.git . \
18-
&& git branch --show-current \
19-
&& git show -s
20-
21-
# build
22-
WORKDIR /go/src/j/server
3+
WORKDIR /go/src/github.com/jsightapi/jsight-server
234
COPY . .
24-
RUN GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -o jsight-server .
25-
5+
RUN GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -o /go/bin/jsight-server .
266

27-
FROM alpine
7+
FROM scratch
288
ARG CORS
299
ARG STATISTICS
3010
ENV JSIGHT_SERVER_CORS=$CORS
3111
ENV JSIGHT_SERVER_STATISTICS=$STATISTICS
32-
COPY --from=builder /go/src/j/server/jsight-server .
12+
COPY --from=builder /go/bin/jsight-server .
3313
EXPOSE 8080
3414
CMD [ "/jsight-server" ]

Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ fmt:
99
lint:
1010
golangci-lint run
1111

12+
.PHONY: test
13+
test:
14+
go test -cover ./...
15+
1216
.PHONY: build
1317
build:
1418
go build -o jsight-server .

cors.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package main
22

3-
import "net/http"
3+
import (
4+
"net/http"
5+
)
46

57
func cors(w http.ResponseWriter) {
68
w.Header().Set("Access-Control-Allow-Origin", "*")

cors_test.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package main
2+
3+
import (
4+
"net/http"
5+
"net/http/httptest"
6+
"testing"
7+
8+
"github.com/stretchr/testify/assert"
9+
)
10+
11+
func Test_cors(t *testing.T) {
12+
t.Run("positive", func(t *testing.T) {
13+
r := httptest.NewRecorder()
14+
15+
cors(r)
16+
17+
assert.Equal(t, http.StatusOK, r.Code)
18+
assert.Len(t, r.Header(), 3)
19+
assert.Equal(t, "*", r.Header().Get("Access-Control-Allow-Origin"))
20+
assert.Equal(t, "POST, GET, OPTIONS, PUT, DELETE", r.Header().Get("Access-Control-Allow-Methods"))
21+
assert.Equal(t, "Accept, Content-Type, Content-Length, Accept-Encoding, X-CSRF-Token, Authorization, X-Browser-UUID", r.Header().Get("Access-Control-Allow-Headers")) //nolint:lll
22+
})
23+
24+
t.Run("negative", func(t *testing.T) {
25+
assert.Panics(t, func() {
26+
cors(nil)
27+
})
28+
})
29+
}

env_test.go

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package main
2+
3+
import (
4+
"os"
5+
"testing"
6+
7+
"github.com/stretchr/testify/assert"
8+
"github.com/stretchr/testify/require"
9+
)
10+
11+
func Test_getBoolEnv(t *testing.T) {
12+
const env = "JSIGHT_GET_BOOL_ENV_TEST"
13+
14+
cc := map[string]bool{
15+
"": false,
16+
"invalid": false,
17+
"false": false,
18+
"true": true,
19+
"True": true,
20+
"TRUE": true,
21+
"1": true,
22+
"t": true,
23+
}
24+
25+
for given, expected := range cc {
26+
t.Run(given, func(t *testing.T) {
27+
require.NoError(t, os.Setenv(env, given))
28+
29+
assert.Equal(t, expected, getBoolEnv(env))
30+
})
31+
}
32+
33+
require.NoError(t, os.Unsetenv(env))
34+
}

error_info.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ package main
22

33
import (
44
"errors"
5-
"j/japi/jerr"
5+
6+
"github.com/jsightapi/jsight-api-go-library/jerr"
67
)
78

89
type errorInfo struct {

error_info_test.go

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package main
2+
3+
import (
4+
"errors"
5+
"testing"
6+
7+
"github.com/jsightapi/jsight-api-go-library/jerr"
8+
"github.com/jsightapi/jsight-schema-go-library/fs"
9+
"github.com/stretchr/testify/assert"
10+
)
11+
12+
func Test_newErrorInfo(t *testing.T) {
13+
t.Run("positive", func(t *testing.T) {
14+
cc := map[string]struct {
15+
given error
16+
expected errorInfo
17+
}{
18+
"ordinal error": {
19+
errors.New("fake error"),
20+
errorInfo{
21+
Status: "Error",
22+
Message: "fake error",
23+
},
24+
},
25+
26+
"JAPI error": {
27+
jerr.NewJAPIError("fake error", fs.NewFile("foo", []byte("123")), 2),
28+
errorInfo{
29+
Status: "Error",
30+
Message: "fake error",
31+
Line: 1,
32+
Index: 2,
33+
},
34+
},
35+
}
36+
37+
for n, c := range cc {
38+
t.Run(n, func(t *testing.T) {
39+
actual := newErrorInfo(c.given)
40+
assert.Equal(t, c.expected, actual)
41+
})
42+
}
43+
})
44+
45+
t.Run("negative", func(t *testing.T) {
46+
assert.Panics(t, func() {
47+
newErrorInfo(nil)
48+
})
49+
})
50+
}

go.mod

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
1-
module j/server
1+
module github.com/jsightapi/jsight-server
22

33
go 1.17
44

5-
replace j/japi => ./../japi
6-
7-
replace j/schema => ./../schema
8-
9-
require j/japi v0.0.0-00010101000000-000000000000
5+
require (
6+
github.com/jsightapi/jsight-api-go-library v0.3.1-0.20220427155423-7c489a57b5aa
7+
github.com/jsightapi/jsight-schema-go-library v0.0.0-20220426180928-6a830af498a5
8+
github.com/stretchr/testify v1.7.0
9+
)
1010

1111
require (
12+
github.com/davecgh/go-spew v1.1.0 // indirect
1213
github.com/lucasjones/reggen v0.0.0-20200904144131-37ba4fa293bb // indirect
13-
j/schema v0.0.0-00010101000000-000000000000 // indirect
14+
github.com/pmezard/go-difflib v1.0.0 // indirect
15+
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c // indirect
1416
)

0 commit comments

Comments
 (0)