草庐IT

REST-ful

全部标签

rest - 如何在渲染到 jSON 之前将 Golang 结构的字段修改为另一种类型?

我们正在我们的API中添加一个包含参数w/cAPI客户端可以用来包含关系//requestGET/api/events?include=team1[{"id":,"name":,"team1":{"id":,"name":}}]//codetypeEventstruct{IDint64`gorm:"primary_key"json:"id"`Team1IDint64`json:"-"`Team1Team`json:"team1"`}vareventEventDb.Preload("Team1").Find(&event,1)c.JSON(http.StatusOK,event)但我们也

rest - 如何在 Go HTTP 服务器中有条件地设置 HTTP 状态代码?

我有以下HTTP处理函数:func(h*UptimeHttpHandler)CreateSchedule(whttp.ResponseWriter,r*http.Request){deferr.Body.Close()dec:=json.NewDecoder(r.Body)varreqScheduleRequestiferr:=dec.Decode(&req);err!=nil{//errorhandlingomited}result,err:=saveToDb(req)iferr!=nil{//errorhandlingomited}//Respondingwith201-Creat

rest - 如何在 Go HTTP 服务器中有条件地设置 HTTP 状态代码?

我有以下HTTP处理函数:func(h*UptimeHttpHandler)CreateSchedule(whttp.ResponseWriter,r*http.Request){deferr.Body.Close()dec:=json.NewDecoder(r.Body)varreqScheduleRequestiferr:=dec.Decode(&req);err!=nil{//errorhandlingomited}result,err:=saveToDb(req)iferr!=nil{//errorhandlingomited}//Respondingwith201-Creat

json - 将复杂的 JSON 解析为 goweb REST Create() 函数

我提前为一个非常的长问题道歉。希望您能多多包涵。我正在使用goweb库,并尝试使用examplewebapp.我一直在尝试修改RESTfulexamplecode,它定义了一个Thing作为:typeThingstruct{IdstringTextstring}一个Thing是通过发送一个HTTPPost请求和一个适当的JSON主体到http://localhost创建的:9090/事物。这在Createfunction中的示例代码中处理。,特别是行:dataMap:=data.(map[string]interface{})thing:=new(Thing)thing.Id=data

json - 将复杂的 JSON 解析为 goweb REST Create() 函数

我提前为一个非常的长问题道歉。希望您能多多包涵。我正在使用goweb库,并尝试使用examplewebapp.我一直在尝试修改RESTfulexamplecode,它定义了一个Thing作为:typeThingstruct{IdstringTextstring}一个Thing是通过发送一个HTTPPost请求和一个适当的JSON主体到http://localhost创建的:9090/事物。这在Createfunction中的示例代码中处理。,特别是行:dataMap:=data.(map[string]interface{})thing:=new(Thing)thing.Id=data

rest - Soundcloud API Auth 通过 Golang 401 错误

我正在尝试连接到SoundcloudAPI并在Golang中获取token,但我收到401errr消息,“error”:“invalid_client”。我已经验证了客户端ID和密码。我的重定向URI存在并且是:http://localhost:8080/platform/soundcloudCallback.html我的代码如下:funcmain(){v:=url.Values{}v.Set("scope","non-expiring")v.Set("client_id",auth.ClientID)v.Set("response_type","code")v.Set("redire

rest - Soundcloud API Auth 通过 Golang 401 错误

我正在尝试连接到SoundcloudAPI并在Golang中获取token,但我收到401errr消息,“error”:“invalid_client”。我已经验证了客户端ID和密码。我的重定向URI存在并且是:http://localhost:8080/platform/soundcloudCallback.html我的代码如下:funcmain(){v:=url.Values{}v.Set("scope","non-expiring")v.Set("client_id",auth.ClientID)v.Set("response_type","code")v.Set("redire

json - 有没有更简单的方法来使用 net/http 实现 JSON REST 服务?

我正在尝试使用net/http开发一个REST服务。服务接收包含所有输入参数的JSON结构。我想知道是否有更简单、更短的方法来实现以下内容:funccall(whttp.ResponseWriter,r*http.Request){iferr:=r.ParseForm();err!=nil{fmt.Printf("Errorparsingrequest%s\n",err)}varbuf[]bytebuf=make([]byte,256)varn,err=r.Body.Read(buf)vardecodedmap[string]interface{}err=json.Unmarshal(

json - 有没有更简单的方法来使用 net/http 实现 JSON REST 服务?

我正在尝试使用net/http开发一个REST服务。服务接收包含所有输入参数的JSON结构。我想知道是否有更简单、更短的方法来实现以下内容:funccall(whttp.ResponseWriter,r*http.Request){iferr:=r.ParseForm();err!=nil{fmt.Printf("Errorparsingrequest%s\n",err)}varbuf[]bytebuf=make([]byte,256)varn,err=r.Body.Read(buf)vardecodedmap[string]interface{}err=json.Unmarshal(

rest - 当我尝试使用 Instagram API 连接到 oauth2.0 时,我从 api.instagram.com 返回了 400 - Bad Result。为什么?

这是我在golang中连接到instagramapi的代码ifresp,err:=http.PostForm("https://api.instagram.com/oauth/access_token",url.Values{"client_secret":{appSecret},"grant_type":{"authorization_code"},"redirect_uri":{redirectUri},"client_id":{appId},"code":{code},});err==nil{log.Info("%s",resp)}else{return500,ctr.Error