File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ # Test Server
2+
3+ For a quick test of an iSpindel this tool can to print out the packets send.
4+
5+ It can be run simply with ` Golang ` build environment installed via ` go run . `
6+
7+ Configure the iSpindel with the following settings:
8+
9+ * Method: 'HTTP'
10+ * Host: <your workstation IP >
11+ * Port: 8080
12+ * Path: anything (e.g. /test)
13+
14+ ## running in a Docker container
15+
16+ * cd into the ` tools/TestServer ` directory
17+
18+ ``` bash
19+ docker run -it --rm -v $PWD :/src -p 8080:8080 golang:alpine sh -c " cd /src && go mod tidy && go run ."
20+ ```
Original file line number Diff line number Diff line change 1+ module testserver
2+
3+ go 1.16
4+
5+ require (
6+ github.com/TylerBrock/colorjson v0.0.0-20200706003622-8a50f05110d2
7+ github.com/fatih/color v1.13.0 // indirect
8+ github.com/hokaccha/go-prettyjson v0.0.0-20210113012101-fb4e108d2519 // indirect
9+ )
Original file line number Diff line number Diff line change 1+ github.com/TylerBrock/colorjson v0.0.0-20200706003622-8a50f05110d2 h1:ZBbLwSJqkHBuFDA6DUhhse0IGJ7T5bemHyNILUjvOq4 =
2+ github.com/TylerBrock/colorjson v0.0.0-20200706003622-8a50f05110d2 /go.mod h1:VSw57q4QFiWDbRnjdX8Cb3Ow0SFncRw+bA/ofY6Q83w =
3+ github.com/fatih/color v1.13.0 h1:8LOYc1KYPPmyKMuN8QV2DNRWNbLo6LZ0iLs8+mlH53w =
4+ github.com/fatih/color v1.13.0 /go.mod h1:kLAiJbzzSOZDVNGyDpeOxJ47H46qBXwg5ILebYFFOfk =
5+ github.com/hokaccha/go-prettyjson v0.0.0-20210113012101-fb4e108d2519 h1:nqAlWFEdqI0ClbTDrhDvE/8LeQ4pftrqKUX9w5k0j3s =
6+ github.com/hokaccha/go-prettyjson v0.0.0-20210113012101-fb4e108d2519 /go.mod h1:pFlLw2CfqZiIBOx6BuCeRLCrfxBJipTY0nIOF/VbGcI =
7+ github.com/mattn/go-colorable v0.1.9 h1:sqDoxXbdeALODt0DAeJCVp38ps9ZogZEAXjus69YV3U =
8+ github.com/mattn/go-colorable v0.1.9 /go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc =
9+ github.com/mattn/go-isatty v0.0.12 /go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU =
10+ github.com/mattn/go-isatty v0.0.14 h1:yVuAays6BHfxijgZPzw+3Zlu5yQgKGP2/hcQbHb7S9Y =
11+ github.com/mattn/go-isatty v0.0.14 /go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94 =
12+ golang.org/x/sys v0.0.0-20200116001909-b77594299b42 /go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs =
13+ golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae /go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs =
14+ golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c h1:F1jZWGFhYfh0Ci55sIpILtKKK8p3i2/krTr0H1rg74I =
15+ golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c /go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg =
Original file line number Diff line number Diff line change 1+ package main
2+
3+ import (
4+ "encoding/json"
5+ "fmt"
6+ "io/ioutil"
7+ "log"
8+ "net/http"
9+
10+ "github.com/TylerBrock/colorjson"
11+ )
12+
13+ func main () {
14+ fmt .Println ("Test server for iSpindle: connect to <your IP>:8080 using HTTP method" )
15+ http .HandleFunc ("/" , serve )
16+ log .Fatal (http .ListenAndServe (":8080" , nil ))
17+ }
18+
19+ func serve (w http.ResponseWriter , r * http.Request ) {
20+ var obj map [string ]interface {}
21+ fmt .Printf ("%+v\n " , r )
22+ str , err := ioutil .ReadAll (r .Body )
23+ if err != nil {
24+ log .Fatal (err )
25+ }
26+ err = json .Unmarshal ([]byte (str ), & obj )
27+ if err != nil {
28+ log .Fatal (err )
29+ }
30+ f := colorjson .NewFormatter ()
31+ f .Indent = 4
32+ s , _ := f .Marshal (obj )
33+ fmt .Println (string (s ))
34+
35+ fmt .Fprint (w , "ok" )
36+ }
You can’t perform that action at this time.
0 commit comments