lib/generators/gomicroservice/scaffold/handlers/health.go.erb in minke-generator-go-0.1.0 vs lib/generators/gomicroservice/scaffold/handlers/health.go.erb in minke-generator-go-0.4.0
- old
+ new
@@ -1,10 +1,11 @@
package handlers
import (
"encoding/json"
"net/http"
+ "log"
"<%= namespace %>/<%= application_name %>/logging"
)
// This is not particularlly a real world example it mearly shows how a builder or a factory could be injected
@@ -29,22 +30,27 @@
SingletonBuilder *HealthResponseBuilder `inject:""`
// statsD interface must use a name type as injection cannot infer ducktypes
Stats logging.StatsD `inject:"statsd"`
+ // reference to the log writer
+ Log *log.Logger `inject:""`
+
// if not specified in the graph will automatically create private instance
PrivateBuilder *HealthResponseBuilder `inject:"private"`
}
type HealthResponse struct {
StatusMessage string `json:"status_message"`
}
var HealthDependencies *HealthDependenciesContainer = &HealthDependenciesContainer{}
+const HHTAGNAME = "HealthHandler: "
func HealthHandler(rw http.ResponseWriter, r *http.Request) {
// all HealthHandlerDependencies are automatically created by injection process
HealthDependencies.Stats.Increment(HEALTH_HANDLER + GET + CALLED)
+ HealthDependencies.Log.Printf("%v Called GET\n", HHTAGNAME)
response := HealthDependencies.SingletonBuilder.SetStatusMessage("OK").Build()
encoder := json.NewEncoder(rw)
encoder.Encode(&response)