无论如何string
在Go中创建null终止?
我目前正在尝试a:="golang\0"
但它显示编译错误:
non-octal character in escape sequence: "
Run Code Online (Sandbox Code Playgroud) 嗨,我正在实施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) 我想在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响应的解决方法吗?
我正在开发一个项目,其中前端部分在 wordpress 中完成,后端 apis 在 GO 中完成。我想知道它们是否可以集成。
go ×4
ajax ×1
aws-sdk ×1
aws-sdk-go ×1
c-strings ×1
cors ×1
cross-domain ×1
json ×1
string ×1
wordpress ×1