Build a Full‑Featured Enterprise Go Application in 3 Steps with osbuilder
This guide shows how to use the osbuilder scaffold to quickly generate a complete enterprise‑grade Go project—including a web server, async job server, message‑queue server, and CLI tool—by configuring a YAML file, adding resources, and implementing business logic.
Why Use osbuilder for Enterprise Go Projects?
In enterprise application development the most common workloads are web services and asynchronous job services, while command‑line tools, message‑processing services, and WebSocket servers are also frequently needed. A scaffold that can generate high‑quality source code with a single command and later add resources dynamically dramatically improves development efficiency and code quality. The osbuilder scaffold fulfills this need by standardising and automating repetitive tasks.
Example: Creating a Feature‑Complete MiniBlog Application
The example project, miniblog, provides the following components:
Web server offering blog APIs
Asynchronous job server that reads the database and processes records
Message‑processing server that consumes Kafka messages and stores results
Command‑line tool similar to kubectl for operational tasks
Additional REST resources or commands can be added later, and osbuilder supports convenient addition of new resources.
Three‑Step Workflow
Generate the project source code
Add REST resources and commands
Develop business logic
Step 1: Generate Project Source Code
Create a configuration file miniblog.yaml that defines the scaffold version, module path, deployment method, Docker settings, storage type, and which services to generate. A trimmed example:
scaffold: osbuilder
version: v0.14.3
metadata:
# Go module path (must be under $GOPATH/src/...)
modulePath: github.com/onexstack/miniblog
shortDescription: Please update the short description of the binary file.
longMessage: Please update the detailed description of the binary file.
deploymentMethod: docker
registryPrefix: docker.io/colin404
dockerfileMode: combined
distrolessMode: auto
makefileMode: unstructured
author: 孔令飞
email: [email protected]
webServers:
- binaryName: mb-apiserver
webFramework: gin
storageType: memory
withHealthz: true
withUser: false
withOTel: true
withWS: true
serviceRegistry: none
withPreloader: true
jobServers:
- binaryName: mb-jobserver
storageType: memory
withOTel: true
withPreloader: true
disableCronJob: true
mqServers:
- binaryName: mb-mqserver
mqFramework: kafka
storageType: memory
withOTel: true
withPreloader: true
cliTools:
- binaryName: mbctlRun the following command to generate the full source tree:
$ osbuilder create project -c miniblog.yaml miniblogCompile the generated code using the Makefile:
$ cd miniblog
$ make deps # optional, install missing tools
$ go get cloud.google.com/go/compute@latest
$ go get cloud.google.com/go/compute/metadata@latest
$ make protoc # compile protobuf files
$ go mod tidy # tidy dependencies
$ go generate ./... # run go:generate directives
$ make build # build all binariesThe compiled binaries are placed under miniblog/_output/platforms/linux/amd64/.
Step 2: Add REST Resources and Commands
After the initial generation the services contain no domain resources. Use osbuilder to add them dynamically:
# Define the resource kinds
kinds="post,comment,tag,follow,follower,friend,block,like,bookmark,share,report,vote"
# Add API resources to the web server
osbuilder create api --kinds $kinds
# Add asynchronous jobs for each kind
osbuilder create job --kinds $kinds
# Add Kafka message handling for each kind
osbuilder create mq --kinds $kinds
# Add corresponding CLI commands
osbuilder create cmd --kinds $kindsRe‑compile the updated components:
$ make protoc
$ go mod tidy
$ make buildRun the binaries with their configuration files, for example:
$ _output/platforms/linux/amd64/mb-apiserver -c configs/mb-apiserver.yaml
$ _output/platforms/linux/amd64/mb-jobserver -c configs/mb-jobserver.yaml
$ _output/platforms/linux/amd64/mb-mqserver -c configs/mb-mqserver.yamlInspect the generated CLI commands: $ _output/platforms/linux/amd64/mbctl -h Sample output shows commands such as post, comment, vote, etc.
Step 3: Develop Business Logic
Modify files under internal/apiserver/biz/v1/ to implement API‑side logic.
Modify files under internal/jobserver/watcher/customized/ for job‑server logic.
Modify files under internal/mqserver/biz/v1/ for message‑server logic.
Modify files under internal/mbctl/cmd/ to implement CLI command behavior.
Code Statistics
The generated code follows a consistent architecture and style, making it highly maintainable and suitable for learning.
Quick‑Start One‑Liner
osbuilder also provides a shortcut to generate the entire project with a single command:
$ osbuilder create quickstartGo Programming World
Mobile version of tech blog https://jianghushinian.cn/, covering Golang, Docker, Kubernetes and beyond.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
