Skip to content

Commit 44b5770

Browse files
authored
Update dependencies (#322)
* Update npm deps * Fix errors from new deps * Update copyright * Small tweak * Remove unecessary extension * Update go deps, go, and node versions * Update node and go versions * New generator version * Move to config * Regenerate on config file change * Make file cleanup * Fixed windows build
1 parent 8188da7 commit 44b5770

27 files changed

+10974
-515
lines changed

.devcontainer/devcontainer.json

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
"context": "..",
77
"dockerfile": "Dockerfile",
88
"args": {
9-
"GO_VERSION": "1.16",
10-
"NODE_VERSION": "14",
11-
"DEVCONTAINER_VERSION": "0.205.2"
9+
"GO_VERSION": "1.18",
10+
"NODE_VERSION": "16",
11+
"DEVCONTAINER_VERSION": "0.238.0"
1212
}
1313
},
1414
"extensions": [
@@ -21,7 +21,6 @@
2121
"eg2.vscode-npm-script",
2222
"formulahendry.auto-rename-tag",
2323
"golang.go",
24-
"justinribeiro.polymer2snippets",
2524
"ms-azuretools.vscode-docker",
2625
"redhat.vscode-yaml",
2726
"spmeesseman.vscode-taskexplorer",

.github/workflows/ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ jobs:
1414
- uses: actions/checkout@v2
1515
- uses: actions/setup-node@v2
1616
with:
17-
node-version: "14"
17+
node-version: "16"
1818
- uses: actions/setup-go@v2
1919
with:
20-
go-version: "^1.16.0"
20+
go-version: "^1.18.0"
2121
- uses: docker/setup-buildx-action@v1
2222
- uses: docker/setup-qemu-action@v1
2323
with:

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,6 @@ _testmain.go
4545

4646
# Ignore generated files
4747
generated/
48+
49+
# Logs
50+
*.log

LICENSE

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Copyright (c) 2016 Chad Weimer
1+
Copyright (c) 2016-2022 Chad Weimer
22

33
Permission is hereby granted, free of charge, to any person obtaining a copy
44
of this software and associated documentation files (the "Software"), to deal
@@ -16,4 +16,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
1616
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
1717
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
1818
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19-
SOFTWARE.
19+
SOFTWARE.

Makefile

Lines changed: 37 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ CODEGEN_DIR=generated
1515
CLIENT_CODEGEN_DIR=static/src/generated
1616

1717
GO_VERSION_FLAGS=-X 'github.com/chadweimer/gomp/metadata.BuildVersion=$(BUILD_VERSION)'
18-
GO_LIN_LD_FLAGS=-ldflags "$(GO_VERSION_FLAGS) -extldflags '-static -static-libgcc'"
18+
GO_LD_FLAGS=-ldflags "$(GO_VERSION_FLAGS) -extldflags '-static -static-libgcc'"
1919
GO_WIN_LD_FLAGS=-ldflags "$(GO_VERSION_FLAGS)"
2020
GO_ENV_LIN_AMD64=GOOS=linux GOARCH=amd64 CGO_ENABLED=1
2121
GO_ENV_LIN_ARM=GOOS=linux GOARCH=arm CGO_ENABLED=1 CC=arm-linux-gnueabihf-gcc
@@ -25,14 +25,15 @@ GO_ENV_WIN_AMD64=GOOS=windows GOARCH=amd64 CGO_ENABLED=1 CC=x86_64-w64-mingw32-g
2525
GO_FILES := $(filter-out $(shell test -d $(CODEGEN_DIR) && find ./$(CODEGEN_DIR) -name "*"), $(shell find . -type f -name "*.go"))
2626
DB_MIGRATION_FILES := $(shell find db/migrations -type f -name "*.*")
2727
CLIENT_FILES := $(filter-out $(shell test -d $(CLIENT_CODEGEN_DIR) && find $(CLIENT_CODEGEN_DIR) -name "*"), $(shell find static -maxdepth 1 -type f -name "*") $(shell find static/src -type f -name "*"))
28+
OAPI_CFGS := $(shell find oapi-codegen -type f -name "*.yaml")
2829

2930
.DEFAULT_GOAL := build
3031

3132
# ---- INSTALL ----
3233

3334
.PHONY: install
3435
install: $(CLIENT_INSTALL_DIR)
35-
go install github.com/deepmap/oapi-codegen/cmd/oapi-codegen@latest
36+
go install github.com/deepmap/oapi-codegen/cmd/oapi-codegen@v1.11.0
3637

3738
$(CLIENT_INSTALL_DIR): static/package.json
3839
cd static && npm install --silent
@@ -46,20 +47,20 @@ uninstall:
4647
$(CLIENT_CODEGEN_DIR): $(CLIENT_INSTALL_DIR) openapi.yaml models.yaml
4748
cd static && npm run codegen
4849

49-
$(CODEGEN_DIR): openapi.yaml models.yaml
50+
$(CODEGEN_DIR): openapi.yaml models.yaml $(OAPI_CFGS)
5051
rm -rf $@
5152
mkdir -p $@/models
52-
oapi-codegen -generate types,skip-prune -package models models.yaml > $@/models/models.go
53+
oapi-codegen --config oapi-codegen/models.yaml models.yaml > $@/models/models.go
5354
mkdir -p $@/api/public
54-
oapi-codegen -generate types,chi-server -package public -include-tags=public -import-mapping=./models.yaml:github.com/chadweimer/gomp/generated/models openapi.yaml > $@/api/public/public.go
55+
oapi-codegen --config oapi-codegen/public.yaml openapi.yaml > $@/api/public/public.go
5556
mkdir -p $@/api/viewer
56-
oapi-codegen -generate types,chi-server -package viewer -include-tags=viewer -import-mapping=./models.yaml:github.com/chadweimer/gomp/generated/models openapi.yaml > $@/api/viewer/viewer.go
57+
oapi-codegen --config oapi-codegen/viewer.yaml openapi.yaml > $@/api/viewer/viewer.go
5758
mkdir -p $@/api/editor
58-
oapi-codegen -generate types,chi-server -package editor -include-tags=editor -import-mapping=./models.yaml:github.com/chadweimer/gomp/generated/models openapi.yaml > $@/api/editor/editor.go
59+
oapi-codegen --config oapi-codegen/editor.yaml openapi.yaml > $@/api/editor/editor.go
5960
mkdir -p $@/api/admin
60-
oapi-codegen -generate types,chi-server -package admin -include-tags=admin -import-mapping=./models.yaml:github.com/chadweimer/gomp/generated/models openapi.yaml > $@/api/admin/admin.go
61+
oapi-codegen --config oapi-codegen/admin.yaml openapi.yaml > $@/api/admin/admin.go
6162
mkdir -p $@/api/adminOrSelf
62-
oapi-codegen -generate types,chi-server -package adminOrSelf -include-tags=adminOrSelf -import-mapping=./models.yaml:github.com/chadweimer/gomp/generated/models openapi.yaml > $@/api/adminOrSelf/adminOrSelf.go
63+
oapi-codegen --config oapi-codegen/adminOrSelf.yaml openapi.yaml > $@/api/adminOrSelf/adminOrSelf.go
6364

6465

6566
# ---- LINT ----
@@ -85,6 +86,7 @@ build: $(BUILD_LIN_AMD64_DIR) $(BUILD_LIN_ARM_DIR) $(BUILD_LIN_ARM64_DIR) $(BUIL
8586
clean: clean-linux-amd64 clean-linux-arm clean-linux-arm64 clean-windows-amd64
8687
rm -rf $(BUILD_DIR)
8788
rm -rf $(CODEGEN_DIR)
89+
cd static && npm run clean
8890

8991
# - GENERIC ARCH -
9092

@@ -97,61 +99,60 @@ $(BUILD_DIR)/%/db/migrations: $(DB_MIGRATION_FILES)
9799
$(BUILD_DIR)/%/static: $(CLIENT_BUILD_DIR)
98100
rm -rf $@ && mkdir -p $@ && cp -R $</* $@
99101

100-
.PHONY: clean-client
101-
clean-client:
102-
cd static && npm run clean
102+
$(BUILD_DIR)/linux/%/gomp: go.mod $(CODEGEN_DIR) $(GO_FILES)
103+
$(GO_ENV) go build -o $@ $(GO_LD_FLAGS)
104+
$(BUILD_DIR)/windows/%/gomp.exe: go.mod $(CODEGEN_DIR) $(GO_FILES)
105+
$(GO_ENV) go build -o $@ $(GO_WIN_LD_FLAGS)
106+
107+
.PHONY: clean-$(BUILD_DIR)/%
108+
clean-$(BUILD_DIR)/%:
109+
rm -rf $(BUILD_DIR)/$*
110+
111+
.PHONY: clean-$(BUILD_DIR)/linux/%/gomp clean-$(BUILD_DIR)/windows/%/gomp.exe
112+
clean-$(BUILD_DIR)/linux/%/gomp:
113+
$(GO_ENV) go clean -i ./...
114+
clean-$(BUILD_DIR)/windows/%/gomp.exe:
115+
$(GO_ENV) go clean -i ./...
103116

104117
# - AMD64 -
105118

106119
$(BUILD_LIN_AMD64_DIR): $(BUILD_LIN_AMD64_DIR)/gomp $(BUILD_LIN_AMD64_DIR)/db/migrations $(BUILD_LIN_AMD64_DIR)/static
107120

108-
$(BUILD_LIN_AMD64_DIR)/gomp: go.mod $(CODEGEN_DIR) $(GO_FILES)
109-
$(GO_ENV_LIN_AMD64) go build -o $@ $(GO_LIN_LD_FLAGS)
121+
$(BUILD_LIN_AMD64_DIR)/gomp: GO_ENV := $(GO_ENV_LIN_AMD64)
110122

111123
.PHONY: clean-linux-amd64
112-
clean-linux-amd64: clean-client
113-
$(GO_ENV_LIN_AMD64) go clean -i ./...
114-
rm -rf $(BUILD_LIN_AMD64_DIR)
115-
rm -f $(BUILD_DIR)/gomp-linux-amd64.tar.gz
124+
clean-linux-amd64: GO_ENV := $(GO_ENV_LIN_AMD64)
125+
clean-linux-amd64: clean-$(BUILD_LIN_AMD64_DIR)/gomp clean-$(BUILD_LIN_AMD64_DIR) clean-$(BUILD_DIR)/gomp-linux-amd64.tar.gz
116126

117127
# - ARM32 -
118128

119129
$(BUILD_LIN_ARM_DIR): $(BUILD_LIN_ARM_DIR)/gomp $(BUILD_LIN_ARM_DIR)/db/migrations $(BUILD_LIN_ARM_DIR)/static
120130

121-
$(BUILD_LIN_ARM_DIR)/gomp: go.mod $(CODEGEN_DIR) $(GO_FILES)
122-
$(GO_ENV_LIN_ARM) go build -o $@ $(GO_LIN_LD_FLAGS)
131+
$(BUILD_LIN_ARM_DIR)/gomp: GO_ENV := $(GO_ENV_LIN_ARM)
123132

124133
.PHONY: clean-linux-arm
125-
clean-linux-arm: clean-client
126-
$(GO_ENV_LIN_ARM) go clean -i ./...
127-
rm -rf $(BUILD_LIN_ARM_DIR)
128-
rm -f $(BUILD_DIR)/gomp-linux-arm.tar.gz
134+
clean-linux-arm: GO_ENV := $(GO_ENV_LIN_ARM)
135+
clean-linux-arm: clean-$(BUILD_LIN_ARM_DIR)/gomp clean-$(BUILD_LIN_ARM_DIR) clean-$(BUILD_DIR)/gomp-linux-arm.tar.gz
129136

130137
# - ARM64 -
131138

132139
$(BUILD_LIN_ARM64_DIR): $(BUILD_LIN_ARM64_DIR)/gomp $(BUILD_LIN_ARM64_DIR)/db/migrations $(BUILD_LIN_ARM64_DIR)/static
133140

134-
$(BUILD_LIN_ARM64_DIR)/gomp: go.mod $(CODEGEN_DIR) $(GO_FILES)
135-
$(GO_ENV_LIN_ARM64) go build -o $@ $(GO_LIN_LD_FLAGS)
141+
$(BUILD_LIN_ARM64_DIR)/gomp: GO_ENV := $(GO_ENV_LIN_ARM64)
136142

137143
.PHONY: clean-linux-arm64
138-
clean-linux-arm64: clean-client
139-
$(GO_ENV_LIN_ARM64) go clean -i ./...
140-
rm -rf $(BUILD_LIN_ARM64_DIR)
141-
rm -f $(BUILD_DIR)/gomp-linux-arm64.tar.gz
144+
clean-linux-arm64: GO_ENV := $(GO_ENV_LIN_ARM64)
145+
clean-linux-arm64: clean-$(BUILD_LIN_ARM64_DIR)/gomp clean-$(BUILD_LIN_ARM64_DIR) clean-$(BUILD_DIR)/gomp-linux-arm64.tar.gz
142146

143147
# - WINDOWS -
144148

145149
$(BUILD_WIN_AMD64_DIR): $(BUILD_WIN_AMD64_DIR)/gomp.exe $(BUILD_WIN_AMD64_DIR)/db/migrations $(BUILD_WIN_AMD64_DIR)/static
146150

147-
$(BUILD_WIN_AMD64_DIR)/gomp.exe: go.mod $(CODEGEN_DIR) $(GO_FILES)
148-
$(GO_ENV_WIN_AMD64) go build -o $@ $(GO_WIN_LD_FLAGS)
151+
$(BUILD_WIN_AMD64_DIR)/gomp.exe: GO_ENV := $(GO_ENV_WIN_AMD64)
149152

150153
.PHONY: clean-windows-amd64
151-
clean-windows-amd64: clean-client
152-
$(GO_ENV_WIN_AMD64) go clean -i ./...
153-
rm -rf $(BUILD_WIN_AMD64_DIR)
154-
rm -f $(BUILD_DIR)/gomp-windows-amd64.zip
154+
clean-windows-amd64: GO_ENV := $(GO_ENV_WIN_AMD64)
155+
clean-windows-amd64: clean-$(BUILD_WIN_AMD64_DIR)/gomp.exe clean-$(BUILD_WIN_AMD64_DIR) clean-$(BUILD_DIR)/gomp-windows-amd64.zip
155156

156157

157158
# ---- DOCKER ----

api/app.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010

1111
func (h apiHandler) GetInfo(resp http.ResponseWriter, req *http.Request) {
1212
info := models.AppInfo{
13-
Version: metadata.BuildVersion,
13+
Version: &metadata.BuildVersion,
1414
}
1515

1616
h.OK(resp, info)

api/authentication.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ func (h apiHandler) verifyUserExists(userId int64) (*models.User, error) {
186186

187187
func (h apiHandler) verifyUserIsAdmin(req *http.Request) error {
188188
accessLevel := req.Context().Value(currentUserAccessLevelCtxKey).(models.AccessLevel)
189-
if accessLevel != models.AccessLevelAdmin {
189+
if accessLevel != models.Admin {
190190
return fmt.Errorf("endpoint '%s' requires admin rights", req.URL.Path)
191191
}
192192

@@ -195,7 +195,7 @@ func (h apiHandler) verifyUserIsAdmin(req *http.Request) error {
195195

196196
func (h apiHandler) verifyUserIsEditor(req *http.Request) error {
197197
accessLevel := req.Context().Value(currentUserAccessLevelCtxKey).(models.AccessLevel)
198-
if accessLevel != models.AccessLevelAdmin && accessLevel != models.AccessLevelEditor {
198+
if accessLevel != models.Admin && accessLevel != models.Editor {
199199
return fmt.Errorf("endpoint '%s' requires edit rights", req.URL.Path)
200200
}
201201

api/images.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ func (h apiHandler) SetMainImage(resp http.ResponseWriter, req *http.Request, re
4343
return
4444
}
4545

46-
image := models.RecipeImage{Id: &imageId, RecipeId: recipeId}
46+
image := models.RecipeImage{Id: &imageId, RecipeId: &recipeId}
4747
if err := h.db.Images().UpdateMainImage(&image); err != nil {
4848
h.Error(resp, http.StatusInternalServerError, err)
4949
return
@@ -80,10 +80,10 @@ func (h apiHandler) UploadImage(resp http.ResponseWriter, req *http.Request, rec
8080
}
8181

8282
imageInfo := models.RecipeImage{
83-
RecipeId: recipeId,
84-
Name: imageName,
85-
Url: url,
86-
ThumbnailUrl: thumbUrl,
83+
RecipeId: &recipeId,
84+
Name: &imageName,
85+
Url: &url,
86+
ThumbnailUrl: &thumbUrl,
8787
}
8888

8989
// Now insert the record in the database
@@ -113,7 +113,7 @@ func (h apiHandler) DeleteImage(resp http.ResponseWriter, req *http.Request, rec
113113
}
114114

115115
// And lastly delete the image file itself
116-
if err := upload.Delete(h.upl, image.RecipeId, image.Name); err != nil {
116+
if err := upload.Delete(h.upl, *image.RecipeId, *image.Name); err != nil {
117117
fullErr := fmt.Errorf("failed to delete image file: %v", err)
118118
h.Error(resp, http.StatusInternalServerError, fullErr)
119119
return

api/recipes.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@ func (h apiHandler) Find(resp http.ResponseWriter, req *http.Request, params vie
2929
var withPictures *bool
3030
if params.Pictures != nil {
3131
switch *params.Pictures {
32-
case viewer.YesNoAnyYes:
32+
case viewer.Yes:
3333
val := true
3434
withPictures = &val
35-
case viewer.YesNoAnyNo:
35+
case viewer.No:
3636
val := false
3737
withPictures = &val
3838
}

db/image-postgres.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,5 @@ func (d *postgresRecipeImageDriver) createtx(image *models.RecipeImage, tx *sqlx
2626
}
2727

2828
// Switch to a new main image if necessary, since this might be the first image attached
29-
return d.setMainImageIfNecessary(image.RecipeId, tx)
29+
return d.setMainImageIfNecessary(*image.RecipeId, tx)
3030
}

db/image-sql.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ func (d *sqlRecipeImageDriver) Createtx(image *models.RecipeImage, tx *sqlx.Tx)
3030
image.Id = &imageId
3131

3232
// Switch to a new main image if necessary, since this might be the first image attached
33-
return d.setMainImageIfNecessary(image.RecipeId, tx)
33+
return d.setMainImageIfNecessary(*image.RecipeId, tx)
3434
}
3535

3636
func (d *sqlRecipeImageDriver) Read(id int64) (*models.RecipeImage, error) {
@@ -110,7 +110,7 @@ func (d *sqlRecipeImageDriver) deletetx(id int64, tx *sqlx.Tx) error {
110110
}
111111

112112
// Switch to a new main image if necessary, since the image we just deleted may have been the main image
113-
return d.setMainImageIfNecessary(image.RecipeId, tx)
113+
return d.setMainImageIfNecessary(*image.RecipeId, tx)
114114
}
115115

116116
func (d *sqlRecipeImageDriver) setMainImageIfNecessary(recipeId int64, tx *sqlx.Tx) error {

db/recipe-postgres.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ func (d *postgresRecipeDriver) Find(filter *models.SearchFilter, page int64, cou
176176
default:
177177
orderStmt += "r.name"
178178
}
179-
if filter.SortDir == models.SortDirDesc {
179+
if filter.SortDir == models.Desc {
180180
orderStmt += " DESC"
181181
}
182182
// Need a special case for rating, since the way the execution plan works can

db/recipe-sqlite.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ func (d *sqliteRecipeDriver) Find(filter *models.SearchFilter, page int64, count
178178
default:
179179
orderStmt += "r.name"
180180
}
181-
if filter.SortDir == models.SortDirDesc {
181+
if filter.SortDir == models.Desc {
182182
orderStmt += " DESC"
183183
}
184184
// Need a special case for rating, since the way the execution plan works can

go.mod

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,25 @@
11
module github.com/chadweimer/gomp
22

33
require (
4-
github.com/aws/aws-sdk-go v1.41.4
5-
github.com/deepmap/oapi-codegen v1.8.3
4+
github.com/aws/aws-sdk-go v1.44.28
5+
github.com/deepmap/oapi-codegen v1.11.0
66
github.com/disintegration/imaging v1.6.2
7-
github.com/go-chi/chi/v5 v5.0.4
8-
github.com/golang-jwt/jwt/v4 v4.1.0
9-
github.com/golang-migrate/migrate/v4 v4.15.1
7+
github.com/go-chi/chi/v5 v5.0.7
8+
github.com/golang-jwt/jwt/v4 v4.4.1
9+
github.com/golang-migrate/migrate/v4 v4.15.2
1010
github.com/google/uuid v1.3.0
11+
github.com/jmoiron/sqlx v1.3.5
12+
github.com/lib/pq v1.10.6
13+
github.com/mattn/go-sqlite3 v1.14.13
14+
golang.org/x/crypto v0.0.0-20220525230936-793ad666bf5e
15+
)
16+
17+
require (
1118
github.com/hashicorp/errwrap v1.1.0 // indirect
1219
github.com/hashicorp/go-multierror v1.1.1 // indirect
13-
github.com/jmoiron/sqlx v1.3.4
14-
github.com/lib/pq v1.10.3
15-
github.com/mattn/go-sqlite3 v1.14.8
20+
github.com/jmespath/go-jmespath v0.4.0 // indirect
1621
go.uber.org/atomic v1.9.0 // indirect
17-
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519
18-
golang.org/x/image v0.0.0-20210628002857-a66eb6448b8d // indirect
19-
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
22+
golang.org/x/image v0.0.0-20220601225756-64ec528b34cd // indirect
2023
)
2124

22-
go 1.16
25+
go 1.18

0 commit comments

Comments
 (0)