You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I define a struct File include file array.Cpu and memory is 100% when run this program.
I find if File struct not include []File the program is right.But I can't find proberlem point :(
type File struct {
Id, Name string
HitoryFile []File
}
type FileService struct {
// normally one would use DAO (data access object)
files map[string]File
}
func (f FileService) Register() {
ws := new(restful.WebService)
ws.
Path("/files").
Consumes(restful.MIME_XML, restful.MIME_JSON).
Produces(restful.MIME_JSON, restful.MIME_XML) // you can specify this per route as well
ws.Route(ws.GET("/{file-id}").To(f.findFile).
// docs
Doc("get a file").
Param(ws.PathParameter("file-id", "identifier of the file").DataType("string")).
Writes(File{})) // on the response
restful.Add(ws)
}
// GET http://localhost:8080/users/1
//
func (f FileService) findFile(request *restful.Request, response *restful.Response) {
id := request.PathParameter("file-id")
file := f.files[id]
if len(file.Id) == 0 {
response.WriteErrorString(http.StatusNotFound, "File could not be found.")
} else {
response.WriteEntity(file)
}
}
func main() {
f := FileService{map[string]File{}}
f.Register()
// Optionally, you can install the Swagger Service which provides a nice Web UI on your REST API
// You need to download the Swagger HTML5 assets and change the FilePath location in the config below.
// Open http://localhost:8080/apidocs and enter http://localhost:8080/apidocs.json in the api input field.
config := swagger.Config{
WebServices: restful.RegisteredWebServices(), // you control what services are visible
WebServicesUrl: "http://localhost:8080",
ApiPath: "/apidocs.json",
// Optionally, specifiy where the UI is located
SwaggerPath: "/apidocs/",
SwaggerFilePath: "./apiview"}
swagger.InstallSwaggerService(config)
log.Printf("start listening on localhost:8080")
log.Fatal(http.ListenAndServe(":8080", nil))
}
The text was updated successfully, but these errors were encountered:
So you defined a recursive data structure. Does the problem only happen when asking for the user interface, i.e. when the Swagger model is constructed? I will create a test to verify that recursive structures are handled properly just in case.
I define a struct File include file array.Cpu and memory is 100% when run this program.
I find if File struct not include []File the program is right.But I can't find proberlem point :(
The text was updated successfully, but these errors were encountered: