hybridgroup.gobot/api/cors.go

25 lines
536 B
Go
Raw Normal View History

2014-09-18 07:20:18 +08:00
package api
type CORS struct {
AllowOrigins []string
AllowHeaders []string // Not yet implemented
AllowMethods []string // ditto
}
func NewCORS(allowedOrigins []string) *CORS {
return &CORS{
AllowOrigins: allowedOrigins,
AllowMethods: []string{"GET", "POST"},
AllowHeaders: []string{"Origin", "Content-Type"},
}
}
func (c *CORS) isOriginAllowed(currentOrigin string) bool {
for _, allowedOrigin := range c.AllowOrigins {
if "*" == allowedOrigin || currentOrigin == allowedOrigin {
return true
}
}
return false
}