小编Yas*_*ava的帖子

无论如何在Go中创建空终止字符串?

无论如何string在Go中创建null终止?

我目前正在尝试a:="golang\0"但它显示编译错误:

non-octal character in escape sequence: "
Run Code Online (Sandbox Code Playgroud)

string c-strings go

10
推荐指数
1
解决办法
7645
查看次数

在Golang中启用CORS

嗨,我正在实施rest apis,为此我想要允许交叉原始请求.

我目前在做什么:

AWS上的Go-server代码:

func (c *UserController) Login(w http.ResponseWriter, r *http.Request, ctx *rack.Context) {
w.Header().Set("Access-Control-Allow-Origin", r.Header.Get("Origin"))
w.Header().Set("Access-Control-Allow-Methods", "POST, GET, OPTIONS, PUT, DELETE")
...
...
c.render.Json(w,rsp, http.StatusOK)
return
}
Run Code Online (Sandbox Code Playgroud)

localhost上的Ajax代码:

<script>
$( document ).ready(function() {
    console.log( "ready!" );
    $.ajax({
        url: 'http://ip:8080/login',
        crossDomain: true, //set as a cross domain requests
        withCredentials:false,
        type: 'post',
        success: function (data) {
            alert("Data " + data);
        },
    });
});
Run Code Online (Sandbox Code Playgroud)

我在浏览器控制台上收到以下错误: XMLHttpRequest无法加载http:// ip:8080/login.请求的资源上不存在"Access-Control-Allow-Origin"标头.因此不允许来源' http:// localhost:8081 '访问.响应具有HTTP状态代码422.

我尝试添加预检选项:

func corsRoute(app *app.App) {
allowedHeaders := "Accept, Content-Type, Content-Length, …
Run Code Online (Sandbox Code Playgroud)

ajax cross-domain go cors

7
推荐指数
5
解决办法
3万
查看次数

如何在dynamodb中保存JSON响应

我想在aws-dynamodb中保存一个JSON响应,我正在使用aws-dynamodb-sdk。我目前正在做的是:

func (e *DB) saveToDynamodb(data map[string]interface{}){
params := &dynamodb.PutItemInput{
    Item: map[string]*dynamodb.AttributeValue{
        "Key": {
            M: data,
        },
    },
    TableName: aws.String("Asset_Data"),
}
resp, err := e.dynamodb.PutItem(params)

if err != nil {
    fmt.Println(err.Error())
    return
}
fmt.Println(resp)
}
Run Code Online (Sandbox Code Playgroud)

但是正如您所看到的,数据map [string] interface {}类型的,而期望的类型是map [string] * AttributeValue,这就是为什么会出现编译错误的原因。

有保存JSON响应的解决方法吗?

json go amazon-dynamodb aws-sdk aws-sdk-go

4
推荐指数
2
解决办法
2112
查看次数

将 Wordpress 与 golang 集成

我正在开发一个项目,其中前端部分在 wordpress 中完成,后端 apis 在 GO 中完成。我想知道它们是否可以集成。

wordpress go

2
推荐指数
1
解决办法
1740
查看次数