Security News
The Risks of Misguided Research in Supply Chain Security
Snyk's use of malicious npm packages for research raises ethical concerns, highlighting risks in public deployment, data exfiltration, and unauthorized testing.
github.com/clarenceb/jokes_api_golang
This is a basic example of a RESTful API which serves jokes from the internet and a commandline client to make requesting jokes easier.
This is my first ever Go program so its probably not going to be idiomatic Go lang and not a good example of a "real life" API.
The main purpose is for me to try out some of the Go concepts I have learnt about in a Tour of Go and a starting point for a Go lang Dojo at work.
The code will only use packages from the standard library.
Install Go compiler and tools: https://golang.org/doc/install
On Mac OS X, you can use Homebrew:
brew install go
Prepare your Go workspace and set your GOPATH:
$ mkdir -p $HOME/go/{src,pkg,bin}
$ export GOPATH=$HOME/go
$ echo "export GOPATH=$HOME/go" >> ~/.bashrc
Read more about Go lang workspaces.
Fetch this project into your Go workspace:
$ cd $GOPATH
$ go get github.com/clarenceb/jokes_api_golang
# Build the server
cd $GOPATH/src/github.com/clarenceb/jokes_api/server
go build
# Run the server (on port localhost:8080)
./server
# Test server with curl:
curl -H "Accept: application/json" http://localhost:8080/joke
# => {"joke":"Chuck Norris finished World of Warcraft."}
# Build the client
cd $GOPATH/src/github.com/clarenceb/jokes_api/client
go build
# View usage
./client --help
# Fetch one joke
./client
# => 1: Chuck Norris finished World of Warcraft.
# Fetch multiple jokes
./client -n 2
# => 1: No one has ever spoken during review of Chuck Norris' code and lived to tell about it.
# => 2: Chuck Norris once ate four 30lb bowling balls without chewing.
# Fetch multiple jokes concurrently
./client -n 2 -c
# => 2: Chuck Norris once ate four 30lb bowling balls without chewing.
# => 1: No one has ever spoken during review of Chuck Norris' code and lived to tell about it.
# You can time synchronous vs. concurrent requests like so:
time ./client -n 10
# => real 0m3.681s
time ./client -n 10 -c
# => real 0m0.846s
jokes_api/server
Demonstrates:
jokes_api/client
Demonstrates:
testing
package and HTTP testing with net/http/httptest
packageThe MIT License (MIT)
Copyright (c) 2014 Clarence Bakirtzidis
(see LICENSE file for details)
FAQs
Unknown package
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Snyk's use of malicious npm packages for research raises ethical concerns, highlighting risks in public deployment, data exfiltration, and unauthorized testing.
Research
Security News
Socket researchers found several malicious npm packages typosquatting Chalk and Chokidar, targeting Node.js developers with kill switches and data theft.
Security News
pnpm 10 blocks lifecycle scripts by default to improve security, addressing supply chain attack risks but sparking debate over compatibility and workflow changes.