cors

package
v0.0.0-...-16de10f Latest Latest
Warning

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

Go to latest
Published: Aug 27, 2018 License: MIT Imports: 3 Imported by: 0

README

Middleware CORS

DHTTP server middleware for CORS

Intro

Add CORS headers. It response automatically if get OPTIONS method request.

Config

  • NeedOrigin bool
    default true. Only setup CORS header when request header has Origin when method is not OPTIONS.
  • Origins []string
    default return *
  • Methods []string
    default is GET, POST, HEAD
  • Headers []string
    default return same as Access-Control-Request-Headers

Exampl

Default

server.Use(cors.Middleware())

With Config

conf := cors.Config{
  NeedOrigin: true,
  Origins: []string{"mydomain.com", "sub.mydomain.com"},
  Methods: []string{"GET", "POST", "PUT", "DELETE"},
}

server.Use(cors.Middleware(conf))

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Middleware

func Middleware(config ...Config) *dhttp.Middleware

Middleware to allow CORS

Types

type Config

type Config struct {
	NeedOrigin bool
	Origins    []string
	Methods    []string
	Headers    []string
}

Config realip middleware config

Jump to

Keyboard shortcuts

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