doc_examples_test.go 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. package restful
  2. import "net/http"
  3. func ExampleOPTIONSFilter() {
  4. // Install the OPTIONS filter on the default Container
  5. Filter(OPTIONSFilter())
  6. }
  7. func ExampleContainer_OPTIONSFilter() {
  8. // Install the OPTIONS filter on a Container
  9. myContainer := new(Container)
  10. myContainer.Filter(myContainer.OPTIONSFilter)
  11. }
  12. func ExampleContainer() {
  13. // The Default container of go-restful uses the http.DefaultServeMux.
  14. // You can create your own Container using restful.NewContainer() and create a new http.Server for that particular container
  15. ws := new(WebService)
  16. wsContainer := NewContainer()
  17. wsContainer.Add(ws)
  18. server := &http.Server{Addr: ":8080", Handler: wsContainer}
  19. server.ListenAndServe()
  20. }
  21. func ExampleCrossOriginResourceSharing() {
  22. // To install this filter on the Default Container use:
  23. cors := CrossOriginResourceSharing{ExposeHeaders: []string{"X-My-Header"}, CookiesAllowed: false, Container: DefaultContainer}
  24. Filter(cors.Filter)
  25. }
  26. func ExampleServiceError() {
  27. resp := new(Response)
  28. resp.WriteEntity(NewError(http.StatusBadRequest, "Non-integer {id} path parameter"))
  29. }
  30. func ExampleBoundedCachedCompressors() {
  31. // Register a compressor provider (gzip/deflate read/write) that uses
  32. // a bounded cache with a maximum of 20 writers and 20 readers.
  33. SetCompressorProvider(NewBoundedCachedCompressors(20, 20))
  34. }