type MyResource struct { Name string Age int } func (r MyResource) Register(container *restful.Container) { ws := new(restful.WebService) ws.Path("/my-resource"). Doc("MyResource documentation"). Route(ws.GET("").To(r.getMyResource)) container.Add(ws) } func (r MyResource) getMyResource(request *restful.Request, response *restful.Response) { myResource := MyResource{Name: "John", Age: 30} response.WriteEntity(myResource) }
func (r MyResource) getMyResource(request *restful.Request, response *restful.Response) { response.WriteEntity("Hello, World!") }This example shows how to write a simple string entity to the response using the `WriteEntity` function. Package library: `github.com.emicklei.go-restful`