Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: rename directories and fix makefile #12

Merged
merged 1 commit into from
Feb 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.