aboutsummaryrefslogtreecommitdiff
path: root/vendor/github.com/rs/cors/examples
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/github.com/rs/cors/examples')
-rw-r--r--vendor/github.com/rs/cors/examples/alice/server.go24
-rw-r--r--vendor/github.com/rs/cors/examples/default/server.go19
-rw-r--r--vendor/github.com/rs/cors/examples/goji/server.go22
-rw-r--r--vendor/github.com/rs/cors/examples/martini/server.go23
-rw-r--r--vendor/github.com/rs/cors/examples/negroni/server.go26
-rw-r--r--vendor/github.com/rs/cors/examples/nethttp/server.go20
-rw-r--r--vendor/github.com/rs/cors/examples/openbar/server.go22
-rw-r--r--vendor/github.com/rs/cors/examples/xhandler/server.go24
8 files changed, 180 insertions, 0 deletions
diff --git a/vendor/github.com/rs/cors/examples/alice/server.go b/vendor/github.com/rs/cors/examples/alice/server.go
new file mode 100644
index 0000000..0a3e15c
--- /dev/null
+++ b/vendor/github.com/rs/cors/examples/alice/server.go
@@ -0,0 +1,24 @@
+package main
+
+import (
+ "net/http"
+
+ "github.com/justinas/alice"
+ "github.com/rs/cors"
+)
+
+func main() {
+ c := cors.New(cors.Options{
+ AllowedOrigins: []string{"http://foo.com"},
+ })
+
+ mux := http.NewServeMux()
+
+ mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
+ w.Header().Set("Content-Type", "application/json")
+ w.Write([]byte("{\"hello\": \"world\"}"))
+ })
+
+ chain := alice.New(c.Handler).Then(mux)
+ http.ListenAndServe(":8080", chain)
+}
diff --git a/vendor/github.com/rs/cors/examples/default/server.go b/vendor/github.com/rs/cors/examples/default/server.go
new file mode 100644
index 0000000..ccb5e1b
--- /dev/null
+++ b/vendor/github.com/rs/cors/examples/default/server.go
@@ -0,0 +1,19 @@
+package main
+
+import (
+ "net/http"
+
+ "github.com/rs/cors"
+)
+
+func main() {
+ mux := http.NewServeMux()
+ mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
+ w.Header().Set("Content-Type", "application/json")
+ w.Write([]byte("{\"hello\": \"world\"}"))
+ })
+
+ // Use default options
+ handler := cors.Default().Handler(mux)
+ http.ListenAndServe(":8080", handler)
+}
diff --git a/vendor/github.com/rs/cors/examples/goji/server.go b/vendor/github.com/rs/cors/examples/goji/server.go
new file mode 100644
index 0000000..1fb4073
--- /dev/null
+++ b/vendor/github.com/rs/cors/examples/goji/server.go
@@ -0,0 +1,22 @@
+package main
+
+import (
+ "net/http"
+
+ "github.com/rs/cors"
+ "github.com/zenazn/goji"
+)
+
+func main() {
+ c := cors.New(cors.Options{
+ AllowedOrigins: []string{"http://foo.com"},
+ })
+ goji.Use(c.Handler)
+
+ goji.Get("/", func(w http.ResponseWriter, r *http.Request) {
+ w.Header().Set("Content-Type", "application/json")
+ w.Write([]byte("{\"hello\": \"world\"}"))
+ })
+
+ goji.Serve()
+}
diff --git a/vendor/github.com/rs/cors/examples/martini/server.go b/vendor/github.com/rs/cors/examples/martini/server.go
new file mode 100644
index 0000000..081af32
--- /dev/null
+++ b/vendor/github.com/rs/cors/examples/martini/server.go
@@ -0,0 +1,23 @@
+package main
+
+import (
+ "github.com/go-martini/martini"
+ "github.com/martini-contrib/render"
+ "github.com/rs/cors"
+)
+
+func main() {
+ c := cors.New(cors.Options{
+ AllowedOrigins: []string{"http://foo.com"},
+ })
+
+ m := martini.Classic()
+ m.Use(render.Renderer())
+ m.Use(c.HandlerFunc)
+
+ m.Get("/", func(r render.Render) {
+ r.JSON(200, map[string]interface{}{"hello": "world"})
+ })
+
+ m.Run()
+}
diff --git a/vendor/github.com/rs/cors/examples/negroni/server.go b/vendor/github.com/rs/cors/examples/negroni/server.go
new file mode 100644
index 0000000..3cb33bf
--- /dev/null
+++ b/vendor/github.com/rs/cors/examples/negroni/server.go
@@ -0,0 +1,26 @@
+package main
+
+import (
+ "net/http"
+
+ "github.com/codegangsta/negroni"
+ "github.com/rs/cors"
+)
+
+func main() {
+ c := cors.New(cors.Options{
+ AllowedOrigins: []string{"http://foo.com"},
+ })
+
+ mux := http.NewServeMux()
+
+ mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
+ w.Header().Set("Content-Type", "application/json")
+ w.Write([]byte("{\"hello\": \"world\"}"))
+ })
+
+ n := negroni.Classic()
+ n.Use(c)
+ n.UseHandler(mux)
+ n.Run(":3000")
+}
diff --git a/vendor/github.com/rs/cors/examples/nethttp/server.go b/vendor/github.com/rs/cors/examples/nethttp/server.go
new file mode 100644
index 0000000..eaa775e
--- /dev/null
+++ b/vendor/github.com/rs/cors/examples/nethttp/server.go
@@ -0,0 +1,20 @@
+package main
+
+import (
+ "net/http"
+
+ "github.com/rs/cors"
+)
+
+func main() {
+ c := cors.New(cors.Options{
+ AllowedOrigins: []string{"http://foo.com"},
+ })
+
+ handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
+ w.Header().Set("Content-Type", "application/json")
+ w.Write([]byte("{\"hello\": \"world\"}"))
+ })
+
+ http.ListenAndServe(":8080", c.Handler(handler))
+}
diff --git a/vendor/github.com/rs/cors/examples/openbar/server.go b/vendor/github.com/rs/cors/examples/openbar/server.go
new file mode 100644
index 0000000..0940423
--- /dev/null
+++ b/vendor/github.com/rs/cors/examples/openbar/server.go
@@ -0,0 +1,22 @@
+package main
+
+import (
+ "net/http"
+
+ "github.com/rs/cors"
+)
+
+func main() {
+ c := cors.New(cors.Options{
+ AllowedOrigins: []string{"*"},
+ AllowedMethods: []string{"GET", "POST", "PUT", "DELETE"},
+ AllowCredentials: true,
+ })
+
+ h := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
+ w.Header().Set("Content-Type", "application/json")
+ w.Write([]byte("{\"hello\": \"world\"}"))
+ })
+
+ http.ListenAndServe(":8080", c.Handler(h))
+}
diff --git a/vendor/github.com/rs/cors/examples/xhandler/server.go b/vendor/github.com/rs/cors/examples/xhandler/server.go
new file mode 100644
index 0000000..649a1c7
--- /dev/null
+++ b/vendor/github.com/rs/cors/examples/xhandler/server.go
@@ -0,0 +1,24 @@
+package main
+
+import (
+ "net/http"
+
+ "github.com/rs/cors"
+ "github.com/rs/xhandler"
+ "golang.org/x/net/context"
+)
+
+func main() {
+ c := xhandler.Chain{}
+
+ // Use default options
+ c.UseC(cors.Default().HandlerC)
+
+ mux := http.NewServeMux()
+ mux.Handle("/", c.Handler(xhandler.HandlerFuncC(func(ctx context.Context, w http.ResponseWriter, r *http.Request) {
+ w.Header().Set("Content-Type", "application/json")
+ w.Write([]byte("{\"hello\": \"world\"}"))
+ })))
+
+ http.ListenAndServe(":8080", mux)
+}