在rest.go库和Golang中,指定rest.Resource中的内容类型。

huangapple go评论101阅读模式
英文:

specifying type of content in rest.Resource (rest.go lib & Golang)

问题

我写了一个json数据结构,并将其存储在URL中作为资源。

type FileString struct {
    Data string
}
rest.Resource("json_data", &FileString{Data: some_string})

但是当我将其作为uri加载到java-script中时,

loader.load({ model: '/json_data/', callback: function (geometry) {
...
}

我在js控制台中得到了以下错误信息:

> 'Resource interpreted as Script but transferred with MIME type text/html.'

在执行rest.Resource(...)时,我应该在哪里设置内容类型?请帮忙。

英文:

I write a json data structure,
and store it in the url as a resource

type FileString struct {
    Data string
 }
rest.Resource("json_data", &FileString{Data : some_string})

but when I load it in the java-script, as a uri

 loader.load( { model: '/json_data/', callback: function ( geometry ) {
  ...
  }

I get in the js console

>'Resource interpreted as Script but transferred with MIME type text/html.'

Where do I set the content type when doing rest.Resource(...) ???
Please Help.

答案1

得分: 1

你不能。rest.go不公开该功能。你可以向开发者提交一个问题。

英文:

You can't. rest.go doesn't expose that functionality.
You could file an issue with the developer.

答案2

得分: 1

Goweb的API部分提供了更多对底层HTTP的控制,允许您以通常的方式指定内容类型。

英文:

Goweb's API stuff provides much more control over the underlying HTTP allowing you to specify content type in the usual way.

huangapple
  • 本文由 发表于 2011年7月17日 00:28:54
  • 转载请务必保留本文链接:https://go.coder-hub.com/6718718.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定