diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index fb4c591..474d970 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -91,13 +91,13 @@ jobs: run: go mod download - name: Build - run: make + run: make term - name: Create role for test run: | echo -n "CREATE ROLE test WITH LOGIN PASSWORD " >> $SQL_FILE_PATH echo -n "'" >> $SQL_FILE_PATH - ./cmd/tool/encrypt test | tr -d '\n' >> $SQL_FILE_PATH + ./cmd/term/encrypt test | tr -d '\n' >> $SQL_FILE_PATH echo "';" >> $SQL_FILE_PATH cat $SQL_FILE_PATH | tee /dev/stderr | psql env: diff --git a/.gitignore b/.gitignore index 5086168..5a0a8eb 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ -/cmd/tool/encrypt +/cmd/term/encrypt +/cmd/debug/server diff --git a/.goreleaser.yaml b/.goreleaser.yaml index 294a58b..579c133 100644 --- a/.goreleaser.yaml +++ b/.goreleaser.yaml @@ -22,7 +22,7 @@ builds: goarm: - 6 - 7 - main: ./cmd/tool + main: ./cmd/term # https://goreleaser.com/customization/archive/ archives: diff --git a/Makefile b/Makefile index cacde37..da44a27 100644 --- a/Makefile +++ b/Makefile @@ -3,11 +3,16 @@ GOOS ?= $(shell go env GOOS) GOARCH ?= $(shell go env GOARCH) CGO_ENABLED ?= $(shell go env CGO_ENABLED) -cmd/tool/encrypt: cmd/tool/main.go - GOOS=${GOOS} GOARCH=${GOARCH} CGO_ENABLED=${CGO_ENABLED} go build -ldflags="-s -w" -trimpath -o $@ $^ +define go-build + GOOS=${GOOS} GOARCH=${GOARCH} CGO_ENABLED=${CGO_ENABLED}\ + go build -ldflags="-s -w" -trimpath -o $@ $^ +endef -docs/encrypt.wasm: cmd/wasm/main.go - GOOS=js GOARCH=wasm CGO_ENABLED=0 go build -ldflags="-s -w" -trimpath -o $@ $^ +build: term wasm + +term: cmd/term/encrypt + +wasm: docs/wasm_exec.js docs/encrypt.wasm cmd/debug/server test: @go clean -testcache @@ -17,6 +22,22 @@ lint: @go vet ./... clean: - @rm -rf cmd/tool/encrypt + @rm -f cmd/term/encrypt cmd/debug/server + +cmd/term/encrypt: cmd/term/main.go + $(call go-build) + +cmd/debug/server: cmd/debug/main.go + $(call go-build) + +docs/encrypt.wasm: GOOS := js +docs/encrypt.wasm: GOARCH := wasm +docs/encrypt.wasm: CGO_ENABLED := 0 +docs/encrypt.wasm: cmd/wasm/main.go + $(call go-build) + +docs/wasm_exec.js: $(shell go env GOROOT)/misc/wasm/wasm_exec.js + @cp $^ $@ -.PHONY: cmd/tool/encrypt docs/encrypt.wasm test lint clean +.PHONY: build term wasm test lint clean \ + cmd/term/encrypt docs/encrypt.wasm diff --git a/README.md b/README.md index 1153cea..ab15c0c 100644 --- a/README.md +++ b/README.md @@ -50,8 +50,8 @@ func doSomething(rawPassword []byte) error { ``` $ git clone https://github.com/supercaracal/scram-sha-256.git $ cd scram-sha-256/ -$ make -$ ./cmd/tool/encrypt +$ make term +$ ./cmd/term/encrypt Raw password: SCRAM-SHA-256$4096:Mg8UNqSaPstxvBVRVYPQTw==$Zl7Rhln+rus3z+4YwC+7CgL/uKSUvqWH8mHMUizh1EI=:G9dSawW20CNLxTnZdcwHEHg9U9hG2noNEV2/t7ptq3s= ``` diff --git a/docs/server.go b/cmd/debug/main.go similarity index 83% rename from docs/server.go rename to cmd/debug/main.go index 2d2f331..3f8cd6f 100644 --- a/docs/server.go +++ b/cmd/debug/main.go @@ -6,7 +6,8 @@ import ( ) const ( - appName = "scram-sha-256" + appName = "scram-sha-256" + staticDir = "docs" ) var ( @@ -21,7 +22,7 @@ var ( func makeStaticHandler(f string) func(http.ResponseWriter, *http.Request) { return func(w http.ResponseWriter, r *http.Request) { - http.ServeFile(w, r, f) + http.ServeFile(w, r, fmt.Sprintf("%s/%s", staticDir, f)) } } diff --git a/cmd/tool/main.go b/cmd/term/main.go similarity index 100% rename from cmd/tool/main.go rename to cmd/term/main.go diff --git a/cmd/tool/main_test.go b/cmd/term/main_test.go similarity index 100% rename from cmd/tool/main_test.go rename to cmd/term/main_test.go