Beispiel #1
0
// Performs validation and combines errors from validation
// with errors from deserialization, then maps both the
// resulting struct and the errors to the context.
func validateAndMap(obj reflect.Value, context martini.Context, errors *Errors, ifacePtr ...interface{}) {
	context.Invoke(Validate(obj.Interface()))
	errors.combine(getErrors(context))
	context.Map(*errors)
	context.Map(obj.Elem().Interface())
	if len(ifacePtr) > 0 {
		context.MapTo(obj.Elem().Interface(), ifacePtr[0])
	}
}
Beispiel #2
0
func reqHelperMiddleware(c martini.Context, req *http.Request, w http.ResponseWriter, r render.Render, conf *Config) {
	rh := &reqHelper{
		Render:         r,
		ResponseWriter: w,
		req:            req,
		conf:           conf,
	}

	rh.session, _ = conf.SessionStore.Get(req, "session")

	c.MapTo(rh, (*RequestHelper)(nil))
}
Beispiel #3
0
func connectHostMiddleware(c martini.Context, params martini.Params, cl clusterClient, r ResponseHelper) {
	hostID, jobID := parseJobID(params["jobs_id"])
	if hostID == "" {
		log.Printf("Unable to parse hostID from %q", params["jobs_id"])
		r.Error(ErrNotFound)
		return
	}
	params["jobs_id"] = jobID

	client, err := cl.DialHost(hostID)
	if err != nil {
		r.Error(err)
		return
	}
	c.MapTo(client, (*cluster.Host)(nil))

	c.Next()
	client.Close()
}
Beispiel #4
0
func responseHelperHandler(c martini.Context, w http.ResponseWriter, r render.Render) {
	c.MapTo(&responseHelper{w, r}, (*ResponseHelper)(nil))
}