Example #1
0
func (routes *Routes) sendRegistrationResponse(w rest.ResponseWriter, r *rest.Request, sir *store.ServiceInstance) {
	routes.logger.WithFields(log.Fields{
		"namespace": r.Env["REMOTE_USER"],
	}).Infof("Instance %s registered", sir)

	ttl := uint32(sir.TTL / time.Second)
	linksURL := r.BaseUrl()
	if middleware.IsUsingSecureConnection(r) { // request came in over a secure connection, continue using it
		linksURL.Scheme = "https"
	}

	links := BuildLinks(linksURL.String(), sir.ID)
	instance := &ServiceInstance{
		ID:    sir.ID,
		TTL:   ttl,
		Links: links,
	}

	w.Header().Set("Location", links.Self)
	w.WriteHeader(http.StatusCreated)

	if err := w.WriteJson(instance); err != nil {
		routes.logger.WithFields(log.Fields{
			"namespace": r.Env["REMOTE_USER"],
			"error":     err,
		}).Warnf("Failed to write registration response for instance %s", sir)

		i18n.Error(r, w, http.StatusInternalServerError, i18n.ErrorEncoding)
	}
}
Example #2
0
func (a *Accounts) Detail(w rest.ResponseWriter, r *rest.Request) {
	account := &Account{}
	result := a.Db.First(&account, "username = ?", r.PathParam("username"))

	if result.RecordNotFound() {
		rest.NotFound(w, r)
		return
	}

	resource := &AccountResource{}

	context := map[string]interface{}{"base_url": r.BaseUrl()}

	deepcopier.Copy(account).WithContext(context).To(resource)

	w.WriteJson(&resource)
}