diff --git a/Makefile b/Makefile index 2bf3f00..85afbd2 100644 --- a/Makefile +++ b/Makefile @@ -5,28 +5,29 @@ VERSION = $(shell git describe --always --tags) BUILDTIME = $(shell date +%FT%T%z) GOPATH=$(shell go env GOPATH) -IMAGE = golang-design/redir +IMAGE = redir BINARY = redir.app TARGET = -o $(BINARY) BUILD_SETTINGS = -ldflags="-X main.Version=$(VERSION) -X main.BuildTime=$(BUILDTIME)" -BUILD_FLAGS = $(TARGET) $(BUILD_SETTINGS) +BUILD_FLAGS = $(TARGET) $(BUILD_SETTINGS) -mod=vendor all: native native: - GO111MODULE=on go build $(BUILD_FLAGS) + go build $(BUILD_FLAGS) run: ./$(BINARY) -s build: + GOOS=linux go build $(BUILD_FLAGS) docker build -t $(IMAGE):$(VERSION) -t $(IMAGE):latest -f docker/Dockerfile . -compose: +up: down docker-compose -f docker/docker-compose.yml up -d -compose-down: +down: docker-compose -f docker/docker-compose.yml down test: mkdir -p build go test -cover -coverprofile=build/cover.test -v ./... go tool cover -html=build/cover.test -o build/cover.html -clean: +clean: down rm redir.app docker rmi -f $(shell docker images -f "dangling=true" -q) 2> /dev/null; true docker rmi -f $(IMAGE):latest $(IMAGE):$(VERSION) 2> /dev/null; true diff --git a/README.md b/README.md index f301762..570d4da 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ a request redirector that is dedicated for golang.design The current `redir` implementation talks to a redis data store for PV/UV counting, as well as short alias storage. In the booting phase, it will read `REDIR_CONF` -from environment variable to identify configuration file (default: `./config.yml`). +from environment variable to identify configuration file (default: [`./config.yml`](./config.yml)). `redir` is designed for the following purpose: serve two major redirectors `/s` and `/x` (at the moment). @@ -72,12 +72,12 @@ Moreover, it is possible to visit [`/s`](https://golang.design/s) directly listi `Makefile` defines different ways to build the service: ```bash -make # build native binary -make run # assume your local redis is running -make build # build docker images -make compose # run via docker-compose -make compose-down # remove compose stuff -make clean # cleanup +make # build native binary +make run # assume your local redis is running +make build # build docker images +make up # run via docker-compose +make down # remove compose stuff +make clean # cleanup ``` ## Troubleshooting @@ -87,6 +87,7 @@ make clean # cleanup 1. make sure you are a member of golang.design 2. add ssh public key to your account 3. `git config --global url."git@github.com:".insteadOf "https://github.com/"` +4. add `export GOPRIVATE=golang.design/x` to your bash profile (e.g. `.zshrc`). ## License diff --git a/config.go b/config.go index c60e13d..7e8f691 100644 --- a/config.go +++ b/config.go @@ -21,6 +21,7 @@ var ( ) type config struct { + Title string `yaml:"title"` Host string `yaml:"host"` Addr string `yaml:"addr"` Store string `yaml:"store"` @@ -35,7 +36,9 @@ type config struct { VCS string `yaml:"vcs"` ImportPath string `yaml:"import_path"` RepoPath string `yaml:"repo_path"` + GoDocHost string `yaml:"godoc_host"` } `yaml:"x"` + GoogleAnalytics string `yaml:"google_analytics"` } func (c *config) parse() { diff --git a/config.yml b/config.yml index 643e547..c5b6011 100644 --- a/config.yml +++ b/config.yml @@ -3,8 +3,9 @@ # by a MIT license that can be found in the LICENSE file. --- +title: "The golang.design Initiative" host: https://golang.design -addr: :8080 +addr: :9123 store: redis://localhost:6379/9 backup_min: 10 backup_dir: ./data/backup @@ -15,4 +16,14 @@ x: prefix: /x/ vcs: git import_path: golang.design/x/* - repo_path: https://github.com/golang-design/* \ No newline at end of file + repo_path: https://github.com/golang-design/* + godoc_host: https://pkg.go.dev/ +google_analytics: | + + + diff --git a/data/container.yml b/data/container.yml index 372348b..5cda2fa 100644 --- a/data/container.yml +++ b/data/container.yml @@ -3,7 +3,8 @@ # by a MIT license that can be found in the LICENSE file. --- -host: https://golang.design/ +title: The golang.design Initiative +host: https://golang.design addr: :8080 store: redis://redis:6379/9 backup_min: 1440 # 24h @@ -15,4 +16,14 @@ x: prefix: /x/ vcs: git import_path: golang.design/x/* - repo_path: https://github.com/golang-design/* \ No newline at end of file + repo_path: https://github.com/golang-design/* + godoc_host: https://pkg.go.dev/ +google_analytics: | + + + diff --git a/docker/Dockerfile b/docker/Dockerfile index 5ccca69..3abee3a 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -2,12 +2,7 @@ # All rights reserved. Use of this source code is governed # by a MIT license that can be found in the LICENSE file. -FROM golang:1.14.9 +FROM golang:1.15.3 WORKDIR /app COPY . . -RUN go build -o redir -ldflags \ - "-X main.Version=v$(git describe --always --tags) \ - -X main.BuildTime=$(date +%FT%T%z)" -# @changkun: could use alpine instead, maybe in the future. -EXPOSE 8080 -CMD ["/app/redir", "-s"] \ No newline at end of file +CMD ["/app/redir.app", "-s"] \ No newline at end of file diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml index 05a5af5..b9c28b4 100644 --- a/docker/docker-compose.yml +++ b/docker/docker-compose.yml @@ -9,34 +9,34 @@ services: container_name: redir restart: always volumes: - - ../data/backup:/data/backup - image: golang-design/redir:latest + - ../data/backup:/app/data/backup + image: redir:latest environment: REDIR_CONF: ./data/container.yml cap_add: - SYS_PTRACE # for debugging ports: - - "8080:8080" + - "9123:8080" depends_on: - redis networks: redirnet: - ipv4_address: 172.16.238.10 + ipv4_address: 172.16.1.10 redis: container_name: redis restart: always volumes: - ../data/redis:/data - image: redis:3.2 + image: redis:6.0 ports: - "6379:6379" networks: redirnet: - ipv4_address: 172.16.238.11 + ipv4_address: 172.16.1.11 networks: redirnet: driver: bridge ipam: driver: default config: - - subnet: 172.16.238.0/24 \ No newline at end of file + - subnet: 172.16.1.0/24 \ No newline at end of file diff --git a/public/stats.html b/public/stats.html index ad69679..745120f 100644 --- a/public/stats.html +++ b/public/stats.html @@ -1,14 +1,7 @@
- - - + {{ .GoogleAnalytics }}{{ .PV }} | {{ .UV }} | -https://golang.design/s/{{ .Alias }} | +{{ $.Host }}/s/{{ .Alias }} |