Browse Source

refactor(cors): Simplify corsInfo struct

Brian Waldon 12 years ago
parent
commit
074099a1b2
1 changed files with 5 additions and 6 deletions
  1. 5 6
      server/cors.go

+ 5 - 6
server/cors.go

@@ -22,9 +22,7 @@ import (
 	"net/url"
 	"net/url"
 )
 )
 
 
-type corsInfo struct {
-	origins map[string]bool
-}
+type corsInfo map[string]bool
 
 
 func NewCORSInfo(origins []string) (*corsInfo, error) {
 func NewCORSInfo(origins []string) (*corsInfo, error) {
 	// Construct a lookup of all origins.
 	// Construct a lookup of all origins.
@@ -38,12 +36,13 @@ func NewCORSInfo(origins []string) (*corsInfo, error) {
 		m[v] = true
 		m[v] = true
 	}
 	}
 
 
-	return &corsInfo{m}, nil
+	info := corsInfo(m)
+	return &info, nil
 }
 }
 
 
 // OriginAllowed determines whether the server will allow a given CORS origin.
 // OriginAllowed determines whether the server will allow a given CORS origin.
-func (c *corsInfo) OriginAllowed(origin string) bool {
-	return c.origins["*"] || c.origins[origin]
+func (c corsInfo) OriginAllowed(origin string) bool {
+	return c["*"] || c[origin]
 }
 }
 
 
 type corsHTTPMiddleware struct {
 type corsHTTPMiddleware struct {