Skip to content

Commit c6b32d5

Browse files
committed
Added json tags to middleware config
Signed-off-by: Vishal Rana <vr@labstack.com>
1 parent 52a5dcf commit c6b32d5

File tree

8 files changed

+29
-29
lines changed

8 files changed

+29
-29
lines changed

middleware/compress.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ type (
1717
GzipConfig struct {
1818
// Gzip compression level.
1919
// Optional. Default value -1.
20-
Level int
20+
Level int `json:"level"`
2121
}
2222

2323
gzipResponseWriter struct {

middleware/cors.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,34 +13,34 @@ type (
1313
CORSConfig struct {
1414
// AllowOrigin defines a list of origins that may access the resource.
1515
// Optional. Default value []string{"*"}.
16-
AllowOrigins []string
16+
AllowOrigins []string `json:"allow_origins"`
1717

1818
// AllowMethods defines a list methods allowed when accessing the resource.
1919
// This is used in response to a preflight request.
2020
// Optional. Default value DefaultCORSConfig.AllowMethods.
21-
AllowMethods []string
21+
AllowMethods []string `json:"allow_methods"`
2222

2323
// AllowHeaders defines a list of request headers that can be used when
2424
// making the actual request. This in response to a preflight request.
2525
// Optional. Default value []string{}.
26-
AllowHeaders []string
26+
AllowHeaders []string `json:"allow_headers"`
2727

2828
// AllowCredentials indicates whether or not the response to the request
2929
// can be exposed when the credentials flag is true. When used as part of
3030
// a response to a preflight request, this indicates whether or not the
3131
// actual request can be made using credentials.
3232
// Optional. Default value false.
33-
AllowCredentials bool
33+
AllowCredentials bool `json:"allow_credentials"`
3434

3535
// ExposeHeaders defines a whitelist headers that clients are allowed to
3636
// access.
3737
// Optional. Default value []string{}.
38-
ExposeHeaders []string
38+
ExposeHeaders []string `json:"expose_headers"`
3939

4040
// MaxAge indicates how long (in seconds) the results of a preflight request
4141
// can be cached.
4242
// Optional. Default value 0.
43-
MaxAge int
43+
MaxAge int `json:"max_age"`
4444
}
4545
)
4646

middleware/csrf.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,39 +18,39 @@ type (
1818
// CSRFConfig defines the config for CSRF middleware.
1919
CSRFConfig struct {
2020
// Key to create CSRF token.
21-
Secret []byte
21+
Secret []byte `json:"secret"`
2222

2323
// Context key to store generated CSRF token into context.
2424
// Optional. Default value "csrf".
25-
ContextKey string
25+
ContextKey string `json:"context_key"`
2626

2727
// Extractor is a function that extracts token from the request.
2828
// Optional. Default value CSRFTokenFromHeader(echo.HeaderXCSRFToken).
2929
Extractor CSRFTokenExtractor
3030

3131
// Name of the CSRF cookie. This cookie will store CSRF token.
3232
// Optional. Default value "csrf".
33-
CookieName string
33+
CookieName string `json:"cookie_name"`
3434

3535
// Domain of the CSRF cookie.
3636
// Optional. Default value none.
37-
CookieDomain string
37+
CookieDomain string `json:"cookie_domain"`
3838

3939
// Path of the CSRF cookie.
4040
// Optional. Default value none.
41-
CookiePath string
41+
CookiePath string `json:"cookie_path"`
4242

4343
// Expiration time of the CSRF cookie.
4444
// Optional. Default value 24H.
45-
CookieExpires time.Time
45+
CookieExpires time.Time `json:"cookie_expires"`
4646

4747
// Indicates if CSRF cookie is secure.
48-
CookieSecure bool
48+
CookieSecure bool `json:"cookie_secure"`
4949
// Optional. Default value false.
5050

5151
// Indicates if CSRF cookie is HTTP only.
5252
// Optional. Default value false.
53-
CookieHTTPOnly bool
53+
CookieHTTPOnly bool `json:"cookie_http_only"`
5454
}
5555

5656
// CSRFTokenExtractor defines a function that takes `echo.Context` and returns

middleware/jwt.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@ type (
1414
JWTConfig struct {
1515
// Signing key to validate token.
1616
// Required.
17-
SigningKey []byte
17+
SigningKey []byte `json:"signing_key"`
1818

1919
// Signing method, used to check token signing method.
2020
// Optional. Default value HS256.
21-
SigningMethod string
21+
SigningMethod string `json:"signing_method"`
2222

2323
// Context key to store user information from the token into context.
2424
// Optional. Default value "user".
25-
ContextKey string
25+
ContextKey string `json:"context_key"`
2626

2727
// Extractor is a function that extracts token from the request.
2828
// Optional. Default value JWTFromHeader.

middleware/logger.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ type (
3939
// Example "${remote_ip} ${status}"
4040
//
4141
// Optional. Default value DefaultLoggerConfig.Format.
42-
Format string
42+
Format string `json:"format"`
4343

4444
// Output is a writer where logs are written.
4545
// Optional. Default value os.Stdout.

middleware/recover.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,16 @@ type (
1313
RecoverConfig struct {
1414
// Size of the stack to be printed.
1515
// Optional. Default value 4KB.
16-
StackSize int
16+
StackSize int `json:"stack_size"`
1717

1818
// DisableStackAll disables formatting stack traces of all other goroutines
1919
// into buffer after the trace for the current goroutine.
2020
// Optional. Default value false.
21-
DisableStackAll bool
21+
DisableStackAll bool `json:"disable_stack_all"`
2222

2323
// DisablePrintStack disables printing stack trace.
2424
// Optional. Default value as false.
25-
DisablePrintStack bool
25+
DisablePrintStack bool `json:"disable_print_stack"`
2626
}
2727
)
2828

middleware/secure.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ type (
1212
// XSSProtection provides protection against cross-site scripting attack (XSS)
1313
// by setting the `X-XSS-Protection` header.
1414
// Optional. Default value "1; mode=block".
15-
XSSProtection string
15+
XSSProtection string `json:"xss_protection"`
1616

1717
// ContentTypeNosniff provides protection against overriding Content-Type
1818
// header by setting the `X-Content-Type-Options` header.
1919
// Optional. Default value "nosniff".
20-
ContentTypeNosniff string
20+
ContentTypeNosniff string `json:"content_type_nosniff"`
2121

2222
// XFrameOptions can be used to indicate whether or not a browser should
2323
// be allowed to render a page in a <frame>, <iframe> or <object> .
@@ -29,27 +29,27 @@ type (
2929
// `SAMEORIGIN` - The page can only be displayed in a frame on the same origin as the page itself.
3030
// `DENY` - The page cannot be displayed in a frame, regardless of the site attempting to do so.
3131
// `ALLOW-FROM uri` - The page can only be displayed in a frame on the specified origin.
32-
XFrameOptions string
32+
XFrameOptions string `json:"x_frame_options"`
3333

3434
// HSTSMaxAge sets the `Strict-Transport-Security` header to indicate how
3535
// long (in seconds) browsers should remember that this site is only to
3636
// be accessed using HTTPS. This reduces your exposure to some SSL-stripping
3737
// man-in-the-middle (MITM) attacks.
3838
// Optional. Default value 0.
39-
HSTSMaxAge int
39+
HSTSMaxAge int `json:"hsts_max_age"`
4040

4141
// HSTSExcludeSubdomains won't include subdomains tag in the `Strict Transport Security`
4242
// header, excluding all subdomains from security policy. It has no effect
4343
// unless HSTSMaxAge is set to a non-zero value.
4444
// Optional. Default value false.
45-
HSTSExcludeSubdomains bool
45+
HSTSExcludeSubdomains bool `json:"hsts_exclude_subdomains"`
4646

4747
// ContentSecurityPolicy sets the `Content-Security-Policy` header providing
4848
// security against cross-site scripting (XSS), clickjacking and other code
4949
// injection attacks resulting from execution of malicious content in the
5050
// trusted web page context.
5151
// Optional. Default value "".
52-
ContentSecurityPolicy string
52+
ContentSecurityPolicy string `json:"content_security_policy"`
5353
}
5454
)
5555

middleware/slash.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ type (
99
TrailingSlashConfig struct {
1010
// Status code to be used when redirecting the request.
1111
// Optional, but when provided the request is redirected using this code.
12-
RedirectCode int
12+
RedirectCode int `json:"redirect_code"`
1313
}
1414
)
1515

0 commit comments

Comments
 (0)