examples/
directoryThis package is not in the latest version of its module.
Details
Validgo.mod file
The Go module system was introduced in Go 1.11 and is the official dependency management solution for Go.
Redistributable license
Redistributable licenses place minimal restrictions on how software can be used, modified, and redistributed.
Tagged version
Modules with tagged versions give importers more predictable builds.
Stable version
When a project reaches major version v1 it is considered stable.
- Learn more about best practices
Repository
Links
README¶
Machine Examples
Higher level examples using the machine
gRPC Bidirectional Chat Server
- (~ 300 lines)
Design
- clients join a channel with a single request that starts streaming from os.Stdin -> chat server
- messages sent to a channel are broadcasted to all client's that are listening to that channel
- Protobuf API
- Implementation
Start Server
go run chat/server/main.go --port 9000Start Client
In one terminal:
go run chat/client/main.go --channel accounting --target localhost:9000In a second terminal:
go run chat/client/main.go --channel accounting --target localhost:9000now start typing in either terminal, messages should be broadcasted to both terminals since they are bothsubscribed to the accounting channel.
TCP Reverse Proxy
(~ 150 lines)
straight up transparent reverse proxy
zero dependencies besides logger
go run reverse-proxy/main.go --port 5000 --target $(upstream ip address/port)
Test proxy:
curl $(local proxy)Concurrent Cron Server
(~ 150 lines)
zero dependencies besides logger
execute any number of shell scripts in separate threads, each with their own timer
config file to hold cron job configuration
every cron is cleaned up when the parent goroutine is cancelled/times out
get crons via http GET request to /cron
add cron at runtime via http POST request to /cron/job
example config:
name: "example"jobs: - name: "hello world" sleep: "1s" script: | echo "hello world" - name: "hello world 2" sleep: "1s" script: | echo "hello world 2"Start Cron Server
go run cron/main.go --config cron/cron.yaml --port 8000Get Cron Jobs
curl -X GET http://localhost:8000/cronAdd Cron Job
curl -L -X POST 'http://localhost:8000/cron/job' \-H 'Content-Type: application/json' \--data-raw '{ "name": "whoami", "script": "whoami", "sleep": "5s"}'