diff --git a/example/go.mod b/example/go.mod deleted file mode 100644 index 426492d..0000000 --- a/example/go.mod +++ /dev/null @@ -1,9 +0,0 @@ -module github.com/mikehelmick/go-chaff/example - -go 1.14 - -require ( - github.com/gorilla/handlers v1.4.2 - github.com/gorilla/mux v1.7.4 - github.com/mikehelmick/go-chaff v0.2.1 -) diff --git a/example/go.sum b/example/go.sum deleted file mode 100644 index fc748f9..0000000 --- a/example/go.sum +++ /dev/null @@ -1,10 +0,0 @@ -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= -github.com/gorilla/handlers v1.4.2 h1:0QniY0USkHQ1RGCLfKxeNHK9bkDHGRYGNDFBCS+YARg= -github.com/gorilla/handlers v1.4.2/go.mod h1:Qkdc/uu4tH4g6mTK6auzZ766c4CA0Ng8+o/OAirnOIQ= -github.com/gorilla/mux v1.7.4 h1:VuZ8uybHlWmqV03+zRzdwKL4tUnIp1MAQtp1mIFE1bc= -github.com/gorilla/mux v1.7.4/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So= -github.com/mikehelmick/go-chaff v0.2.0 h1:A9HJIcsqkR3uN1VNLZs9cRVApPOkYc7Jy76LnXQ7bvY= -github.com/mikehelmick/go-chaff v0.2.0/go.mod h1:mFry3zNW17oxNGmZpQV3PEOmzTNyly3nLDYawCT/iCE= -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= diff --git a/example/main.go b/example/main.go index ea6482b..ef3f8b3 100644 --- a/example/main.go +++ b/example/main.go @@ -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 ( @@ -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" ) @@ -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) @@ -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) diff --git a/go.mod b/go.mod index 12d0ad2..ad72db3 100644 --- a/go.mod +++ b/go.mod @@ -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 diff --git a/go.sum b/go.sum index 50d0e6f..62841cd 100644 --- a/go.sum +++ b/go.sum @@ -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=