mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
refactor(cors): Simplify corsInfo struct
This commit is contained in:
@@ -22,9 +22,7 @@ import (
|
|||||||
"net/url"
|
"net/url"
|
||||||
)
|
)
|
||||||
|
|
||||||
type corsInfo struct {
|
type corsInfo map[string]bool
|
||||||
origins 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 {
|
func (c corsInfo) OriginAllowed(origin string) bool {
|
||||||
return c.origins["*"] || c.origins[origin]
|
return c["*"] || c[origin]
|
||||||
}
|
}
|
||||||
|
|
||||||
type corsHTTPMiddleware struct {
|
type corsHTTPMiddleware struct {
|
||||||
|
|||||||
Reference in New Issue
Block a user