From 0e5a46f0501c4143dde388f4e6bc4ee7c42d89c8 Mon Sep 17 00:00:00 2001 From: Drew Bednar Date: Sat, 11 Jan 2025 09:35:17 -0500 Subject: [PATCH] Basic project structure --- Makefile | 7 +++++++ README.md | 42 +++++++++++++++++++++++++++++++++++++-- cmd/ratchetd/main.go | 21 ++++++++++++++++++++ cmd/ratchetd/main_test.go | 1 + go.mod | 3 +++ ratchet.go | 8 ++++++++ 6 files changed, 80 insertions(+), 2 deletions(-) create mode 100644 Makefile create mode 100644 cmd/ratchetd/main.go create mode 100644 cmd/ratchetd/main_test.go create mode 100644 go.mod create mode 100644 ratchet.go diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..7070b2d --- /dev/null +++ b/Makefile @@ -0,0 +1,7 @@ +test: + go test -v ./... +PHONEY: test + +serve: + go run ./cmd/ratchetd/main.go +PHONEY: serve \ No newline at end of file diff --git a/README.md b/README.md index 5e8faac..a554b37 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,41 @@ -# ratchet +# Ratchet + +An example web application in Golang. + + +## Project Structure + +Loosely inspired by the organization of [WTFDial](https://github.com/benbjohnson/wtf?tab=readme-ov-file#project-structure), +- Application domain types reside in the project root (User, UserService, etc) +- Implementations of the application domain reside in the subpackages `sqlite`, `http`, etc. +- Everything is tied together in the `cmd` subpackages + + +### Application Domain + +This is project is an Indie reader inspired by [Feedi](https://github.com/facundoolano/feedi). + + +### Implementation Subpackages + +The subpackages function as an adapter between our domain and the technology used to implement the domain. For example `sqlite.FeedService` implements the `ratchet.FeedService` using SQLite. + +Subpackages ideally **SHOULD NOT** know about one another and **SHOULD** communicate in terms of the application domain. + +A special `mock` packages can be used to create simple mocks for each application domain interface. This will allow each subpackages unit tests to share a common set of mocks so layers can be tested in isolatation. + +### Binary Packages + +With loosely coupledc subpackages the application is wired together in the `cmd` subpackages to produce a final binary. + +The `cmd` packages are ultimately the interface between the application domain and the operator. Configuration of types and any CLI flags *SHOULD* live in these packages. + +## Development + +You can build `ratchet` locally by cloning the respository, then run + +`make` +`go install ./cmd/...` + +The `ratchetd` cmd binary uses Oauth so you will need to create a new Oauth App. The vlaue of the authorization callback must be the hostname and IP at which clients can access the `ratchetd` server. -An example web application in Golang. \ No newline at end of file diff --git a/cmd/ratchetd/main.go b/cmd/ratchetd/main.go new file mode 100644 index 0000000..b2b8c6e --- /dev/null +++ b/cmd/ratchetd/main.go @@ -0,0 +1,21 @@ +package main + +import ( + "fmt" + "os" + "strings" + + "git.runcible.io/learning/ratchet" +) + +var ( + version string + commit string +) + +func main() { + // Propagate build information to root package to share globally + ratchet.Version = strings.TrimPrefix(version, "") + ratchet.Commit = commit + fmt.Fprintf(os.Stdout, "Version: %s\nCommit: %s\n", ratchet.Version, ratchet.Commit) +} diff --git a/cmd/ratchetd/main_test.go b/cmd/ratchetd/main_test.go new file mode 100644 index 0000000..06ab7d0 --- /dev/null +++ b/cmd/ratchetd/main_test.go @@ -0,0 +1 @@ +package main diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..f5929ae --- /dev/null +++ b/go.mod @@ -0,0 +1,3 @@ +module git.runcible.io/learning/ratchet + +go 1.23.3 diff --git a/ratchet.go b/ratchet.go new file mode 100644 index 0000000..6dfd241 --- /dev/null +++ b/ratchet.go @@ -0,0 +1,8 @@ +package ratchet + +// Build version and commit SHA. + +var ( + Version string + Commit string +)