Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 0 additions & 9 deletions example/go.mod

This file was deleted.

10 changes: 0 additions & 10 deletions example/go.sum

This file was deleted.

21 changes: 6 additions & 15 deletions example/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,13 @@
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package main

import (
Expand All @@ -20,12 +19,9 @@ import (
"log"
"math/big"
"net/http"
"os"
"strings"
"time"

"github.com/gorilla/handlers"
"github.com/gorilla/mux"
"github.com/mikehelmick/go-chaff"
)

Expand All @@ -38,17 +34,13 @@ func randInt(s int) (int64, error) {
}

func main() {
r := mux.NewRouter()
r := http.NewServeMux()

track := chaff.New()
defer track.Close()

{
// Create a submodule
sub := r.PathPrefix("").Subrouter()
// Install the chaff tracker middleware.
sub.Use(track.Track)
sub.Handle("/", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
r.Handle("/", track.Track(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
sleep, err := randInt(1000)
if err != nil {
w.WriteHeader(http.StatusInternalServerError)
Expand All @@ -61,17 +53,16 @@ func main() {
w.WriteHeader(http.StatusOK)
fmt.Fprintf(w, "Slept %v ms, some data below\n", sleep)
w.Write([]byte(strings.Repeat("a", int(sleep))))
})).Methods("GET")
})))
}

{
sub := r.PathPrefix("/chaff").Subrouter()
// The tracker itself is an HTTP handler, so just install on the chaff path.
sub.Handle("", track).Methods("GET")
r.Handle("/chaff", track)
}

srv := &http.Server{
Handler: handlers.CombinedLoggingHandler(os.Stdout, r),
Handler: r,
Addr: "0.0.0.0:8080",
}
log.Printf("Listening on :%v", 8080)
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module github.com/mikehelmick/go-chaff

go 1.14
go 1.19

require github.com/google/go-cmp v0.5.0
require github.com/google/go-cmp v0.5.9
6 changes: 2 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
github.com/google/go-cmp v0.5.0 h1:/QaMHBdZ26BB3SSst0Iwl10Epc+xhTquomWX0oZEB6w=
github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=