From 79215d5fe17f1bca21bf5e965e67833f9dce7082 Mon Sep 17 00:00:00 2001 From: vinchent Date: Sun, 4 Aug 2024 16:25:16 +0200 Subject: [PATCH] add makefile support --- .air.toml | 6 ++--- Makefile | 60 +++++++++++++++++++++++++++++++++++++++++++++++++ cmd/web/main.go | 6 +++++ 3 files changed, 69 insertions(+), 3 deletions(-) create mode 100644 Makefile diff --git a/.air.toml b/.air.toml index 3164658..a49ed86 100644 --- a/.air.toml +++ b/.air.toml @@ -7,11 +7,11 @@ tmp_dir = "tmp" [build] # Just plain old shell command. You could use `make` as well. -cmd = "go build -o ./tmp/main ./cmd/web/" +cmd = "make" # Binary file yields from `cmd`. -bin = "tmp main" +bin = "dist/gostripe" # Customize binary. -full_bin = "STRIPE_SECRET= STRIPE_KEY= ./tmp/main" +full_bin = "STRIPE_SECRET= STRIPE_KEY= ./dist/gostripe" # Watch these filename extensions. include_ext = ["go", "tpl", "tmpl", "html", "gohtml"] # Ignore these filename extensions or directories. diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..4a8c894 --- /dev/null +++ b/Makefile @@ -0,0 +1,60 @@ +STRIPE_SECRET=$(shell sed '2q;d' cred.txt) +STRIPE_KEY=$(shell sed '2q;d' cred.txt) +GOSTRIPE_PORT=4000 +API_PORT=4001 +DSN=root@tcp(localhost:6379)/widgets?parseTime=true&tls=false + +## build: builds all binaries +build: clean build_front build_back + @printf "All binaries built!\n" + +## clean: cleans all binaries and runs go clean +clean: + @echo "Cleaning..." + @- rm -f dist/* + @go clean + @echo "Cleaned!" + +## build_front: builds the front end +build_front: + @echo "Building front end..." + @go build -o dist/gostripe ./cmd/web + @echo "Front end built!" + +## build_back: builds the back end +build_back: + @echo "Building back end..." + @go build -o dist/gostripe_api ./cmd/api + @echo "Back end built!" + +## start: starts front and back end +start: start_front start_back + +## start_front: starts the front end +start_front: build_front + @echo "Starting the front end..." + @env STRIPE_KEY=${STRIPE_KEY} STRIPE_SECRET=${STRIPE_SECRET} ./dist/gostripe -port=${GOSTRIPE_PORT} -dsn="${DSN}" & + @echo "Front end running!" + +## start_back: starts the back end +start_back: build_back + @echo "Starting the back end..." + @env STRIPE_KEY=${STRIPE_KEY} STRIPE_SECRET=${STRIPE_SECRET} ./dist/gostripe_api -port=${API_PORT} -dsn="${DSN}" & + @echo "Back end running!" + +## stop: stops the front and back end +stop: stop_front stop_back + @echo "All applications stopped" + +## stop_front: stops the front end +stop_front: + @echo "Stopping the front end..." + @-pkill -SIGTERM -f "gostripe -port=${GOSTRIPE_PORT}" + @echo "Stopped front end" + +## stop_back: stops the back end +stop_back: + @echo "Stopping the back end..." + @-pkill -SIGTERM -f "gostripe_api -port=${API_PORT}" + @echo "Stopped back end" + diff --git a/cmd/web/main.go b/cmd/web/main.go index 07e952e..c0a87f0 100644 --- a/cmd/web/main.go +++ b/cmd/web/main.go @@ -64,6 +64,12 @@ func main() { "development", "Application environment {development|production}", ) + flag.StringVar( + &cfg.db.dsn, + "dsn", + "root@tcp(localhost:6379)/widgets?parseTime=true&tls=false", + "Application environment {development|production}", + ) flag.StringVar(&cfg.api, "api", "http://localhost:4001", "URL to api") flag.Parse()