gohttp

command module
v0.0.0-...-3d9cc79 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 10, 2018 License: MIT Imports: 5 Imported by: 0

README

HTTP Server for Go Build Status

This is an HTTP server for Go.

Requirements

This is being developed on Go 1.10, 64-bit.

Installation

Install Go 1.10 with their installer, or with brew install go if you use homebrew.

Set up Go environment

Go recommends following a few conventions on setting up your environment

  • Set GOPATH. You can set it to the value from go env GOPATH, if you're not sure of the conventional path on your system.
  • Add Go binaries to your system path. I recommend putting the following into your startup scripts (.bash_profile et al)
go version >/dev/null 2>&1
if (( $? == 0 ))
then
  export PATH="$PATH:$(go env GOPATH)/bin"
fi
Install support tools

This installs goimports for formatting and organizing imports and ginkgo for spec-style testing.

$ go get github.com/onsi/ginkgo/ginkgo
$ go get golang.org/x/tools/cmd/goimports

When you are done, GOPATH/bin should contain ginkgo and goimports.
which ginkgo and which goimports should then work if the binaries are installed and present in your PATH.

Clone this repository
$ cd $(go env GOPATH)
$ mkdir src
$ cd src
$ git clone git@github.com:kkrull/gohttp.git
Set up pre-push hook

Set up a Git hook to double check that code is formatted and imports are sorted/curated before pushing.

$ cp bin/pre-push .git/hooks/pre-push

Running

From the path where you cloned this repository:

$ go get -t -u -v
$ go build
$ ./gohttp -p <port> -d <content root directory>

Note that if you build and run this with go run, it will not handle SIGTERM from Ctrl+C correctly.

When you want to exit the server, press Ctrl+C.

Linting

Install gometalinter

$ go get -u gopkg.in/alecthomas/gometalinter.v2

which - if you set up your path correctly in the earlier steps - places gometalinter.v2 in your PATH. Run the linters configured in .gometalinter.json with gometalinter.v2 ./... in the base of this repository.

Testing

$ go get -t #Download dependencies, including those used by tests
$ ginkgo -r #Run tests in all packages

Continuous Integration happens on Travis CI. See .travis.yml in this repository for details in the CI environment and how the tests are run.

Additional testing is performed by a version of cob_spec that has been configured to start/stop this server. This version of cob_spec can be found on GitHub.

Support scripts

A few steps of the development process are being automated, as the project takes shape. These are located in the bin/ directory:

  • bin/build-and-start.sh: Re-builds the local binary gohttp and runs it. Pass it the same options you would if you were running gohttp directly.
  • bin/update-dependencies.sh: Updates all Go libraries in your GOPATH and runs tests to make sure everything still works. Note that this repository's current branch must have an upstream branch, for this to work.

Developer notes

cob_spec Nuances

If gohttp goes down, cob_spec will:

  • take about 30 seconds to time out
  • fail all tests after the process went down (this may not be exactly after the failed test, due to potential timing, concurrency, and synchronization issues)
  • swallow any output that was given to the console

If cob_spec fails in strange ways where it looked like it was working before...:

  • Try the request in cURL
  • Make sure there are no panics
TCP Traffic

When the server just listens, accepts, and closes a connection.

$ ./gohttp -p 1234 -d ... #Server
$ netcat -vz -4 localhost 1234 #Client

Packet sniffing

$ tcpdump -D #Show interfaces; find localhost
$ tcpdump -i <interface> -s 0 -w gohttp--netcat-4.pcap #Capture
$ tcpdump -4 <file> #View file

There's also curl --trace <hex as ascii dump file> ...

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis
Handles requests about generic capabilities of the server Any requests specific to a resource are handled by that resource's Route.
Handles requests about generic capabilities of the server Any requests specific to a resource are handled by that resource's Route.
HTTP requests and responses that work with files on the server's file system
HTTP requests and responses that work with files on the server's file system
An HTTP server that manages connections and parses HTTP request messages into executable requests
An HTTP server that manages connections and parses HTTP request messages into executable requests
Testing related to the http package
Testing related to the http package
Access to request logs
Access to request logs
main
cmd
The "main" package, that does command-line parsing and application initialization
The "main" package, that does command-line parsing and application initialization
msg
Generic HTTP responses that aren't specific to any particular type of request
Generic HTTP responses that aren't specific to any particular type of request
clienterror
HTTP 4xx Client Error responses from RFC 7231, Section 6.5
HTTP 4xx Client Error responses from RFC 7231, Section 6.5
servererror
HTTP 5xx Server Error responses from RFC 7231, Section 6.6
HTTP 5xx Server Error responses from RFC 7231, Section 6.6
success
HTTP 2xx Successful responses from RFC 7231, Section 6.3
HTTP 2xx Successful responses from RFC 7231, Section 6.3
Routes that don't serve much of a practical purpose, short of giving cob_spec an endpoint it needs to play with the server's features.
Routes that don't serve much of a practical purpose, short of giving cob_spec an endpoint it needs to play with the server's features.
A route for how a teapot should behave, under RFC 2324
A route for how a teapot should behave, under RFC 2324

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL