Skip to content

Commit 9d777c2

Browse files
Update Readme and custom dir env variable (#6)
1 parent 4edfade commit 9d777c2

File tree

7 files changed

+91
-70
lines changed

7 files changed

+91
-70
lines changed

.github/workflows/go.yaml

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,22 @@ jobs:
2424
run: |
2525
go test ./...
2626
27+
code_quality:
28+
name: Code Quality🎖️
29+
runs-on: ubuntu-latest
30+
container: "golangci/golangci-lint:v1.62.2"
31+
steps:
32+
- name: Check out code into the Go module directory
33+
uses: actions/checkout@v4
34+
- name: Get dependencies
35+
run: go get -v -t -d ./...
36+
- name: GolangCI-Lint
37+
run: |
38+
golangci-lint run --timeout 9m0s
39+
2740
release_package:
2841
if: ${{ startsWith(github.ref, 'refs/tags/v')}}
42+
needs: [test_and_build,code_quality]
2943
runs-on: ubuntu-latest
3044

3145
permissions:
@@ -61,4 +75,4 @@ jobs:
6175
push: true
6276
context: .
6377
file: Dockerfile
64-
tags: zopdev/static-server:${{ env.RELEASE_VERSION }}, zopdev/static-server:latest
78+
tags: zopdev/static-server:${{ env.RELEASE_VERSION }}

README.md

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,15 @@
11
# Static Server
22

3-
A simple and efficient solution for serving static files. This server can be easily deployed via Docker, and it's optimized for serving static websites.
3+
A simple and efficient solution for serving static files.
44

55
## Features
66

7-
- **Easy to use**: Just place your static files in the `website` directory, and the server takes care of the rest.
7+
- **Easy to use**: Just place your static files in the `static` directory, and the server takes care of the rest.
88
- **Dockerized**: Easily deployable as a Docker container.
99
- **Lightweight**: Minimal dependencies for optimal performance.
1010
- **Configurable**: You can easily configure the server or extend it based on your needs.
11-
12-
## Requirements
13-
14-
To use this static server, you need the following:
15-
- Docker installed on your system.
11+
- The server serves files from the `static` directory by default, but you can change this by setting the `STATIC_DIR_PATH` environment variable.
12+
- Support all the confgs of the gofr framework - https://gofr.dev
1613

1714
## Usage
1815

@@ -30,7 +27,7 @@ FROM zopdev/static-server:latest
3027
# Copy static files into the container
3128
# The 'COPY' directive moves your static files (in this case, located at '/app/out') into the '/website' directory
3229
# which is where the static server expects to find the files to serve
33-
COPY /app/out /website
30+
COPY /app/out /static
3431

3532
# Expose the port on which the server will run
3633
# By default, the server listens on port 8000, so we expose that port to allow access from outside the container
@@ -78,7 +75,6 @@ Your static files will be served, and the root (`/`) will typically display your
7875

7976
## Notes
8077

81-
- The static server is designed to handle a large number of requests efficiently. However, if you have special requirements (such as caching or routing), you may need to customize the server or use additional reverse proxies (like Nginx).
8278
- The server serves all files in the `website` directory, so make sure to avoid any sensitive files or configuration details in that directory.
8379

8480
## License

configs/.env

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1 @@
1-
APP_NAME=static-server
2-
3-
STATIC_FILE_PATH=./website
1+
APP_NAME=static-server

go.mod

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@ module zop.dev/static-server
22

33
go 1.22.9
44

5-
require gofr.dev v1.28.1
5+
require gofr.dev v1.28.2
66

77
require (
88
cloud.google.com/go v0.116.0 // indirect
9-
cloud.google.com/go/auth v0.10.2 // indirect
10-
cloud.google.com/go/auth/oauth2adapt v0.2.5 // indirect
9+
cloud.google.com/go/auth v0.11.0 // indirect
10+
cloud.google.com/go/auth/oauth2adapt v0.2.6 // indirect
1111
cloud.google.com/go/compute/metadata v0.5.2 // indirect
1212
cloud.google.com/go/iam v1.2.2 // indirect
13-
cloud.google.com/go/pubsub v1.45.1 // indirect
13+
cloud.google.com/go/pubsub v1.45.3 // indirect
1414
filippo.io/edwards25519 v1.1.0 // indirect
1515
github.com/DATA-DOG/go-sqlmock v1.5.2 // indirect
1616
github.com/XSAM/otelsql v0.34.0 // indirect
@@ -75,23 +75,23 @@ require (
7575
golang.org/x/crypto v0.29.0 // indirect
7676
golang.org/x/net v0.31.0 // indirect
7777
golang.org/x/oauth2 v0.24.0 // indirect
78-
golang.org/x/sync v0.9.0 // indirect
79-
golang.org/x/sys v0.27.0 // indirect
80-
golang.org/x/term v0.26.0 // indirect
81-
golang.org/x/text v0.20.0 // indirect
78+
golang.org/x/sync v0.10.0 // indirect
79+
golang.org/x/sys v0.28.0 // indirect
80+
golang.org/x/term v0.27.0 // indirect
81+
golang.org/x/text v0.21.0 // indirect
8282
golang.org/x/time v0.8.0 // indirect
83-
google.golang.org/api v0.209.0 // indirect
84-
google.golang.org/genproto v0.0.0-20241113202542-65e8d215514f // indirect
85-
google.golang.org/genproto/googleapis/api v0.0.0-20241104194629-dd2ea8efbc28 // indirect
86-
google.golang.org/genproto/googleapis/rpc v0.0.0-20241113202542-65e8d215514f // indirect
87-
google.golang.org/grpc v1.67.1 // indirect
83+
google.golang.org/api v0.210.0 // indirect
84+
google.golang.org/genproto v0.0.0-20241118233622-e639e219e697 // indirect
85+
google.golang.org/genproto/googleapis/api v0.0.0-20241113202542-65e8d215514f // indirect
86+
google.golang.org/genproto/googleapis/rpc v0.0.0-20241118233622-e639e219e697 // indirect
87+
google.golang.org/grpc v1.68.1 // indirect
8888
google.golang.org/protobuf v1.35.2 // indirect
8989
gopkg.in/yaml.v3 v3.0.1 // indirect
9090
modernc.org/gc/v3 v3.0.0-20240107210532-573471604cb6 // indirect
9191
modernc.org/libc v1.55.3 // indirect
9292
modernc.org/mathutil v1.6.0 // indirect
9393
modernc.org/memory v1.8.0 // indirect
94-
modernc.org/sqlite v1.34.1 // indirect
94+
modernc.org/sqlite v1.34.2 // indirect
9595
modernc.org/strutil v1.2.0 // indirect
9696
modernc.org/token v1.1.0 // indirect
9797
)

go.sum

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
22
cloud.google.com/go v0.116.0 h1:B3fRrSDkLRt5qSHWe40ERJvhvnQwdZiHu0bJOpldweE=
33
cloud.google.com/go v0.116.0/go.mod h1:cEPSRWPzZEswwdr9BxE6ChEn01dWlTaF05LiC2Xs70U=
4-
cloud.google.com/go/auth v0.10.2 h1:oKF7rgBfSHdp/kuhXtqU/tNDr0mZqhYbEh+6SiqzkKo=
5-
cloud.google.com/go/auth v0.10.2/go.mod h1:xxA5AqpDrvS+Gkmo9RqrGGRh6WSNKKOXhY3zNOr38tI=
6-
cloud.google.com/go/auth/oauth2adapt v0.2.5 h1:2p29+dePqsCHPP1bqDJcKj4qxRyYCcbzKpFyKGt3MTk=
7-
cloud.google.com/go/auth/oauth2adapt v0.2.5/go.mod h1:AlmsELtlEBnaNTL7jCj8VQFLy6mbZv0s4Q7NGBeQ5E8=
4+
cloud.google.com/go/auth v0.11.0 h1:Ic5SZz2lsvbYcWT5dfjNWgw6tTlGi2Wc8hyQSC9BstA=
5+
cloud.google.com/go/auth v0.11.0/go.mod h1:xxA5AqpDrvS+Gkmo9RqrGGRh6WSNKKOXhY3zNOr38tI=
6+
cloud.google.com/go/auth/oauth2adapt v0.2.6 h1:V6a6XDu2lTwPZWOawrAa9HUK+DB2zfJyTuciBG5hFkU=
7+
cloud.google.com/go/auth/oauth2adapt v0.2.6/go.mod h1:AlmsELtlEBnaNTL7jCj8VQFLy6mbZv0s4Q7NGBeQ5E8=
88
cloud.google.com/go/compute/metadata v0.5.2 h1:UxK4uu/Tn+I3p2dYWTfiX4wva7aYlKixAHn3fyqngqo=
99
cloud.google.com/go/compute/metadata v0.5.2/go.mod h1:C66sj2AluDcIqakBq/M8lw8/ybHgOZqin2obFxa/E5k=
1010
cloud.google.com/go/iam v1.2.2 h1:ozUSofHUGf/F4tCNy/mu9tHLTaxZFLOUiKzjcgWHGIA=
@@ -13,8 +13,8 @@ cloud.google.com/go/kms v1.20.1 h1:og29Wv59uf2FVaZlesaiDAqHFzHaoUyHI3HYp9VUHVg=
1313
cloud.google.com/go/kms v1.20.1/go.mod h1:LywpNiVCvzYNJWS9JUcGJSVTNSwPwi0vBAotzDqn2nc=
1414
cloud.google.com/go/longrunning v0.6.2 h1:xjDfh1pQcWPEvnfjZmwjKQEcHnpz6lHjfy7Fo0MK+hc=
1515
cloud.google.com/go/longrunning v0.6.2/go.mod h1:k/vIs83RN4bE3YCswdXC5PFfWVILjm3hpEUlSko4PiI=
16-
cloud.google.com/go/pubsub v1.45.1 h1:ZC/UzYcrmK12THWn1P72z+Pnp2vu/zCZRXyhAfP1hJY=
17-
cloud.google.com/go/pubsub v1.45.1/go.mod h1:3bn7fTmzZFwaUjllitv1WlsNMkqBgGUb3UdMhI54eCc=
16+
cloud.google.com/go/pubsub v1.45.3 h1:prYj8EEAAAwkp6WNoGTE4ahe0DgHoyJd5Pbop931zow=
17+
cloud.google.com/go/pubsub v1.45.3/go.mod h1:cGyloK/hXC4at7smAtxFnXprKEFTqmMXNNd9w+bd94Q=
1818
filippo.io/edwards25519 v1.1.0 h1:FNf4tywRC1HmFuKW5xopWpigGjJKiJSV0Cqo0cJWDaA=
1919
filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4=
2020
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
@@ -238,8 +238,8 @@ go.uber.org/mock v0.5.0 h1:KAMbZvZPyBPWgD14IrIQ38QCyjwpvVVV6K/bHl1IwQU=
238238
go.uber.org/mock v0.5.0/go.mod h1:ge71pBPLYDk7QIi1LupWxdAykm7KIEFchiOqd6z7qMM=
239239
go.uber.org/multierr v1.6.0/go.mod h1:cdWPpRnG4AhwMwsgIHip0KRBQjJy5kYEpYjJxpXp9iU=
240240
go.uber.org/zap v1.18.1/go.mod h1:xg/QME4nWcxGxrpdeYfq7UvYrLh66cuVKdrbD1XF/NI=
241-
gofr.dev v1.28.1 h1:yf2Bv52JUtZeRbisRYEQYGuhL2EjJ81Mn0oAI0vStko=
242-
gofr.dev v1.28.1/go.mod h1:cQnVM+j8UFc8dM2VzNdJWU5GJMN5YWNsqPs44SsZxfY=
241+
gofr.dev v1.28.2 h1:F8wDGfcSm9LXQXVsKKIqwMIPny+weUANFSWTevnpdwo=
242+
gofr.dev v1.28.2/go.mod h1:0VucTBVth8ZnQPJyPa9EavQuWExV93N7PkmsyXqsxww=
243243
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
244244
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
245245
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
@@ -284,8 +284,8 @@ golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJ
284284
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
285285
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
286286
golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
287-
golang.org/x/sync v0.9.0 h1:fEo0HyrW1GIgZdpbhCRO0PkJajUS5H9IFUztCgEo2jQ=
288-
golang.org/x/sync v0.9.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
287+
golang.org/x/sync v0.10.0 h1:3NQrjDixjgGwUOCaF8w2+VYHv0Ve/vGYSbdkTa98gmQ=
288+
golang.org/x/sync v0.10.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
289289
golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
290290
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
291291
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
@@ -300,24 +300,24 @@ golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
300300
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
301301
golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
302302
golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
303-
golang.org/x/sys v0.27.0 h1:wBqf8DvsY9Y/2P8gAfPDEYNuS30J4lPHJxXSb/nJZ+s=
304-
golang.org/x/sys v0.27.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
303+
golang.org/x/sys v0.28.0 h1:Fksou7UEQUWlKvIdsqzJmUmCX3cZuD2+P3XyyzwMhlA=
304+
golang.org/x/sys v0.28.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
305305
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
306306
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
307307
golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k=
308308
golang.org/x/term v0.8.0/go.mod h1:xPskH00ivmX89bAKVGSKKtLOWNx2+17Eiy94tnKShWo=
309309
golang.org/x/term v0.13.0/go.mod h1:LTmsnFJwVN6bCy1rVCoS+qHT1HhALEFxKncY3WNNh4U=
310-
golang.org/x/term v0.26.0 h1:WEQa6V3Gja/BhNxg540hBip/kkaYtRg3cxg4oXSw4AU=
311-
golang.org/x/term v0.26.0/go.mod h1:Si5m1o57C5nBNQo5z1iq+XDijt21BDBDp2bK0QI8e3E=
310+
golang.org/x/term v0.27.0 h1:WP60Sv1nlK1T6SupCHbXzSaN0b9wUmsPoRS9b61A23Q=
311+
golang.org/x/term v0.27.0/go.mod h1:iMsnZpn0cago0GOrHO2+Y7u7JPn5AylBrcoWkElMTSM=
312312
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
313313
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
314314
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
315315
golang.org/x/text v0.3.8/go.mod h1:E6s5w1FMmriuDzIBO73fBruAKo1PCIq6d2Q6DHfQ8WQ=
316316
golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
317317
golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
318318
golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
319-
golang.org/x/text v0.20.0 h1:gK/Kv2otX8gz+wn7Rmb3vT96ZwuoxnQlY+HlJVj7Qug=
320-
golang.org/x/text v0.20.0/go.mod h1:D4IsuqiFMhST5bX19pQ9ikHC2GsaKyk/oF+pn3ducp4=
319+
golang.org/x/text v0.21.0 h1:zyQAAkrwaneQ066sspRyJaG9VNi/YJ1NfzcGB3hZ/qo=
320+
golang.org/x/text v0.21.0/go.mod h1:4IBbMaMmOPCJ8SecivzSH54+73PCFmPWxNTLm+vZkEQ=
321321
golang.org/x/time v0.8.0 h1:9i3RxcPv3PZnitoVGMPDKZSq1xW1gK1Xy3ArNOGZfEg=
322322
golang.org/x/time v0.8.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM=
323323
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
@@ -337,28 +337,28 @@ golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8T
337337
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
338338
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
339339
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
340-
google.golang.org/api v0.209.0 h1:Ja2OXNlyRlWCWu8o+GgI4yUn/wz9h/5ZfFbKz+dQX+w=
341-
google.golang.org/api v0.209.0/go.mod h1:I53S168Yr/PNDNMi5yPnDc0/LGRZO6o7PoEbl/HY3CM=
340+
google.golang.org/api v0.210.0 h1:HMNffZ57OoZCRYSbdWVRoqOa8V8NIHLL0CzdBPLztWk=
341+
google.golang.org/api v0.210.0/go.mod h1:B9XDZGnx2NtyjzVkOVTGrFSAVZgPcbedzKg/gTLwqBs=
342342
google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM=
343343
google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
344344
google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc=
345345
google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc=
346346
google.golang.org/genproto v0.0.0-20200423170343-7949de9c1215/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c=
347347
google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013/go.mod h1:NbSheEEYHJ7i3ixzK3sjbqSGDJWnxyFXZblF3eUsNvo=
348-
google.golang.org/genproto v0.0.0-20241113202542-65e8d215514f h1:zDoHYmMzMacIdjNe+P2XiTmPsLawi/pCbSPfxt6lTfw=
349-
google.golang.org/genproto v0.0.0-20241113202542-65e8d215514f/go.mod h1:Q5m6g8b5KaFFzsQFIGdJkSJDGeJiybVenoYFMMa3ohI=
350-
google.golang.org/genproto/googleapis/api v0.0.0-20241104194629-dd2ea8efbc28 h1:M0KvPgPmDZHPlbRbaNU1APr28TvwvvdUPlSv7PUvy8g=
351-
google.golang.org/genproto/googleapis/api v0.0.0-20241104194629-dd2ea8efbc28/go.mod h1:dguCy7UOdZhTvLzDyt15+rOrawrpM4q7DD9dQ1P11P4=
352-
google.golang.org/genproto/googleapis/rpc v0.0.0-20241113202542-65e8d215514f h1:C1QccEa9kUwvMgEUORqQD9S17QesQijxjZ84sO82mfo=
353-
google.golang.org/genproto/googleapis/rpc v0.0.0-20241113202542-65e8d215514f/go.mod h1:GX3210XPVPUjJbTUbvwI8f2IpZDMZuPJWDzDuebbviI=
348+
google.golang.org/genproto v0.0.0-20241118233622-e639e219e697 h1:ToEetK57OidYuqD4Q5w+vfEnPvPpuTwedCNVohYJfNk=
349+
google.golang.org/genproto v0.0.0-20241118233622-e639e219e697/go.mod h1:JJrvXBWRZaFMxBufik1a4RpFw4HhgVtBBWQeQgUj2cc=
350+
google.golang.org/genproto/googleapis/api v0.0.0-20241113202542-65e8d215514f h1:M65LEviCfuZTfrfzwwEoxVtgvfkFkBUbFnRbxCXuXhU=
351+
google.golang.org/genproto/googleapis/api v0.0.0-20241113202542-65e8d215514f/go.mod h1:Yo94eF2nj7igQt+TiJ49KxjIH8ndLYPZMIRSiRcEbg0=
352+
google.golang.org/genproto/googleapis/rpc v0.0.0-20241118233622-e639e219e697 h1:LWZqQOEjDyONlF1H6afSWpAL/znlREo2tHfLoe+8LMA=
353+
google.golang.org/genproto/googleapis/rpc v0.0.0-20241118233622-e639e219e697/go.mod h1:5uTbfoYQed2U9p3KIj2/Zzm02PYhndfdmML0qC3q3FU=
354354
google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c=
355355
google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg=
356356
google.golang.org/grpc v1.25.1/go.mod h1:c3i+UQWmh7LiEpx4sFZnkU36qjEYZ0imhYfXVyQciAY=
357357
google.golang.org/grpc v1.27.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk=
358358
google.golang.org/grpc v1.29.1/go.mod h1:itym6AZVZYACWQqET3MqgPpjcuV5QH3BxFS3IjizoKk=
359359
google.golang.org/grpc v1.33.2/go.mod h1:JMHMWHQWaTccqQQlmk3MJZS+GWXOdAesneDmEnv2fbc=
360-
google.golang.org/grpc v1.67.1 h1:zWnc1Vrcno+lHZCOofnIMvycFcc0QRGIzm9dhnDX68E=
361-
google.golang.org/grpc v1.67.1/go.mod h1:1gLDyUQU7CTLJI90u3nXZ9ekeghjeM7pTDZlqFNg2AA=
360+
google.golang.org/grpc v1.68.1 h1:oI5oTa11+ng8r8XMMN7jAOmWfPZWbYpCFaMUTACxkM0=
361+
google.golang.org/grpc v1.68.1/go.mod h1:+q1XYFJjShcqn0QZHvCyeR4CXPA+llXIeUIfIe00waw=
362362
google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8=
363363
google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0=
364364
google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM=
@@ -402,8 +402,8 @@ modernc.org/opt v0.1.3 h1:3XOZf2yznlhC+ibLltsDGzABUGVx8J6pnFMS3E4dcq4=
402402
modernc.org/opt v0.1.3/go.mod h1:WdSiB5evDcignE70guQKxYUl14mgWtbClRi5wmkkTX0=
403403
modernc.org/sortutil v1.2.0 h1:jQiD3PfS2REGJNzNCMMaLSp/wdMNieTbKX920Cqdgqc=
404404
modernc.org/sortutil v1.2.0/go.mod h1:TKU2s7kJMf1AE84OoiGppNHJwvB753OYfNl2WRb++Ss=
405-
modernc.org/sqlite v1.34.1 h1:u3Yi6M0N8t9yKRDwhXcyp1eS5/ErhPTBggxWFuR6Hfk=
406-
modernc.org/sqlite v1.34.1/go.mod h1:pXV2xHxhzXZsgT/RtTFAPY6JJDEvOTcTdwADQCCWD4k=
405+
modernc.org/sqlite v1.34.2 h1:J9n76TPsfYYkFkZ9Uy1QphILYifiVEwwOT7yP5b++2Y=
406+
modernc.org/sqlite v1.34.2/go.mod h1:dnR723UrTtjKpoHCAMN0Q/gZ9MT4r+iRvIBb9umWFkU=
407407
modernc.org/strutil v1.2.0 h1:agBi9dp1I+eOnxXeiZawM8F4LawKv4NzGWSaLfyeNZA=
408408
modernc.org/strutil v1.2.0/go.mod h1:/mdcBmfOibveCTBxUl5B5l6W+TTH1FXPLHZE6bTosX0=
409409
modernc.org/token v1.1.0 h1:Xl7Ap9dKaEs5kLoOQeQmPWevfnk/DM5qcLcYlA8ys6Y=

main.go

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

33
import (
4-
"gofr.dev/pkg/gofr"
54
"net/http"
65
"os"
76
"path/filepath"
87
"regexp"
8+
9+
"gofr.dev/pkg/gofr"
910
)
1011

1112
const defaultStaticFilePath = `./static`
1213

1314
func main() {
1415
app := gofr.New()
1516

16-
staticFilePath := app.Config.GetOrDefault("STATIC_FILE_PATH", defaultStaticFilePath)
17+
staticFilePath := app.Config.GetOrDefault("STATIC_DIR_PATH", defaultStaticFilePath)
1718

18-
app.UseMiddleware(func(handler http.Handler) http.Handler {
19+
app.UseMiddleware(func(_ http.Handler) http.Handler {
1920
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
2021
// check if the path has a file extension
2122
ok, _ := regexp.MatchString(`\.\S+$`, r.URL.Path)
@@ -27,9 +28,13 @@ func main() {
2728
filePath := filepath.Join(staticFilePath, r.URL.Path)
2829
if _, err := os.Stat(filePath); os.IsNotExist(err) {
2930
r.URL.Path = "/404.html"
31+
3032
w.WriteHeader(http.StatusNotFound)
33+
3134
filePath = filepath.Join(staticFilePath, "404.html")
3235

36+
http.ServeFile(w, r, filePath)
37+
3338
return
3439
}
3540

main_test.go

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package main
22

33
import (
4-
"io/ioutil"
4+
"context"
55
"net/http"
66
"os"
77
"path/filepath"
@@ -11,11 +11,8 @@ import (
1111

1212
func TestServer(t *testing.T) {
1313
// Create a temporary directory
14-
tempDir, err := ioutil.TempDir("", "static")
15-
if err != nil {
16-
t.Fatalf("Failed to create temp dir: %v", err)
17-
}
18-
defer os.RemoveAll(tempDir)
14+
//nolint:staticcheck // Ignore as we are testing the server
15+
tempDir := os.TempDir()
1916

2017
// Create necessary files
2118
files := []struct {
@@ -28,16 +25,17 @@ func TestServer(t *testing.T) {
2825

2926
for _, file := range files {
3027
filePath := filepath.Join(tempDir, file.name)
31-
if err := os.MkdirAll(filepath.Dir(filePath), 0755); err != nil {
28+
if err := os.MkdirAll(filepath.Dir(filePath), 0600); err != nil {
3229
t.Fatalf("Failed to create dir for file %s: %v", file.name, err)
3330
}
34-
if err := ioutil.WriteFile(filePath, []byte(file.content), 0644); err != nil {
31+
32+
if err := os.WriteFile(filePath, []byte(file.content), 0600); err != nil {
3533
t.Fatalf("Failed to write file %s: %v", file.name, err)
3634
}
3735
}
3836

3937
// Set the environment variable for the static file path
40-
t.Setenv("STATIC_FILE_PATH", tempDir)
38+
t.Setenv("STATIC_DIR_PATH", tempDir)
4139

4240
go main()
4341

@@ -55,15 +53,25 @@ func TestServer(t *testing.T) {
5553
}
5654

5755
for _, test := range tests {
58-
resp, err := http.Get("http://localhost:8000" + test.path)
56+
req, err := http.NewRequestWithContext(context.Background(), http.MethodGet, "http://localhost:8000"+test.path, http.NoBody)
5957
if err != nil {
60-
t.Fatalf("Failed to make GET request: %v", err)
58+
t.Fatalf("Failed to create request: %v", err)
6159
}
6260

63-
defer resp.Body.Close()
61+
client := &http.Client{}
62+
63+
resp, err := client.Do(req)
64+
if err != nil {
65+
t.Fatalf("Failed to perform request: %v", err)
66+
}
6467

6568
if resp.StatusCode != test.statusCode {
6669
t.Errorf("Expected status code %v, got %v for path %v", test.statusCode, resp.StatusCode, test.path)
6770
}
71+
72+
resp.Body.Close()
6873
}
74+
75+
//nolint:staticcheck // Ignore as we are testing the server
76+
os.RemoveAll(tempDir)
6977
}

0 commit comments

Comments
 (0)