Initial structure

Signed-off-by: Marcus Noble <github@marcusnoble.co.uk>
This commit is contained in:
2025-05-02 13:22:49 +01:00
parent 71fccf0ddf
commit 866cbaa42f
6 changed files with 66 additions and 28 deletions

View File

@@ -0,0 +1,13 @@
FROM golang:1.24-alpine AS builder
RUN apk update && apk add --no-cache git && apk add -U --no-cache ca-certificates
WORKDIR /app/
ADD go.mod go.sum ./
RUN go mod download
ADD . .
RUN GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -ldflags="-w -s" -o next-book .
FROM scratch
WORKDIR /app/
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
COPY --from=builder /app/next-book /app/next-book
ENTRYPOINT ["/app/next-book"]

View File

@@ -7,43 +7,27 @@ test: lint check-format run-tests
.PHONY: lint # Perform lint checks against code .PHONY: lint # Perform lint checks against code
lint: lint:
@echo "⚠️ 'lint' unimplemented" @go vet && golint -set_exit_status ./...
# GO Projects
# @go vet && golint -set_exit_status ./...
.PHONY: check-format # Checks code formatting and returns a non-zero exit code if formatting errors found .PHONY: check-format # Checks code formatting and returns a non-zero exit code if formatting errors found
check-format: check-format:
@echo "⚠️ 'check-format' unimplemented" @gofmt -e -l .
# GO Projects
# @gofmt -e -l .
.PHONY: format # Performs automatic format fixes on all code .PHONY: format # Performs automatic format fixes on all code
format: format:
@echo "⚠️ 'format' unimplemented" @gofmt -s -w .
# GO Projects
# @gofmt -s -w .
.PHONY: run-tests # Runs all tests .PHONY: run-tests # Runs all tests
run-tests: run-tests:
@echo "⚠️ 'run-tests' unimplemented" @go test
# GO Projects
# @go test
# Node Projects
# @npm test
.PHONY: fetch-deps # Fetch all project dependencies .PHONY: fetch-deps # Fetch all project dependencies
fetch-deps: fetch-deps:
@echo "⚠️ 'fetch-deps' unimplemented" @go mod tidy
# GO Projects
# @go mod tidy
# Node Projects
# @npm install
.PHONY: build # Build the project .PHONY: build # Build the project
build: lint check-format fetch-deps build: lint check-format fetch-deps
@echo "⚠️ 'build' unimplemented" @go build -o PROJECT_NAME main.go
# GO Projects
# @go build -o PROJECT_NAME main.go
.PHONY: docker-build # Build the docker image .PHONY: docker-build # Build the docker image
docker-build: docker-build:
@@ -55,11 +39,7 @@ docker-publish:
.PHONY: run # Run the application .PHONY: run # Run the application
run: run:
@echo "⚠️ 'run' unimplemented" @go run main.go
# GO Projects
# @go run main.go
# Node Projects
# @npm start
.PHONY: ci # Perform CI specific tasks to perform on a pull request .PHONY: ci # Perform CI specific tasks to perform on a pull request
ci: ci:

View File

@@ -1,6 +1,6 @@
# next-book # next-book
Checks the users Storygraph "to read" list and shows the highest rated in various catergories.
## Features ## Features

5
go.mod Normal file
View File

@@ -0,0 +1,5 @@
module nextbook
go 1.24.0
require github.com/joho/godotenv v1.5.1

2
go.sum Normal file
View File

@@ -0,0 +1,2 @@
github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0=
github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=

38
main.go Normal file
View File

@@ -0,0 +1,38 @@
package main
import (
"fmt"
"net/http"
"os"
"github.com/joho/godotenv"
)
var (
port string
)
func init() {
godotenv.Load(os.Getenv("DOTENV_DIR") + ".env")
var ok bool
port, ok = os.LookupEnv("PORT")
if !ok {
port = "8000"
}
}
func main() {
go updateWorker()
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusBadRequest)
})
http.ListenAndServe(fmt.Sprintf(":%s", port), nil)
}
func updateWorker() {
// TODO: Update worker
}