Skip to content
This repository has been archived by the owner on Jan 12, 2020. It is now read-only.

Latest commit

 

History

History
41 lines (33 loc) · 764 Bytes

README.md

File metadata and controls

41 lines (33 loc) · 764 Bytes

Middleware: CORS Request

Reference

Config

type Config struct {
	Origin        []string
	Methods       []string
	Headers       []string
	ExposeHeaders []string
	Credentials   bool
	MaxAge        time.Duration
}

// Default
var _config = Config{
	Origin:      []string{"*"},
	Methods:     []string{"GET", "POST", "PUT", "DELETE", "OPTIONS", "HEAD", "PATCH"},
	Headers:     []string{"Content-Type"},
	Credentials: false,
	MaxAge:      time.Hour,
}

How to use?

var api rest.API

config := cors.Config{
    Methods: []string{"GET", "POST"},
    Credentials: true,
    MaxAge: 6 * time.Hour,
}

api.Use(cors.Load(config))