func (o *Options) Header(origin string) (headers map[string]string) {
	headers = make(map[string]string)
	if !o.AllowAllOrigins && !o.IsOriginAllowed(origin) {
		return
	}
	if o.AllowAllOrigins {
		headers[headerAllowOrigin] = "*"
	} else {
		headers[headerAllowOrigin] = origin
	}
	headers[headerAllowCredentials] = strconv.FormatBool(o.AllowCredentials)
	if len(o.AllowMethods) > 0 {
		headers[headerAllowMethods] = strings.Join(o.AllowMethods, ",")
	}
	if len(o.AllowHeaders) > 0 {
		headers[headerAllowHeaders] = strings.Join(o.AllowHeaders, ",")
	}
	if len(o.ExposeHeaders) > 0 {
		headers[headerExposeHeaders] = strings.Join(o.ExposeHeaders, ",")
	}
	if o.MaxAge > time.Duration(0) {
		headers[headerMaxAge] = strconv.FormatInt(int64(o.MaxAge/time.Second), 10)
	}
	return
}
Header converts options into CORS headers.
package cors
import (
	"net/http"
	"regexp"
	"strconv"
	"strings"
	"time"
	"github.com/astaxie/beego"
	"github.com/astaxie/beego/context"
)
const (
	headerAllowOrigin      = "Access-Control-Allow-Origin"
	headerAllowCredentials = "Access-Control-Allow-Credentials"
	headerAllowHeaders     = "Access-Control-Allow-Headers"
	headerAllowMethods     = "Access-Control-Allow-Methods"
	headerExposeHeaders    = "Access-Control-Expose-Headers"
	headerMaxAge           = "Access-Control-Max-Age"
	headerOrigin         = "Origin"
	headerRequestMethod  = "Access-Control-Request-Method"
	headerRequestHeaders = "Access-Control-Request-Headers"
)
var (
	defaultAllowHeaders = []string{"Origin", "Accept", "Content-Type", "Authorization"}
	allowOriginPatterns = []string{}
)
type Options struct {
	AllowAllOrigins bool
	AllowOrigins []string
	AllowCredentials bool
	AllowMethods []string
	AllowHeaders []string
	ExposeHeaders []string
	MaxAge time.Duration
}