Skip to content

Commit 80bc483

Browse files
committed
README: standardize code block style
1 parent ddf11c9 commit 80bc483

File tree

1 file changed

+55
-25
lines changed

1 file changed

+55
-25
lines changed

README.md

Lines changed: 55 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -98,12 +98,16 @@ image][material-animation] resized to 200px square and rotated 270 degrees:
9898

9999
Install the package using:
100100

101-
go install willnorris.com/go/imageproxy/cmd/imageproxy@latest
101+
```sh
102+
go install willnorris.com/go/imageproxy/cmd/imageproxy@latest
103+
```
102104

103105
Once installed, ensure `$GOPATH/bin` is in your `$PATH`, then run the proxy
104106
using:
105107

106-
imageproxy
108+
```sh
109+
imageproxy
110+
```
107111

108112
This will start the proxy on port 8080, without any caching and with no allowed
109113
host list (meaning any remote URL can be proxied). Test this by navigating to
@@ -141,12 +145,16 @@ enabled using the `-cache` flag. It supports the following values:
141145
For example, when working with [minio](https://minio.io), which doesn't use
142146
regions, provide a dummy region value and custom endpoint value:
143147

144-
s3://fake-region/bucket/folder?endpoint=minio:9000&disableSSL=1&s3ForcePathStyle=1
148+
```
149+
s3://fake-region/bucket/folder?endpoint=minio:9000&disableSSL=1&s3ForcePathStyle=1
150+
```
145151

146152
Similarly, for [Digital Ocean Spaces](https://www.digitalocean.com/products/spaces/),
147153
provide a dummy region value and the appropriate endpoint for your space:
148154

149-
s3://fake-region/bucket/folder?endpoint=sfo2.digitaloceanspaces.com
155+
```
156+
s3://fake-region/bucket/folder?endpoint=sfo2.digitaloceanspaces.com
157+
```
150158

151159
[aws-options]: https://docs.aws.amazon.com/sdk-for-go/api/aws/#Config
152160

@@ -165,7 +173,9 @@ enabled using the `-cache` flag. It supports the following values:
165173

166174
For example, to cache files on disk in the `/tmp/imageproxy` directory:
167175

168-
imageproxy -cache /tmp/imageproxy
176+
```sh
177+
imageproxy -cache /tmp/imageproxy
178+
```
169179

170180
Reload the [codercat URL][], and then inspect the contents of
171181
`/tmp/imageproxy`. Within the subdirectories, there should be two files, one
@@ -180,7 +190,9 @@ fashion][]. Typically this is used to put a smaller and faster in-memory cache
180190
in front of a larger but slower on-disk cache. For example, the following will
181191
first check an in-memory cache for an image, followed by a gcs bucket:
182192

183-
imageproxy -cache memory -cache gcs://my-bucket/
193+
```sh
194+
imageproxy -cache memory -cache gcs://my-bucket/
195+
```
184196

185197
[tiered fashion]: https://pkg.go.dev/github.com/die-net/lrucache/twotier
186198

@@ -198,15 +210,19 @@ will extend the cache duration if the response header indicates a shorter value.
198210
If called without the `-forceCache` flag, this will have no effect on responses
199211
with the `no-store` or `private` directives.
200212

201-
imageproxy -cache /tmp/imageproxy -minCacheDuration 5m
213+
```sh
214+
imageproxy -cache /tmp/imageproxy -minCacheDuration 5m
215+
```
202216

203217
### Allowed Referrer List
204218

205219
You can limit images to only be accessible for certain hosts in the HTTP
206220
referrer header, which can help prevent others from hotlinking to images. It can
207221
be enabled by running:
208222

209-
imageproxy -referrers example.com
223+
```sh
224+
imageproxy -referrers example.com
225+
```
210226

211227
Reload the [codercat URL][], and you should now get an error message. You can
212228
specify multiple hosts as a comma separated list, or prefix a host value with
@@ -221,12 +237,16 @@ if you want to support fetching from any host, leave off these flags.
221237

222238
Try it out by running:
223239

224-
imageproxy -allowHosts example.com
240+
```sh
241+
imageproxy -allowHosts example.com
242+
```
225243

226244
Reload the [codercat URL][], and you should now get an error message.
227245
Alternately, try running:
228246

229-
imageproxy -denyHosts octodex.github.com
247+
```sh
248+
imageproxy -denyHosts octodex.github.com
249+
```
230250

231251
Reloading the [codercat URL][] will still return an error message.
232252

@@ -252,15 +272,19 @@ is useful in preventing abuse when you don't have just a static list of hosts
252272
you want to allow. Signatures are generated using HMAC-SHA256 against the
253273
remote URL, and url-safe base64 encoding the result:
254274

255-
base64urlencode(hmac.New(sha256, <key>).digest(<remote_url>))
275+
```
276+
base64urlencode(hmac.New(sha256, <key>).digest(<remote_url>))
277+
```
256278

257279
The HMAC key is specified using the `signatureKey` flag. If this flag
258280
begins with an "@", the remainder of the value is interpreted as a file on disk
259281
which contains the HMAC key.
260282

261283
Try it out by running:
262284

263-
imageproxy -signatureKey "secretkey"
285+
```sh
286+
imageproxy -signatureKey "secretkey"
287+
```
264288

265289
Reload the [codercat URL][], and you should see an error message. Now load a
266290
[signed codercat URL][] (which contains the [signature option][]) and verify
@@ -287,7 +311,9 @@ However, if you commonly proxy images from a single source, you can provide a
287311
base URL and then specify remote images relative to that base. Try it out by
288312
running:
289313

290-
imageproxy -baseURL https://octodex.github.com/
314+
```sh
315+
imageproxy -baseURL https://octodex.github.com/
316+
```
291317

292318
Then load the codercat image, specified as a URL relative to that base:
293319
<http://localhost:8080/500/images/codercat.jpg>. Note that this is not an
@@ -300,7 +326,9 @@ specified, you can always provide the absolute URL of the image to be proxied.
300326
By default, the imageproxy won't scale images beyond their original size.
301327
However, you can use the `scaleUp` command-line flag to allow this to happen:
302328

303-
imageproxy -scaleUp true
329+
```sh
330+
imageproxy -scaleUp true
331+
```
304332

305333
### WebP and TIFF support
306334

@@ -326,7 +354,9 @@ needs... it's a very simple command.
326354
All configuration flags have equivalent environment variables of the form
327355
`IMAGEPROXY_$NAME`. For example, an on-disk cache could be configured by calling
328356

329-
IMAGEPROXY_CACHE="/tmp/imageproxy" imageproxy
357+
```sh
358+
IMAGEPROXY_CACHE="/tmp/imageproxy" imageproxy
359+
```
330360

331361
## Deploying
332362

@@ -359,13 +389,13 @@ A docker image is available at [`ghcr.io/willnorris/imageproxy`](https://github.
359389

360390
You can run it by
361391

362-
```
392+
```sh
363393
docker run -p 8080:8080 ghcr.io/willnorris/imageproxy -addr 0.0.0.0:8080
364394
```
365395

366396
Or in your Dockerfile:
367397

368-
```
398+
```Dockerfile
369399
ENTRYPOINT ["/app/imageproxy", "-addr 0.0.0.0:8080"]
370400
```
371401

@@ -383,19 +413,19 @@ containers.
383413
Use the `proxy_pass` directive to send requests to your imageproxy instance.
384414
For example, to run imageproxy at the path "/api/imageproxy/", set:
385415

386-
```
387-
location /api/imageproxy/ {
388-
proxy_pass http://localhost:4593/;
389-
}
416+
```nginx
417+
location /api/imageproxy/ {
418+
proxy_pass http://localhost:4593/;
419+
}
390420
```
391421

392422
Depending on other directives you may have in your nginx config, you might need
393423
to alter the precedence order by setting:
394424

395-
```
396-
location ^~ /api/imageproxy/ {
397-
proxy_pass http://localhost:4593/;
398-
}
425+
```nginx
426+
location ^~ /api/imageproxy/ {
427+
proxy_pass http://localhost:4593/;
428+
}
399429
```
400430

401431
## Clients

0 commit comments

Comments
 (0)