Research
Security News
Malicious npm Package Targets Solana Developers and Hijacks Funds
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
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.
Research
Security News
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Security News
Research
Socket researchers have discovered malicious npm packages targeting crypto developers, stealing credentials and wallet data using spyware delivered through typosquats of popular cryptographic libraries.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.