- Extract main out of the package root and into the examples/ hierarchy.

This commit is contained in:
Matt T. Proud 2012-05-21 10:43:21 +02:00
parent 2c4784f8ee
commit a1f4f3eec2
3 changed files with 24 additions and 15 deletions

22
examples/simple/main.go Normal file
View File

@ -0,0 +1,22 @@
// Copyright (c) 2012, Matt T. Proud
// All rights reserved.
//
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// main.go provides a simple skeletal example of how this instrumentation
// framework is registered and invoked.
package main
import (
"github.com/matttproud/golang_instrumentation"
"net/http"
)
func main() {
exporter := registry.DefaultRegistry.YieldExporter()
http.Handle("/metrics.json", exporter)
http.ListenAndServe(":8080", nil)
}

13
main.go
View File

@ -1,13 +0,0 @@
package main
import (
"github.com/matttproud/golang_instrumentation/export"
"net/http"
)
func main() {
exporter := export.DefaultRegistry.YieldExporter()
http.Handle("/metrics.json", exporter)
http.ListenAndServe(":8080", nil)
}

View File

@ -7,7 +7,7 @@
// registry.go provides a container for centralization exposition of metrics to
// their prospective consumers.
package export
package registry
import (
"encoding/json"
@ -94,7 +94,7 @@ func (r *Registry) Register(name string, metric metrics.Metric) {
// Create a http.HandlerFunc that is tied to r Registry such that requests
// against it generate a representation of the housed metrics.
func (registry *Registry) YieldExporter() *http.HandlerFunc {
func (registry *Registry) YieldExporter() http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var instrumentable metrics.InstrumentableCall = func() {
requestCount.Increment()