Sha256: f5548016844273374247619113bef84582efa9ee99df42124b6060c80abb2137
Contents?: true
Size: 837 Bytes
Versions: 3
Compression:
Stored size: 837 Bytes
Contents
package handlers import ( "encoding/json" "net/http" log "github.com/Sirupsen/logrus" ) const kTagEcho = "EchoHandler" type echoHandlerDependencies struct { logger *log.Logger } // Echo uses the validation middleware to automatically validate input // github.com/asaskevich/govalidator type Echo struct { Echo string `json:"echo" valid:"stringlength(1|255),required"` } type echoHandler struct { deps echoHandlerDependencies } func (e *echoHandler) ServeHTTP(rw http.ResponseWriter, r *http.Request) { e.deps.logger.WithField(kTagEcho, "Called GET") // request is set into the context from the middleware request := r.Context().Value(validationRequestKey{}).(Echo) encoder := json.NewEncoder(rw) encoder.Encode(request) } func newEchoHandler(deps echoHandlerDependencies) http.Handler { return &echoHandler{deps} }
Version data entries
3 entries across 3 versions & 1 rubygems