corsmidware

package module
v0.0.0-...-fef2677 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 4, 2017 License: BSD-3-Clause Imports: 3 Imported by: 0

README

Cross-Origin Resource Sharing Middleware

Build Status GoDoc Coverage Status

Cross-Origin Resource Sharing Middleware for Gem Web framework.

Install

$ go get -u github.com/go-gem/middleware-cors

Example

package main

import (
	"github.com/go-gem/gem"
	"github.com/go-gem/middleware-cors"
	"github.com/rs/cors"
)

var corsMiddleware = corsmidware.New(cors.Options{})

func main() {
	router := gem.NewRouter()
	router.Use(corsMiddleware)
	router.GET("/", func(ctx *gem.Context) {
		ctx.HTML(200, "foo")
	})

	gem.ListenAndServe(":8080", router.Handler())
}

Documentation

Overview

Package corsmidware provides Cross-Origin Resource Sharing middleware for Gem web framework.

Example

package main

import (
	"github.com/go-gem/gem"
	"github.com/go-gem/middleware-cors"
	"github.com/rs/cors"
)

var corsMiddleware = corsmidware.New(cors.Options{})

func main() {
	router := gem.NewRouter()
	router.Use(corsMiddleware)
	router.GET("/", func(ctx *gem.Context) {
		ctx.HTML(200, "foo")
	})

	gem.ListenAndServe(":8080", router.Handler())
}
Example
corsMidware := New(cors.Options{
	AllowedMethods: []string{"GET", "POST"},
})
req := httptest.NewRequest("GET", "/", nil)
resp := httptest.NewRecorder()
ctx := &gem.Context{Request: req, Response: resp}

var pass bool
handler := corsMidware.Wrap(gem.HandlerFunc(func(ctx *gem.Context) {
	pass = true
}))
handler.Handle(ctx)

fmt.Println(pass)
Output:

true

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CORS

type CORS struct {
	// contains filtered or unexported fields
}

CORS Cross-Origin Resource Sharing middleware.

func New

func New(options cors.Options) *CORS

New return a CORS middleware instance with the given options.

func (*CORS) Wrap

func (c *CORS) Wrap(next gem.Handler) gem.Handler

Wrap implements the Middleware interface.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL