diff --git a/cmd/graphql/Dockerfile b/cmd/graphql/Dockerfile index 6a91aa24..907ed9f0 100644 --- a/cmd/graphql/Dockerfile +++ b/cmd/graphql/Dockerfile @@ -22,9 +22,9 @@ FROM node:18-bullseye-slim ENV DEBIAN_FRONTEND=noninteractive -RUN apt update && \ +RUN apt-get update && \ # curl for healthchecks - apt install -y dumb-init curl && \ + apt-get install -y dumb-init curl && \ rm -rf /var/lib/apt/lists/* COPY --from=build-stage /graphql/node_modules /opt/graphql/node_modules diff --git a/cmd/server/Dockerfile b/cmd/server/Dockerfile index e7431822..69b96626 100644 --- a/cmd/server/Dockerfile +++ b/cmd/server/Dockerfile @@ -1,8 +1,9 @@ # build server -FROM golang:1.19-alpine as server +FROM golang:1.21 as server LABEL org.opencontainers.image.source https://github.com/bhidapa/heltin -RUN apk --update --no-cache add git tzdata +RUN apt-get update && \ + apt-get install -y tzdata WORKDIR $GOPATH/src/github.com/bhidapa/heltin @@ -35,10 +36,12 @@ ARG VITE_APP_VER RUN VITE_APP_VER=$VITE_APP_VER yarn build # server -FROM alpine:3.16 +FROM debian:bookworm-slim # necessary for healthchecks -RUN apk --update --no-cache add curl +RUN apt-get update && \ + apt-get install -y dumb-init curl && \ + rm -rf /var/lib/apt/lists/* COPY --from=server /usr/share/zoneinfo /usr/share/zoneinfo COPY --from=server /heltin-server /usr/local/bin/ @@ -46,4 +49,4 @@ COPY --from=server /heltin-server /usr/local/bin/ ENV APP_DIR=/srv/app COPY --from=app /app/build $APP_DIR -ENTRYPOINT ["heltin-server"] +CMD ["dumb-init", "heltin-server"] diff --git a/cmd/server/routes/spa.go b/cmd/server/routes/spa.go index 01af182e..893b5b94 100644 --- a/cmd/server/routes/spa.go +++ b/cmd/server/routes/spa.go @@ -71,7 +71,7 @@ func (spa SPA) ServeHTTP(w http.ResponseWriter, r *http.Request) { } w.Header().Set("Content-Length", fmt.Sprintf("%d", file.Size())) - http.ServeContent(w, r, file.Name(), file.ModTime(), reader) + http.ServeContent(w, r, file.Name(), file.Modified(), reader) } func writeInternalServerError(err error, r *http.Request, w http.ResponseWriter) { diff --git a/database/Dockerfile b/database/Dockerfile index b282aa2a..bee765d5 100644 --- a/database/Dockerfile +++ b/database/Dockerfile @@ -1,11 +1,9 @@ -FROM postgres:15 +FROM postgres:16 LABEL org.opencontainers.image.source https://github.com/bhidapa/heltin -# update apt pkg sources -RUN apt-get update - # pgBackRest -RUN apt-get install -y \ +RUN apt-get update && \ + apt-get install -y \ # build deps curl make gcc libpq-dev libssl-dev libxml2-dev pkg-config liblz4-dev libzstd-dev libbz2-dev libz-dev libyaml-dev \ # runtime deps @@ -33,7 +31,7 @@ RUN rm -rf /tmp/pgbackrest-release && \ # clean apt cache and temporary files RUN apt-get autoremove -y && \ - apt-get clean all && rm -rf /var/lib/apt/lists/* + rm -rf /var/lib/apt/lists/* # configure pgBackRest COPY --chown=postgres:postgres database/pgbackrest.conf $PGBACKREST_CONFIG_PATH diff --git a/go.mod b/go.mod index 1a94d3d1..01915aea 100644 --- a/go.mod +++ b/go.mod @@ -6,40 +6,35 @@ toolchain go1.21.4 require ( github.com/caarlos0/env/v6 v6.10.1 - github.com/domonda/go-errs v0.0.0-20220803101145-9c94ff28df79 - github.com/domonda/go-function v0.0.0-20220906151352-005673c742aa - github.com/domonda/go-sqldb v0.0.0-20220918130832-1bd86f3554aa - github.com/domonda/go-types v0.0.0-20221016092716-7a5b9caf997d - github.com/domonda/golog v0.0.0-20221012120706-8a96ced761b1 - github.com/gorilla/handlers v1.5.1 - github.com/gorilla/mux v1.8.0 - github.com/joho/godotenv v1.4.0 - github.com/ungerik/go-fs v0.0.0-20220919212925-72a039a29894 - github.com/ungerik/go-httpx v0.0.0-20220112162338-087d2c80ef46 - github.com/ungerik/go-structflag v0.0.0-20220112163907-b66a14e91e9c - golang.org/x/crypto v0.0.0-20221012134737-56aed061732a + github.com/domonda/go-errs v0.0.0-20230920094343-6b122da4d22f + github.com/domonda/go-function v0.0.0-20231115235524-2c170e3fcc20 + github.com/domonda/go-sqldb v0.0.0-20231012085739-e042be066e6b + github.com/domonda/go-types v0.0.0-20231120112155-3673dfbdcad5 + github.com/domonda/golog v0.0.0-20231101095743-c0456b06ad1e + github.com/gorilla/handlers v1.5.2 + github.com/gorilla/mux v1.8.1 + github.com/joho/godotenv v1.5.1 + github.com/ungerik/go-fs v0.0.0-20231120113434-f4e3bcec9eeb + github.com/ungerik/go-httpx v0.0.0-20230622152103-7bb636597356 + golang.org/x/crypto v0.15.0 ) require ( - github.com/aymanbagabas/go-osc52 v1.2.1 // indirect + github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect github.com/domonda/go-encjson v0.0.0-20210830085227-1beee57a72d8 // indirect - github.com/domonda/go-pretty v0.0.0-20220317123925-dd9e6bef129a // indirect - github.com/fatih/color v1.13.0 // indirect - github.com/felixge/httpsnoop v1.0.3 // indirect + github.com/domonda/go-pretty v0.0.0-20230810130018-8920f571470a // indirect + github.com/felixge/httpsnoop v1.0.4 // indirect github.com/fsnotify/fsnotify v1.7.0 // indirect github.com/h2non/filetype v1.1.3 // indirect github.com/jinzhu/now v1.1.5 // indirect - github.com/lib/pq v1.10.7 // indirect + github.com/lib/pq v1.10.9 // indirect github.com/lucasb-eyer/go-colorful v1.2.0 // indirect - github.com/mattn/go-colorable v0.1.13 // indirect - github.com/mattn/go-isatty v0.0.16 // indirect - github.com/mattn/go-runewidth v0.0.14 // indirect - github.com/muesli/termenv v0.13.0 // indirect - github.com/ogier/pflag v0.0.1 // indirect - github.com/rivo/uniseg v0.4.2 // indirect - github.com/ungerik/go-reflection v0.0.0-20220113085621-6c5fc1f2694a // indirect - golang.org/x/exp v0.0.0-20221012211006-4de253d81b95 // indirect - golang.org/x/net v0.0.0-20221014081412-f15817d10f9b // indirect + github.com/mattn/go-isatty v0.0.20 // indirect + github.com/mattn/go-runewidth v0.0.15 // indirect + github.com/muesli/termenv v0.15.2 // indirect + github.com/rivo/uniseg v0.4.4 // indirect + github.com/ungerik/go-reflection v0.0.0-20230810134712-a63435f6bc7e // indirect + golang.org/x/net v0.18.0 // indirect golang.org/x/sys v0.14.0 // indirect - golang.org/x/text v0.3.8 // indirect + golang.org/x/text v0.14.0 // indirect ) diff --git a/go.sum b/go.sum index 6ad3dedc..f3a2d417 100644 --- a/go.sum +++ b/go.sum @@ -1,94 +1,68 @@ -github.com/aymanbagabas/go-osc52 v1.0.3/go.mod h1:zT8H+Rk4VSabYN90pWyugflM3ZhpTZNC7cASDfUCdT4= -github.com/aymanbagabas/go-osc52 v1.2.1 h1:q2sWUyDcozPLcLabEMd+a+7Ea2DitxZVN9hTxab9L4E= -github.com/aymanbagabas/go-osc52 v1.2.1/go.mod h1:zT8H+Rk4VSabYN90pWyugflM3ZhpTZNC7cASDfUCdT4= +github.com/aymanbagabas/go-osc52/v2 v2.0.1 h1:HwpRHbFMcZLEVr42D4p7XBqjyuxQH5SMiErDT4WkJ2k= +github.com/aymanbagabas/go-osc52/v2 v2.0.1/go.mod h1:uYgXzlJ7ZpABp8OJ+exZzJJhRNQ2ASbcXHWsFqH8hp8= github.com/caarlos0/env/v6 v6.10.1 h1:t1mPSxNpei6M5yAeu1qtRdPAK29Nbcf/n3G7x+b3/II= github.com/caarlos0/env/v6 v6.10.1/go.mod h1:hvp/ryKXKipEkcuYjs9mI4bBCg+UI0Yhgm5Zu0ddvwc= -github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/domonda/go-encjson v0.0.0-20210830085227-1beee57a72d8 h1:fKtb4cd3cTeioONoavHmcJ8R1zWbU3cVzt2pXHhYWOs= github.com/domonda/go-encjson v0.0.0-20210830085227-1beee57a72d8/go.mod h1:i9MgoQ+iTNvBGS63YftEDoNsr6dW6lAefUibkoCdMS4= -github.com/domonda/go-errs v0.0.0-20220803101145-9c94ff28df79 h1:fBQtqAIzfFx/pGWhcnask+x3OjOfJ/Io1ZY0qNEDtAQ= -github.com/domonda/go-errs v0.0.0-20220803101145-9c94ff28df79/go.mod h1:WvIoE59Dfs0hhB2GYSlwowlBr2WWGXf/F74bg6HWUpQ= -github.com/domonda/go-function v0.0.0-20220906151352-005673c742aa h1:x9HC63sUH6WhS5ZvUn4v05VcFuTXgFzfmI5EZ0g6y2Q= -github.com/domonda/go-function v0.0.0-20220906151352-005673c742aa/go.mod h1:FWeR6gYZ/scPnAr9FnWpzfaXWMQoWumwNFsVOBdX34o= -github.com/domonda/go-pretty v0.0.0-20220317123925-dd9e6bef129a h1:6/Is0KGl5Ot3E8ZLAgAFWYiSRdU+3t3jL38+5yIlCV4= -github.com/domonda/go-pretty v0.0.0-20220317123925-dd9e6bef129a/go.mod h1:3QkM8UJdyJMeKZiIo7hYzSkQBpRS3k0gOHw4ysyEIB4= -github.com/domonda/go-sqldb v0.0.0-20220918130832-1bd86f3554aa h1:xSpcCwqihTL97+ikVvZosgDLm2421JXfAjs6SuuanXw= -github.com/domonda/go-sqldb v0.0.0-20220918130832-1bd86f3554aa/go.mod h1:VtrKtTbBpKShtNOSCBMlhy4yBm2Gql7gQpnCPkHFTaE= -github.com/domonda/go-types v0.0.0-20221016092716-7a5b9caf997d h1:FtugC1+EXlJ8Xz94EpyRGWbV5ATVVpV469HEWgdU5xY= -github.com/domonda/go-types v0.0.0-20221016092716-7a5b9caf997d/go.mod h1:paPqgf6Ni6tv3JmT8r8DQ5iKopxf0IM8f93Ozi/qBfM= -github.com/domonda/golog v0.0.0-20221012120706-8a96ced761b1 h1:u2OrL6jLKps/hEwhv23Tkm3H/TsrM8+zEhz565qMg9Q= -github.com/domonda/golog v0.0.0-20221012120706-8a96ced761b1/go.mod h1:5JdcnBbIOP4dWpaLhlboseUthGya12qAmMtgbz6qQ88= -github.com/fatih/color v1.10.0/go.mod h1:ELkj/draVOlAH/xkhN6mQ50Qd0MPOk5AAr3maGEBuJM= -github.com/fatih/color v1.13.0 h1:8LOYc1KYPPmyKMuN8QV2DNRWNbLo6LZ0iLs8+mlH53w= -github.com/fatih/color v1.13.0/go.mod h1:kLAiJbzzSOZDVNGyDpeOxJ47H46qBXwg5ILebYFFOfk= -github.com/felixge/httpsnoop v1.0.1/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U= -github.com/felixge/httpsnoop v1.0.3 h1:s/nj+GCswXYzN5v2DpNMuMQYe+0DDwt5WVCU6CWBdXk= -github.com/felixge/httpsnoop v1.0.3/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U= +github.com/domonda/go-errs v0.0.0-20230920094343-6b122da4d22f h1:ECYzMHlxXTmVwOYKqAZf7wEri1QvMv7AX9u25zotV0k= +github.com/domonda/go-errs v0.0.0-20230920094343-6b122da4d22f/go.mod h1:DYkFE3rxUGhTCMmR5MpQ2NTtoCPiORdjBATGkIEeGKM= +github.com/domonda/go-function v0.0.0-20231115235524-2c170e3fcc20 h1:xD9VllVKDvxNBdVuv4+A81a+KXd6jynzwTn3Fzs3XJ0= +github.com/domonda/go-function v0.0.0-20231115235524-2c170e3fcc20/go.mod h1:bVkOqRKuO2v4+jfYt0tMSnFZwnijCAFzJ52yMLKW9lo= +github.com/domonda/go-pretty v0.0.0-20230810130018-8920f571470a h1:b3a6MwwMrHR9dw6585e3Ky51T50OKuD3fRuLyh8ziEw= +github.com/domonda/go-pretty v0.0.0-20230810130018-8920f571470a/go.mod h1:3QkM8UJdyJMeKZiIo7hYzSkQBpRS3k0gOHw4ysyEIB4= +github.com/domonda/go-sqldb v0.0.0-20231012085739-e042be066e6b h1:0pDN3Ig8vhyDxvQTwqy1zvjKnt+WMXlzMkT7GmegcSM= +github.com/domonda/go-sqldb v0.0.0-20231012085739-e042be066e6b/go.mod h1:hmJZJnG/gkGxGEn3IQj7cQQJss/XztT4hgkzW/1jOZ0= +github.com/domonda/go-types v0.0.0-20231120112155-3673dfbdcad5 h1:urnwi7TYNFS82AbxC3LRoz34jXQPRRbIPNksCkFmGj4= +github.com/domonda/go-types v0.0.0-20231120112155-3673dfbdcad5/go.mod h1:umVp8TN9LO4PA1rL3vW1c4DQAfXb4xB7xx/nXun0R3U= +github.com/domonda/golog v0.0.0-20231101095743-c0456b06ad1e h1:52ptNMYOZ07NtsVTtEj6oauuEdVF62N4m45pJgBBu48= +github.com/domonda/golog v0.0.0-20231101095743-c0456b06ad1e/go.mod h1:WYMrya9iiLebEGFCYSF6Iwpqi7Kpilk4s69vB46CHyU= +github.com/felixge/httpsnoop v1.0.4 h1:NFTV2Zj1bL4mc9sqWACXbQFVBBg2W3GPvqp8/ESS2Wg= +github.com/felixge/httpsnoop v1.0.4/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U= github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nosvA= github.com/fsnotify/fsnotify v1.7.0/go.mod h1:40Bi/Hjc2AVfZrqy+aj+yEI+/bRxZnMJyTJwOpGvigM= -github.com/gorilla/handlers v1.5.1 h1:9lRY6j8DEeeBT10CvO9hGW0gmky0BprnvDI5vfhUHH4= -github.com/gorilla/handlers v1.5.1/go.mod h1:t8XrUpc4KVXb7HGyJ4/cEnwQiaxrX/hz1Zv/4g96P1Q= -github.com/gorilla/mux v1.8.0 h1:i40aqfkR1h2SlN9hojwV5ZA91wcXFOvkdNIeFDP5koI= -github.com/gorilla/mux v1.8.0/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So= +github.com/gorilla/handlers v1.5.2 h1:cLTUSsNkgcwhgRqvCNmdbRWG0A3N4F+M2nWKdScwyEE= +github.com/gorilla/handlers v1.5.2/go.mod h1:dX+xVpaxdSw+q0Qek8SSsl3dfMk3jNddUkMzo0GtH0w= +github.com/gorilla/mux v1.8.1 h1:TuBL49tXwgrFYWhqrNgrUNEY92u81SPhu7sTdzQEiWY= +github.com/gorilla/mux v1.8.1/go.mod h1:AKf9I4AEqPTmMytcMc0KkNouC66V3BtZ4qD5fmWSiMQ= github.com/h2non/filetype v1.1.3 h1:FKkx9QbD7HR/zjK1Ia5XiBsq9zdLi5Kf3zGyFTAFkGg= github.com/h2non/filetype v1.1.3/go.mod h1:319b3zT68BvV+WRj7cwy856M2ehB3HqNOt6sy1HndBY= github.com/jinzhu/now v1.1.5 h1:/o9tlHleP7gOFmsnYNz3RGnqzefHA47wQpKrrdTIwXQ= github.com/jinzhu/now v1.1.5/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8= -github.com/joho/godotenv v1.4.0 h1:3l4+N6zfMWnkbPEXKng2o2/MR5mSwTrBih4ZEkkz1lg= -github.com/joho/godotenv v1.4.0/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4= -github.com/lib/pq v1.10.7 h1:p7ZhMD+KsSRozJr34udlUrhboJwWAgCg34+/ZZNvZZw= -github.com/lib/pq v1.10.7/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o= +github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0= +github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4= +github.com/lib/pq v1.10.9 h1:YXG7RB+JIjhP29X+OtkiDnYaXQwpS4JEWq7dtCCRUEw= +github.com/lib/pq v1.10.9/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o= github.com/lucasb-eyer/go-colorful v1.2.0 h1:1nnpGOrhyZZuNyfu1QjKiUICQ74+3FNCN69Aj6K7nkY= github.com/lucasb-eyer/go-colorful v1.2.0/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0= -github.com/mattn/go-colorable v0.1.8/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc= -github.com/mattn/go-colorable v0.1.9/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc= -github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA= -github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg= -github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU= -github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94= -github.com/mattn/go-isatty v0.0.16 h1:bq3VjFmv/sOjHtdEhmkEV4x1AJtvUvOJ2PFAZ5+peKQ= -github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= -github.com/mattn/go-runewidth v0.0.14 h1:+xnbZSEeDbOIg5/mE6JF0w6n9duR1l3/WmbinWVwUuU= -github.com/mattn/go-runewidth v0.0.14/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w= -github.com/muesli/termenv v0.13.0 h1:wK20DRpJdDX8b7Ek2QfhvqhRQFZ237RGRO0RQ/Iqdy0= -github.com/muesli/termenv v0.13.0/go.mod h1:sP1+uffeLaEYpyOTb8pLCUctGcGLnoFjSn4YJK5e2bc= -github.com/ogier/pflag v0.0.1 h1:RW6JSWSu/RkSatfcLtogGfFgpim5p7ARQ10ECk5O750= -github.com/ogier/pflag v0.0.1/go.mod h1:zkFki7tvTa0tafRvTBIZTvzYyAu6kQhPZFnshFFPE+g= +github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY= +github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= +github.com/mattn/go-runewidth v0.0.15 h1:UNAjwbU9l54TA3KzvqLGxwWjHmMgBUVhBiTjelZgg3U= +github.com/mattn/go-runewidth v0.0.15/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w= +github.com/muesli/termenv v0.15.2 h1:GohcuySI0QmI3wN8Ok9PtKGkgkFIk7y6Vpb5PvrY+Wo= +github.com/muesli/termenv v0.15.2/go.mod h1:Epx+iuz8sNs7mNKhxzH4fWXGNpZwUaJKRS1noLXviQ8= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= -github.com/rivo/uniseg v0.4.2 h1:YwD0ulJSJytLpiaWua0sBDusfsCZohxjxzVTYjwxfV8= -github.com/rivo/uniseg v0.4.2/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88= -github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PKk= -github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= -github.com/ungerik/go-fs v0.0.0-20220919212925-72a039a29894 h1:e5NeYftLpx8PRNVWFr0NaK1SG9Q0WGFuiIsBBaCZpQc= -github.com/ungerik/go-fs v0.0.0-20220919212925-72a039a29894/go.mod h1:wUC3EAgVFaw13gYxs+5LmCYEQoIkXCv5WOuqCFdlm5Y= -github.com/ungerik/go-httpx v0.0.0-20220112162338-087d2c80ef46 h1:z18o64QWm2jUoEjpw09Pyxv4G+YiOt5aLU2RJBdhEuQ= -github.com/ungerik/go-httpx v0.0.0-20220112162338-087d2c80ef46/go.mod h1:jZGOZsTnyKMALRUsGoggJ5tPAxjc346oIZHIVoosEtw= -github.com/ungerik/go-reflection v0.0.0-20191013094457-172d2e71715f/go.mod h1:LDLWYd30s6zcsOXmrd5TfrHctochNlzRBJPuAEhpnU8= -github.com/ungerik/go-reflection v0.0.0-20220113085621-6c5fc1f2694a h1:9vfYtqoyrPw08TbSLxkSXEflp6iXa3RL86Qjs+DrVas= -github.com/ungerik/go-reflection v0.0.0-20220113085621-6c5fc1f2694a/go.mod h1:6Hnd2/4g3Tpt6TjvxHx8wXOZziwApVxRdIGkr7vNpXs= -github.com/ungerik/go-structflag v0.0.0-20220112163907-b66a14e91e9c h1:PiBxdRhEApBzprqdIylt2Tx1ovKVxFu+VvU7symW2Kc= -github.com/ungerik/go-structflag v0.0.0-20220112163907-b66a14e91e9c/go.mod h1:zn4DRQ82O4y/qvO/7gQP62F2a12f2M7mDGxw+DAkKWc= -golang.org/x/crypto v0.0.0-20221012134737-56aed061732a h1:NmSIgad6KjE6VvHciPZuNRTKxGhlPfD6OA87W/PLkqg= -golang.org/x/crypto v0.0.0-20221012134737-56aed061732a/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= -golang.org/x/exp v0.0.0-20221012211006-4de253d81b95 h1:sBdrWpxhGDdTAYNqbgBLAR+ULAPPhfgncLr1X0lyWtg= -golang.org/x/exp v0.0.0-20221012211006-4de253d81b95/go.mod h1:cyybsKvd6eL0RnXn6p/Grxp8F5bW7iYuBgsNCOHpMYE= -golang.org/x/net v0.0.0-20221014081412-f15817d10f9b h1:tvrvnPFcdzp294diPnrdZZZ8XUt2Tyj7svb7X52iDuU= -golang.org/x/net v0.0.0-20221014081412-f15817d10f9b/go.mod h1:YDH+HFinaLZZlnHAfSS6ZXJJ9M9t4Dl22yv3iI2vPwk= -golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +github.com/rivo/uniseg v0.4.4 h1:8TfxU8dW6PdqD27gjM8MVNuicgxIjxpm4K7x4jp8sis= +github.com/rivo/uniseg v0.4.4/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88= +github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= +github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= +github.com/ungerik/go-fs v0.0.0-20231120113434-f4e3bcec9eeb h1:iJobM5eCeQqh6nqDoa/MtnXKLqKgDvsRrAckw+bVRzk= +github.com/ungerik/go-fs v0.0.0-20231120113434-f4e3bcec9eeb/go.mod h1:2RzyJL3rnCsReUsiHwNticoN7CQSiro27dBJjjqLFTs= +github.com/ungerik/go-httpx v0.0.0-20230622152103-7bb636597356 h1:vN8FIce+59qtRe/G1xiDioVF2EK1jTaxsCrPGjyK1iM= +github.com/ungerik/go-httpx v0.0.0-20230622152103-7bb636597356/go.mod h1:lmKZrbxy5ypCbOkFANz0TQWE4dw9EN0S2WKdAexBbZM= +github.com/ungerik/go-reflection v0.0.0-20230810134712-a63435f6bc7e h1:BPksMeVdgSD8L4yXHYSY3HpdJ/5z2Ok5lF6PxHIVgEQ= +github.com/ungerik/go-reflection v0.0.0-20230810134712-a63435f6bc7e/go.mod h1:1Q14POg/xa/P6/hWKfnUexqUhW1X6jgw+6gG7lOne1E= +golang.org/x/crypto v0.15.0 h1:frVn1TEaCEaZcn3Tmd7Y2b5KKPaZ+I32Q2OA3kYp5TA= +golang.org/x/crypto v0.15.0/go.mod h1:4ChreQoLWfG3xLDer1WdlH5NdlQ3+mwnQq1YTKY+72g= +golang.org/x/net v0.18.0 h1:mIYleuAkSbHh0tCv7RvjL3F6ZVbLjq4+R7zbOn3Kokg= +golang.org/x/net v0.18.0/go.mod h1:/czyP5RqHAH4odGYxBJ1qz0+CE5WZ+2j1YgoEo8F2jQ= +golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.14.0 h1:Vz7Qs629MkJkGyHxUlRHizWJRG2j8fbQKjELVSNhy7Q= golang.org/x/sys v0.14.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= -golang.org/x/text v0.3.8 h1:nAL+RVCQ9uMn3vJZbV+MRnydTJFPf8qqY42YiA6MrqY= -golang.org/x/text v0.3.8/go.mod h1:E6s5w1FMmriuDzIBO73fBruAKo1PCIq6d2Q6DHfQ8WQ= -gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ= +golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/pkg/file/download.go b/pkg/file/download.go index e4b03a8f..cc100552 100644 --- a/pkg/file/download.go +++ b/pkg/file/download.go @@ -56,7 +56,7 @@ func Download(w http.ResponseWriter, r *http.Request) { return } - fileData, err := fsfile.ReadAll(ctx) + fileData, err := fsfile.ReadAll() if err != nil { log.Error("Problem while reading file data").Request(r).Err(err).Log() httperr.New(http.StatusInternalServerError).ServeHTTP(w, r) diff --git a/pkg/reports/conclusion.go b/pkg/reports/conclusion.go index 2403a499..bf901508 100644 --- a/pkg/reports/conclusion.go +++ b/pkg/reports/conclusion.go @@ -34,9 +34,8 @@ func CreateForConclusion(ctx context.Context, conclusionID uu.ID) (fileID uu.ID, log.Info("Creating conclusion report").Log() - var pdfFile *fs.MemFile err = session.TransactionAsUserFromContext(ctx, func(ctx context.Context) error { - pdfFile, err = buildConclusionPDF(ctx, fileID, conclusionID) + pdfFile, err := buildConclusionPDF(ctx, fileID, conclusionID) if err != nil { return err } @@ -86,7 +85,7 @@ func CreateForConclusion(ctx context.Context, conclusionID uu.ID) (fileID uu.ID, //go:embed templates/conclusion.html var conclusionHtml []byte -func buildConclusionPDF(ctx context.Context, fileID, conclusionID uu.ID) (pdfFile *fs.MemFile, err error) { +func buildConclusionPDF(ctx context.Context, fileID, conclusionID uu.ID) (pdfFile fs.MemFile, err error) { conclusion := struct { // therapist shouldn't be null, but the user that created // the case study might not be a therapist @@ -130,11 +129,11 @@ func buildConclusionPDF(ctx context.Context, fileID, conclusionID uu.ID) (pdfFil where case_study_conclusion.id = $1`, conclusionID). ScanStruct(&conclusion) if err != nil { - return nil, err + return fs.MemFile{}, err } if conclusion.Description.IsNull() { - return nil, errors.New("description is required") + return fs.MemFile{}, errors.New("description is required") } conclusion.ClientDOB = conclusion.ClientDOBDate.Format("02.01.2006.") @@ -145,7 +144,7 @@ func buildConclusionPDF(ctx context.Context, fileID, conclusionID uu.ID) (pdfFil // TODO: use timezone from requester loc, err := time.LoadLocation("Europe/Sarajevo") if err != nil { - return nil, err + return fs.MemFile{}, err } createdAt := time.Now().UTC() @@ -165,17 +164,17 @@ func buildConclusionPDF(ctx context.Context, fileID, conclusionID uu.ID) (pdfFil headerHTML, err := render(headerHtml, data) if err != nil { - return nil, err + return fs.MemFile{}, err } indexHTML, err := render(conclusionHtml, data) if err != nil { - return nil, err + return fs.MemFile{}, err } footerHTML, err := render(footerHtml, data) if err != nil { - return nil, err + return fs.MemFile{}, err } pdfFileBytes, err := pdf.RenderHTML(ctx, &pdf.RenderHTMLArgs{ @@ -188,9 +187,10 @@ func buildConclusionPDF(ctx context.Context, fileID, conclusionID uu.ID) (pdfFil MarginLeft: 0.8, }) if err != nil { - return nil, err + return fs.MemFile{}, err } filename := "Report" + "_" + conclusion.ClientName + "_" + conclusion.Title + "_" + createdAt.In(loc).Format(time.RFC3339) + return fs.NewMemFile(strutil.SanitizeFileName(filename)+".pdf", pdfFileBytes), nil } diff --git a/pkg/reports/treatment.go b/pkg/reports/treatment.go index a26e116d..26d2cd00 100644 --- a/pkg/reports/treatment.go +++ b/pkg/reports/treatment.go @@ -32,9 +32,8 @@ func CreateForTreatment(ctx context.Context, treatmentID uu.ID) (fileID uu.ID, e log.Info("Creating treatment report").Log() - var pdfFile *fs.MemFile err = session.TransactionAsUserFromContext(ctx, func(ctx context.Context) error { - pdfFile, err = buildTreatmentPDF(ctx, fileID, treatmentID) + pdfFile, err := buildTreatmentPDF(ctx, fileID, treatmentID) if err != nil { return err } @@ -84,7 +83,7 @@ func CreateForTreatment(ctx context.Context, treatmentID uu.ID) (fileID uu.ID, e //go:embed templates/treatment.html var treatmentHtml []byte -func buildTreatmentPDF(ctx context.Context, fileID, treatmentID uu.ID) (pdfFile *fs.MemFile, err error) { +func buildTreatmentPDF(ctx context.Context, fileID, treatmentID uu.ID) (pdfFile fs.MemFile, err error) { treatment := struct { // therapist shouldn't be null, but the user that created // the case study might not be a mental health professional @@ -123,11 +122,11 @@ func buildTreatmentPDF(ctx context.Context, fileID, treatmentID uu.ID) (pdfFile where case_study_treatment.id = $1`, treatmentID). ScanStruct(&treatment) if err != nil { - return nil, err + return fs.MemFile{}, err } if treatment.Description.IsNull() { - return nil, errors.New("description is required") + return fs.MemFile{}, errors.New("description is required") } treatment.ClientDOB = treatment.ClientDOBDate.Format("02.01.2006.") @@ -135,7 +134,7 @@ func buildTreatmentPDF(ctx context.Context, fileID, treatmentID uu.ID) (pdfFile // TODO: use timezone from requester loc, err := time.LoadLocation("Europe/Sarajevo") if err != nil { - return nil, err + return fs.MemFile{}, err } createdAt := time.Now().UTC() @@ -154,17 +153,17 @@ func buildTreatmentPDF(ctx context.Context, fileID, treatmentID uu.ID) (pdfFile headerHTML, err := render(headerHtml, data) if err != nil { - return nil, err + return fs.MemFile{}, err } indexHTML, err := render(treatmentHtml, data) if err != nil { - return nil, err + return fs.MemFile{}, err } footerHTML, err := render(footerHtml, data) if err != nil { - return nil, err + return fs.MemFile{}, err } pdfFileBytes, err := pdf.RenderHTML(ctx, &pdf.RenderHTMLArgs{ @@ -177,7 +176,7 @@ func buildTreatmentPDF(ctx context.Context, fileID, treatmentID uu.ID) (pdfFile MarginLeft: 0.8, }) if err != nil { - return nil, err + return fs.MemFile{}, err } filename := "Report" + "_" + treatment.ClientName + "_" + treatment.Title + "_" + createdAt.In(loc).Format(time.RFC3339) diff --git a/pkg/session/session.go b/pkg/session/session.go index c73ea33e..e0d0fc27 100644 --- a/pkg/session/session.go +++ b/pkg/session/session.go @@ -30,7 +30,8 @@ func Handler(wrappedHandler http.Handler) http.HandlerFunc { } req = req.WithContext(ContextWithUser(req.Context(), userID.Get())) - req = golog.AddValueToRequest(req, golog.NewUUIDValue("userID", userID)) + + req = golog.RequestWithAttribs(req, golog.UUID{Key: "userID", Val: userID}) wrappedHandler.ServeHTTP(res, req) } @@ -46,7 +47,7 @@ func HandlerWithUserIDAsMuxVar(muxVarName string, wrappedHandler http.Handler) h mux.Vars(req)[muxVarName] = userID.String() - req = golog.AddValueToRequest(req, golog.NewUUIDValue("userID", userID)) + req = golog.RequestWithAttribs(req, golog.UUID{Key: "userID", Val: userID}) wrappedHandler.ServeHTTP(res, req) } diff --git a/pkg/session/user.go b/pkg/session/user.go index f0d24bc3..ad783d66 100644 --- a/pkg/session/user.go +++ b/pkg/session/user.go @@ -6,7 +6,6 @@ import ( "errors" "fmt" - "github.com/domonda/go-errs" "github.com/domonda/go-sqldb/db" "github.com/domonda/go-types/uu" ) @@ -37,7 +36,7 @@ func TransactionAsUser(ctx context.Context, userID uu.ID, txFunc func(ctx contex if !errors.Is(err, sql.ErrTxDone) { // for when this transaction is within another one e := db.Conn(ctx).Exec("reset session.user_id; reset role;") - err = errs.Combine(err, e) + err = errors.Join(err, e) } }() return txFunc(ctx)