Skip to content

Commit

Permalink
refactor: rename directories and fix makefile (#12)
Browse files Browse the repository at this point in the history
  • Loading branch information
supercaracal authored Feb 10, 2024
1 parent 0fc0c2d commit 3b80cb4
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 14 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
/cmd/tool/encrypt
/cmd/term/encrypt
/cmd/debug/server
2 changes: 1 addition & 1 deletion .goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ builds:
goarm:
- 6
- 7
main: ./cmd/tool
main: ./cmd/term

# https://goreleaser.com/customization/archive/
archives:
Expand Down
33 changes: 27 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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=
```
Expand Down
5 changes: 3 additions & 2 deletions docs/server.go → cmd/debug/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import (
)

const (
appName = "scram-sha-256"
appName = "scram-sha-256"
staticDir = "docs"
)

var (
Expand All @@ -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))
}
}

Expand Down
File renamed without changes.
File renamed without changes.

0 comments on commit 3b80cb4

Please sign in to comment.