File: doc_examples_test.go

package info (click to toggle)
golang-github-emicklei-go-restful 3.10.2-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 792 kB
  • sloc: makefile: 9; sh: 6
file content (41 lines) | stat: -rw-r--r-- 1,336 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package restful

import "net/http"

func ExampleOPTIONSFilter() {
	// Install the OPTIONS filter on the default Container
	Filter(OPTIONSFilter())
}
func ExampleContainer_OPTIONSFilter() {
	// Install the OPTIONS filter on a Container
	myContainer := new(Container)
	myContainer.Filter(myContainer.OPTIONSFilter)
}

func ExampleContainer() {
	// The Default container of go-restful uses the http.DefaultServeMux.
	// You can create your own Container using restful.NewContainer() and create a new http.Server for that particular container

	ws := new(WebService)
	wsContainer := NewContainer()
	wsContainer.Add(ws)
	server := &http.Server{Addr: ":8080", Handler: wsContainer}
	server.ListenAndServe()
}

func ExampleCrossOriginResourceSharing() {
	// To install this filter on the Default Container use:
	cors := CrossOriginResourceSharing{ExposeHeaders: []string{"X-My-Header"}, CookiesAllowed: false, Container: DefaultContainer}
	Filter(cors.Filter)
}

func ExampleServiceError() {
	resp := new(Response)
	resp.WriteEntity(NewError(http.StatusBadRequest, "Non-integer {id} path parameter"))
}

func ExampleBoundedCachedCompressors() {
	// Register a compressor provider (gzip/deflate read/write) that uses
	// a bounded cache with a maximum of 20 writers and 20 readers.
	SetCompressorProvider(NewBoundedCachedCompressors(20, 20))
}