本文整理汇总了Golang中github.com/ant0ine/go-json-rest/rest.Request.BaseUrl方法的典型用法代码示例。如果您正苦于以下问题:Golang Request.BaseUrl方法的具体用法?Golang Request.BaseUrl怎么用?Golang Request.BaseUrl使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/ant0ine/go-json-rest/rest.Request
的用法示例。
在下文中一共展示了Request.BaseUrl方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: sendRegistrationResponse
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)
}
}
示例2: Detail
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)
}