草庐IT

REST-Web

全部标签

go - 在 rest api 中使用 goroutine - 出现未定义的错误

我正在学习GO,想做一个简单的restAPI。我想做的是在处理完api请求后触发一个goroutine,并在后台异步完成工作。到目前为止,这是我的实现:packagemainimport("encoding/json""log""net/http""github.com/julienschmidt/httprouter")//APIResponserepresentscommonstructureofeveryapicallresponsetypeAPIResponsestruct{Statusstring`json:"status"`Errorstring`json:"error,o

amazon-web-services - 如何将 S3 数据加载到本地内存,而不是保存到文件

这个问题在这里已经有了答案:Howtokeepfilesinmemory-transferringfilesbetweenserverswithoutstoringthemlocally(1个回答)关闭4年前。这是我当前的代码:import("time""reflect""io/ioutil""fmt""os""github.com/golang/protobuf/proto""github.com/aws/aws-sdk-go/service/s3""github.com/aws/aws-sdk-go/service/s3/s3manager""github.com/aws/aws-

amazon-web-services - aws xray 和 golang http 调用

我正在尝试在我的go应用程序上使用awxxray来调用http服务。我只是跟着这个,不确定我是否错过了什么,https://docs.aws.amazon.com/xray/latest/devguide/xray-sdk-go-httpclients.html我像这样进行http调用:payloadStr,_:=json.Marshal(dxPayload)fmt.Println("size:",int(unsafe.Sizeof(bytes.NewBuffer(payloadStr))))clambda=&http.Client{}//-------ADDEDXRAYHERE---

amazon-web-services - 使用无服务器调用函数时传递 JSON

我正在使用无服务器运行一个用Go编写的lambda函数,我想在它被调用时向它传递几个参数。这是我为接收请求而创建的结构:typeRequestStructstruct{StartAtint`json:"startAt"`EndAtint`json:"endAt"`}在处理程序中,我试图打印出值:funcHandler(ctxcontext.Context,requestRequestStruct)(Response,error){fmt.Printf("Request:%v",request)我尝试使用--raw选项调用它,所以我尝试这样做serverlessinvoke-forder

amazon-web-services - 通过 Lambda 传递 Cloudwatch 数据 - Golang

我正在努力实现以下目标:Lambda由Cloudwatch警报触发Lambda查看Cloudwatch收到的数据,并根据NewStateValue决定要做什么如果需要,Lambda将触发另一个SNS,将所有Cloudwatch数据发送到OpsGenie我卡在了第三步。我可以通过手动指定来传递一些数据,但是,是否有一个函数可以将Lambda接收到的所有JSON传递到下一个SNS?我有SNS、CloudWatch警报和CloudWatch警报的消息部分的JSON。packagemainimport("context""fmt""encoding/json""github.com/aws/a

rest - golang gorilla/mux 和 rest GET 问题

我的删除处理程序:(我正在使用“github.com/gorilla/mux”)funcDeletePerson(whttp.ResponseWriter,r*http.Request){params:=mux.Vars(r)item:=params["id"]fmt.Println("Item=",item)...当被以下curl命令调用时返回Item="2":curl-XDELETEhttp://localhost:8000/address/2但是,我的测试代码:funcTestDeletePerson(t*testing.T){person:=&Person{UniqID:"2"

rest - 如何使用 Golang 实现导入数据功能?

我有2个方法,用于GET和POST。第一个是:varJoinmap[string]intfuncMapTheFields(c*gin.Context){vardata[]string//OpenthecsvfilecsvFile,_:=os.Open("customers.csv")reader:=csv.NewReader(csvFile)line,_:=reader.ReadAll()fori:=0;i第二个也和第一个类似。它只是将值保存到数据库中。我一直面临的问题是,我必须将从csv文件中获取的字段映射到我项目中的字段,为此我制作了一个名为Join的映射如上所示,我正在访问第二个

json - 解析 REST API 响应

我是golang的新手。我正在编写一个程序来解析API的json响应:https://httpbin.org/get.我使用以下代码来解析响应:packagemainimport("encoding/json""fmt""net/http""os")typeHeadersstruct{Closestring`json:"Connection"`Acceptstring`json:"Accept"`}typeapiResponsestruct{HeaderHeaders`json:"headers"`URLstring`json:"url"`}funcmain(){apiRoot:="h

docker - 从 Golang-Web 服务器控制 Docker

我正在寻找一种方法来从golang-webserver控制服务器上的docker-containers。到目前为止,我找到了“github.com/docker/docker/client”和“docker.io/go-docker”。我猜它们都做同样的事情,但它们都没有像样的文档或示例可供使用。有人对这些库有任何经验吗? 最佳答案 https://godoc.org/github.com/docker/docker/client文档对我来说看起来不错。有关更多示例,请查看我的项目https://github.com/loqutus

ssl - 自己的 https certbot web 服务器返回 404 页面未找到

我有非常简单的gohttpswebserver代码如下:packagemainimport(//"fmt"//"io""net/http""log")funcHelloServer(whttp.ResponseWriter,req*http.Request){w.Header().Set("Content-Type","text/plain")w.Write([]byte("Thisisanexampleserver.\n"))//fmt.Fprintf(w,"Thisisanexampleserver.\n")//io.WriteString(w,"Thisisanexamplese