/
environment.go
84 lines (75 loc) · 3.03 KB
/
environment.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
// Copyright (c) 2015 TIBCO Software Inc.
// All Rights Reserved.
package cors
import (
"os"
)
// List of constants default values that can be overriden by environment variables
const (
CORS_ALLOW_ORIGIN_KEY string = "CORS_ALLOW_ORIGIN"
CORS_ALLOW_ORIGIN_DEFAULT string = "*"
CORS_ALLOW_METHODS_KEY string = "CORS_ALLOW_METHODS"
CORS_ALLOW_METHODS_DEFAULT string = "POST, GET, OPTIONS, PUT, DELETE, PATCH"
CORS_ALLOW_HEADERS_KEY string = "CORS_ALLOW_HEADERS"
CORS_EXPOSE_HEADERS_KEY string = "CORS_EXPOSE_HEADERS"
CORS_ALLOW_HEADERS_DEFAULT string = "Content-Type, Content-Length, Accept-Encoding, X-CSRF-Token, X-Requested-With, Accept, Accept-Language"
CORS_EXPOSE_HEADERS_DEFAULT string = ""
CORS_ALLOW_CREDENTIALS_KEY string = "CORS_ALLOW_CREDENTIALS"
CORS_ALLOW_CREDENTIALS_DEFAULT string = "false"
CORS_MAX_AGE_KEY string = "CORS_MAX_AGE"
CORS_MAX_AGE_DEFAULT string = ""
)
//GetCorsAllowOrigin get the value for CORS 'AllowOrigin' param from environment variable and the default BS_CORS_ALLOW_ORIGIN_DEFAULT will be used if not found
func GetCorsAllowOrigin(prefix string) string {
envalue := os.Getenv(prefix + CORS_ALLOW_ORIGIN_KEY)
if envalue == "" {
return CORS_ALLOW_ORIGIN_DEFAULT
} else {
return envalue
}
}
//GetCorsAllowMethods get the allowed method for CORS from environment variable and the default BS_CORS_ALLOW_METHODS_DEFAULT will be used if not found
func GetCorsAllowMethods(prefix string) string {
envalue := os.Getenv(prefix + CORS_ALLOW_METHODS_KEY)
if envalue == "" {
return CORS_ALLOW_METHODS_DEFAULT
} else {
return envalue
}
}
//GetCorsAllowHeaders get the value for CORS 'AllowHeaders' param from environment variable and the default BS_CORS_ALLOW_HEADERS_DEFAULT will be used if not found
func GetCorsAllowHeaders(prefix string) string {
envalue := os.Getenv(prefix + CORS_ALLOW_HEADERS_KEY)
if envalue == "" {
return CORS_ALLOW_HEADERS_DEFAULT
} else {
return envalue
}
}
//GetCorsExposeHeaders get the value for CORS 'ExposeHeaders' param from environment variable and the default BS_CORS_EXPOSE_HEADERS_DEFAULT will be used if not found
func GetCorsExposeHeaders(prefix string) string {
envalue := os.Getenv(prefix + CORS_EXPOSE_HEADERS_KEY)
if envalue == "" {
return CORS_EXPOSE_HEADERS_DEFAULT
} else {
return envalue
}
}
//GetCorsAllowCredentials get the value for CORS 'AllowCredentials' param from environment variable and the default BS_CORS_ALLOW_CREDENTIALS_DEFAULT will be used if not found
func GetCorsAllowCredentials(prefix string) string {
envalue := os.Getenv(prefix + CORS_ALLOW_CREDENTIALS_KEY)
if envalue == "" {
return CORS_ALLOW_CREDENTIALS_DEFAULT
} else {
return envalue
}
}
//GetCorsMaxAge get the value for CORS 'Max Age' param from environment variable and the default BS_CORS_ALLOW_CREDENTIALS_DEFAULT will be used if not found
func GetCorsMaxAge(prefix string) string {
envalue := os.Getenv(prefix + CORS_MAX_AGE_KEY)
if envalue == "" {
return CORS_MAX_AGE_DEFAULT
} else {
return envalue
}
}