|
1 | 1 | # redir |
| 2 | + |
2 | 3 | a request redirector that is dedicated for golang.design |
| 4 | + |
| 5 | +## Design Purpose |
| 6 | + |
| 7 | +The current `redir` implementation talks to a redis data store for PV/UV counting, |
| 8 | +as well as short alias storage. In the booting phase, it will read `REDIR_CONF` |
| 9 | +from environment variable to identify configuration file (default: `./config.yml`). |
| 10 | + |
| 11 | +`redir` is designed for the following purpose: serve two major |
| 12 | +redirectors `/s` and `/x` (at the moment). |
| 13 | + |
| 14 | +### 1. Redirect `golang.design/x/pkg` to the `pkg`'s actual VCS. |
| 15 | + |
| 16 | +This is based on the `go get` vanity import path convention. With this |
| 17 | +feature, all packages issued by [golang.design](https://golang.design) |
| 18 | +requires to use `golang.design/x/` import path. |
| 19 | +That is saying, any `pkg` will be redirected to `github.com/golang-design/pkg` |
| 20 | +if exist. The website itself will redirect the request to [pkg.go.dev](https://pkg.go.dev). |
| 21 | + |
| 22 | +There is a reserved ping router for debugging purpose `/x/.ping` which will |
| 23 | +give you a pong. |
| 24 | + |
| 25 | +### 2. Redirect `golang.design/s/alias` |
| 26 | + |
| 27 | +The served alias can be allocated by [golang.design](https://golang.design/) members. |
| 28 | +The current approach is to use `redir` command on the [golang.design](https://golang.design/) |
| 29 | +server. Here is the overview of its usage: |
| 30 | + |
| 31 | +``` |
| 32 | +usage: redir [-s] [-op <operator> -a <alias> -l <link>] |
| 33 | +options: |
| 34 | + -a string |
| 35 | + alias for a new link |
| 36 | + -l string |
| 37 | + actual link for the alias, optional for delete/fetch |
| 38 | + -op string |
| 39 | + operators, create/update/delete/fetch (default "create") |
| 40 | + -s run redir service |
| 41 | +example: |
| 42 | +redir -s run the redir service |
| 43 | +redir -a alias -l link allocate new short link if possible |
| 44 | +redir -op fetch -a alias fetch alias information |
| 45 | +``` |
| 46 | + |
| 47 | +For the command line usage, one only need to use `-a`, `-l` and `-op` if needed. |
| 48 | +The command will talk to the redis data store and issue a new allocated alias. |
| 49 | +For instance, the following command: |
| 50 | + |
| 51 | +``` |
| 52 | +redir -a changkun -l https://changkun.de |
| 53 | +``` |
| 54 | + |
| 55 | +creates a new alias under [golang.design/s/changkun](https://golang.design/s/changkun). |
| 56 | + |
| 57 | +Moreover, it is possible to visit [`/s`](https://golang.design/s) directly listing all exist aliases under [golang.design](https://golang.design/). |
| 58 | + |
| 59 | +## Build |
| 60 | + |
| 61 | +`Makefile` defines different ways to build the service: |
| 62 | + |
| 63 | +```bash |
| 64 | +make # build native binary |
| 65 | +make run # assume your local redis is running |
| 66 | +make build # build docker images |
| 67 | +make compose # run via docker-compose |
| 68 | +make compose-down # remove compose stuff |
| 69 | +make clean # cleanup |
| 70 | +``` |
| 71 | + |
| 72 | +## Troubleshooting |
| 73 | + |
| 74 | +### private golang.design projects `go get` failure |
| 75 | + |
| 76 | +1. make sure you are a member of golang.design |
| 77 | +2. add ssh public key to your account |
| 78 | +3. `git config --global url."[email protected]:".insteadOf "https://github.com/"` |
| 79 | + |
| 80 | +## License |
| 81 | + |
| 82 | +MIT © The golang.design Initiative Authors |
0 commit comments