Push README.md

Bump version.
This commit is contained in:
n0vad3v 2020-03-03 20:52:42 +08:00
parent 200a52de2a
commit 9e6f648cc4
No known key found for this signature in database
GPG Key ID: 8D42A0E699E50639
4 changed files with 44 additions and 53 deletions

View File

@ -56,39 +56,7 @@ Create a `config.json` as follows to face your need, default convert quality is
} }
``` ```
## 3. Run ## 3. Run
Run the binary like this: `./webp-server --config /path/to/config.json`, for prefetch mode, add `--prefech`.
> Prefetch mode will pre-convert all the images in the `IMG_PATH` on initial start up.
### screen or tmux
Use `screen` or `tmux` to avoid being terminated. Let's take `screen` for example
```
screen -S webp
./webp-server --config /path/to/config.json
```
(Use Ctrl-A-D to detach the `screen` with `webp-server` running.)
### systemd
Don't worry, we've got you covered!
Download `webp-server` to `/opt/webps/webp-server`, and create a config file to `/opt/webps/config.json`, then,
```shell script
cp webps.service /lib/systemd/system/
systemctl daemon-reload
systemctl enable webps.service
systemctl start webps.service
```
## 4. Nginx proxy_pass
Let Nginx to `proxy_pass http://localhost:3333/;`, and your webp-server is on-the-fly
### WordPress example
```
location ^~ /wp-content/uploads/ {
proxy_pass http://127.0.0.1:3333;
}
```
## Advanced usage
### show help
``` ```
./webp-server --help ./webp-server --help
Usage of ./webp-server: Usage of ./webp-server:
@ -108,8 +76,7 @@ Usage of ./webp-server:
use prefork use prefork
``` ```
### Prefetch ### Prefetch
Prefetch will convert all your images to webp. Don't worry, Webp server will start, Prefetch will convert all your images to webp. Don't worry, WebP Server will start, you don't have to wait until prefetch completes.
you don't have to wait until prefetch completes.
``` ```
./webp-server -prefetch ./webp-server -prefetch
``` ```
@ -122,7 +89,7 @@ By default, it will utilize all your CPU cores.
### dump config.json ### dump config.json
The standard `config.json` will show on your screen. You many want to use `>` to redirect to a file. The standard `config.json` will show on your screen. You many want to use `>` to redirect to a file.
``` ```
./webp-server -dump-config ./webp-server -dump-config > config.json
``` ```
### dump systemd service file ### dump systemd service file
The standard systemd service file will show on your screen. You many want to use `>` to redirect to a file. The standard systemd service file will show on your screen. You many want to use `>` to redirect to a file.
@ -131,6 +98,35 @@ The standard systemd service file will show on your screen. You many want to use
./webp-server -dump-systemd ./webp-server -dump-systemd
``` ```
### screen or tmux
Use `screen` or `tmux` to avoid being terminated. Let's take `screen` for example
```
screen -S webp
./webp-server --config /path/to/config.json
```
(Use Ctrl-A-D to detach the `screen` with `webp-server` running.)
### systemd
Don't worry, we've got you covered!
Download `webp-server` to `/opt/webps/webp-server`, and create a config file to `/opt/webps/config.json`, then,
```shell script
./webp-server -dump-systemd > /lib/systemd/system/webp-server.service
systemctl daemon-reload
systemctl enable webps.service
systemctl start webps.service
```
## 4. Nginx proxy_pass
Let Nginx to `proxy_pass http://localhost:3333/;`, and your webp-server is on-the-fly
### WordPress example
```
location ^~ /wp-content/uploads/ {
proxy_pass http://127.0.0.1:3333;
}
```
If you use Caddy, you may refer to [优雅的让 Halo 支持 webp 图片输出](https://halo.run/archives/halo-and-webp).
## Advanced usage
## Build your own binaries ## Build your own binaries
Install latest version of golang, enable go module, clone the repo, and then... Install latest version of golang, enable go module, clone the repo, and then...
```shell script ```shell script

View File

@ -4,11 +4,5 @@
"QUALITY": "80", "QUALITY": "80",
"IMG_PATH": "/path/to/pics", "IMG_PATH": "/path/to/pics",
"EXHAUST_PATH": "", "EXHAUST_PATH": "",
"ALLOWED_TYPES": [ "ALLOWED_TYPES": ["jpg","png","jpeg","bmp","gif"]
"jpg",
"png",
"jpeg",
"bmp",
"gif"
]
} }

View File

@ -1,6 +1,6 @@
[Unit] [Unit]
Description=WebP Server Description=WebP Server Go
Documentation=https://github.com/n0vad3v/webp_server_go Documentation=https://github.com/webp-sh/webp_server_go
After=nginx.target After=nginx.target
[Service] [Service]

View File

@ -7,7 +7,6 @@ import (
"errors" "errors"
"flag" "flag"
"fmt" "fmt"
"golang.org/x/image/bmp"
"image" "image"
"image/gif" "image/gif"
"image/jpeg" "image/jpeg"
@ -22,6 +21,8 @@ import (
"strconv" "strconv"
"strings" "strings"
"golang.org/x/image/bmp"
"github.com/chai2010/webp" "github.com/chai2010/webp"
"github.com/gofiber/fiber" "github.com/gofiber/fiber"
) )
@ -35,7 +36,7 @@ type Config struct {
ExhaustPath string `json:"EXHAUST_PATH"` ExhaustPath string `json:"EXHAUST_PATH"`
} }
const version = "0.0.3" const version = "0.0.4"
var configPath string var configPath string
var prefetch bool var prefetch bool
@ -45,18 +46,18 @@ var dumpSystemd bool
const sampleConfig = ` const sampleConfig = `
{ {
"HOST": "127.0.0.1", "HOST": "127.0.0.1",
"PORT": "3333", "PORT": "3333",
"QUALITY": "80", "QUALITY": "80",
"IMG_PATH": "/Users/benny/goLandProject/webp_server_go/pics", "IMG_PATH": "/path/to/pics",
"EXHAUST_PATH": "", "EXHAUST_PATH": "",
"ALLOWED_TYPES": ["jpg", "png", "jpeg", "bmp", "gif"] "ALLOWED_TYPES": ["jpg","png","jpeg","bmp","gif"]
} }
` `
const sampleSystemd = ` const sampleSystemd = `
[Unit] [Unit]
Description=WebP Server Description=WebP Server
Documentation=https://github.com/n0vad3v/webp_server_go Documentation=https://github.com/webp-sh/webp_server_go
After=nginx.target After=nginx.target
[Service] [Service]