Skip to content

Commit d8df331

Browse files
committed
Revert app Config struct. Add betteralign to Makefile
1 parent ef22517 commit d8df331

File tree

2 files changed

+106
-102
lines changed

2 files changed

+106
-102
lines changed

Makefile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,3 +51,8 @@ longtest:
5151
.PHONY: tidy
5252
tidy:
5353
go mod tidy -v
54+
55+
## betteralign: 📐 Optimize alignment of fields in structs
56+
.PHONY: betteralign
57+
betteralign:
58+
go run github.com/dkorunic/betteralign/cmd/betteralign@latest -test_files -generated_files -apply ./...

app.go

Lines changed: 101 additions & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -130,90 +130,40 @@ type App struct {
130130
}
131131

132132
// Config is a struct holding the server settings.
133-
type Config struct {
134-
// Views is the interface that wraps the Render function.
135-
//
136-
// Default: nil
137-
Views Views `json:"-"`
138-
139-
// If you want to validate header/form/query... automatically when to bind, you can define struct validator.
140-
// Fiber doesn't have default validator, so it'll skip validator step if you don't use any validator.
141-
//
142-
// Default: nil
143-
StructValidator StructValidator
144-
145-
// CompressedFileSuffixes adds suffix to the original file name and
146-
// tries saving the resulting compressed file under the new file name.
147-
//
148-
// Default: map[string]string{"gzip": ".fiber.gz", "br": ".fiber.br", "zstd": ".fiber.zst"}
149-
CompressedFileSuffixes map[string]string `json:"compressed_file_suffixes"`
150-
151-
// ErrorHandler is executed when an error is returned from fiber.Handler.
152-
//
153-
// Default: DefaultErrorHandler
154-
ErrorHandler ErrorHandler `json:"-"`
155-
156-
// When set by an external client of Fiber it will use the provided implementation of a
157-
// JSONMarshal
158-
//
159-
// Allowing for flexibility in using another json library for encoding
160-
// Default: json.Marshal
161-
JSONEncoder utils.JSONMarshal `json:"-"`
162-
163-
// When set by an external client of Fiber it will use the provided implementation of a
164-
// JSONUnmarshal
165-
//
166-
// Allowing for flexibility in using another json library for decoding
167-
// Default: json.Unmarshal
168-
JSONDecoder utils.JSONUnmarshal `json:"-"`
169-
170-
// XMLEncoder set by an external client of Fiber it will use the provided implementation of a
171-
// XMLMarshal
172-
//
173-
// Allowing for flexibility in using another XML library for encoding
174-
// Default: xml.Marshal
175-
XMLEncoder utils.XMLMarshal `json:"-"`
176-
177-
trustedProxiesMap map[string]struct{}
178-
179-
// You can define custom color scheme. They'll be used for startup message, route list and some middlewares.
180-
//
181-
// Optional. Default: DefaultColors
182-
ColorScheme Colors `json:"color_scheme"`
183-
133+
type Config struct { //nolint:govet // Aligning the struct fields is not necessary. betteralign:ignore
184134
// Enables the "Server: value" HTTP header.
185135
//
186136
// Default: ""
187137
ServerHeader string `json:"server_header"`
188138

189-
// Views Layout is the global layout for all template render until override on Render function.
190-
//
191-
// Default: ""
192-
ViewsLayout string `json:"views_layout"`
193-
194-
// ProxyHeader will enable c.IP() to return the value of the given header key
195-
// By default c.IP() will return the Remote IP from the TCP connection
196-
// This property can be useful if you are behind a load balancer: X-Forwarded-*
197-
// NOTE: headers are easily spoofed and the detected IP addresses are unreliable.
139+
// When set to true, the router treats "/foo" and "/foo/" as different.
140+
// By default this is disabled and both "/foo" and "/foo/" will execute the same handler.
198141
//
199-
// Default: ""
200-
ProxyHeader string `json:"proxy_header"`
142+
// Default: false
143+
StrictRouting bool `json:"strict_routing"`
201144

202-
// This function allows to setup app name for the app
145+
// When set to true, enables case sensitive routing.
146+
// E.g. "/FoO" and "/foo" are treated as different routes.
147+
// By default this is disabled and both "/FoO" and "/foo" will execute the same handler.
203148
//
204-
// Default: nil
205-
AppName string `json:"app_name"`
149+
// Default: false
150+
CaseSensitive bool `json:"case_sensitive"`
206151

207-
// Read EnableTrustedProxyCheck doc.
152+
// When set to true, this relinquishes the 0-allocation promise in certain
153+
// cases in order to access the handler values (e.g. request bodies) in an
154+
// immutable fashion so that these values are available even if you return
155+
// from handler.
208156
//
209-
// Default: []string
210-
TrustedProxies []string `json:"trusted_proxies"`
211-
trustedProxyRanges []*net.IPNet
157+
// Default: false
158+
Immutable bool `json:"immutable"`
212159

213-
// RequestMethods provides customizibility for HTTP methods. You can add/remove methods as you wish.
160+
// When set to true, converts all encoded characters in the route back
161+
// before setting the path for the context, so that the routing,
162+
// the returning of the current url from the context `ctx.Path()`
163+
// and the parameters `ctx.Params(%key%)` with decoded characters will work
214164
//
215-
// Optional. Default: DefaultMethods
216-
RequestMethods []string
165+
// Default: false
166+
UnescapePath bool `json:"unescape_path"`
217167

218168
// Max body size that the server accepts.
219169
// -1 will decline any body size
@@ -226,6 +176,21 @@ type Config struct {
226176
// Default: 256 * 1024
227177
Concurrency int `json:"concurrency"`
228178

179+
// Views is the interface that wraps the Render function.
180+
//
181+
// Default: nil
182+
Views Views `json:"-"`
183+
184+
// Views Layout is the global layout for all template render until override on Render function.
185+
//
186+
// Default: ""
187+
ViewsLayout string `json:"views_layout"`
188+
189+
// PassLocalsToViews Enables passing of the locals set on a fiber.Ctx to the template engine
190+
//
191+
// Default: false
192+
PassLocalsToViews bool `json:"pass_locals_to_views"`
193+
229194
// The amount of time allowed to read the full request including body.
230195
// It is reset after the request handler has returned.
231196
// The connection's read deadline is reset when the connection opens.
@@ -258,39 +223,19 @@ type Config struct {
258223
// Default: 4096
259224
WriteBufferSize int `json:"write_buffer_size"`
260225

261-
// When set to true, the router treats "/foo" and "/foo/" as different.
262-
// By default this is disabled and both "/foo" and "/foo/" will execute the same handler.
263-
//
264-
// Default: false
265-
StrictRouting bool `json:"strict_routing"`
266-
267-
// When set to true, enables case sensitive routing.
268-
// E.g. "/FoO" and "/foo" are treated as different routes.
269-
// By default this is disabled and both "/FoO" and "/foo" will execute the same handler.
270-
//
271-
// Default: false
272-
CaseSensitive bool `json:"case_sensitive"`
273-
274-
// When set to true, this relinquishes the 0-allocation promise in certain
275-
// cases in order to access the handler values (e.g. request bodies) in an
276-
// immutable fashion so that these values are available even if you return
277-
// from handler.
278-
//
279-
// Default: false
280-
Immutable bool `json:"immutable"`
281-
282-
// When set to true, converts all encoded characters in the route back
283-
// before setting the path for the context, so that the routing,
284-
// the returning of the current url from the context `ctx.Path()`
285-
// and the parameters `ctx.Params(%key%)` with decoded characters will work
226+
// CompressedFileSuffixes adds suffix to the original file name and
227+
// tries saving the resulting compressed file under the new file name.
286228
//
287-
// Default: false
288-
UnescapePath bool `json:"unescape_path"`
229+
// Default: map[string]string{"gzip": ".fiber.gz", "br": ".fiber.br", "zstd": ".fiber.zst"}
230+
CompressedFileSuffixes map[string]string `json:"compressed_file_suffixes"`
289231

290-
// PassLocalsToViews Enables passing of the locals set on a fiber.Ctx to the template engine
232+
// ProxyHeader will enable c.IP() to return the value of the given header key
233+
// By default c.IP() will return the Remote IP from the TCP connection
234+
// This property can be useful if you are behind a load balancer: X-Forwarded-*
235+
// NOTE: headers are easily spoofed and the detected IP addresses are unreliable.
291236
//
292-
// Default: false
293-
PassLocalsToViews bool `json:"pass_locals_to_views"`
237+
// Default: ""
238+
ProxyHeader string `json:"proxy_header"`
294239

295240
// GETOnly rejects all non-GET requests if set to true.
296241
// This option is useful as anti-DoS protection for servers
@@ -300,6 +245,11 @@ type Config struct {
300245
// Default: false
301246
GETOnly bool `json:"get_only"`
302247

248+
// ErrorHandler is executed when an error is returned from fiber.Handler.
249+
//
250+
// Default: DefaultErrorHandler
251+
ErrorHandler ErrorHandler `json:"-"`
252+
303253
// When set to true, disables keep-alive connections.
304254
// The server will close incoming connections after sending the first response to client.
305255
//
@@ -322,6 +272,11 @@ type Config struct {
322272
// Default: false
323273
DisableHeaderNormalizing bool `json:"disable_header_normalizing"`
324274

275+
// This function allows to setup app name for the app
276+
//
277+
// Default: nil
278+
AppName string `json:"app_name"`
279+
325280
// StreamRequestBody enables request body streaming,
326281
// and calls the handler sooner when given body is
327282
// larger than the current limit.
@@ -349,6 +304,27 @@ type Config struct {
349304
// Default: false
350305
ReduceMemoryUsage bool `json:"reduce_memory_usage"`
351306

307+
// When set by an external client of Fiber it will use the provided implementation of a
308+
// JSONMarshal
309+
//
310+
// Allowing for flexibility in using another json library for encoding
311+
// Default: json.Marshal
312+
JSONEncoder utils.JSONMarshal `json:"-"`
313+
314+
// When set by an external client of Fiber it will use the provided implementation of a
315+
// JSONUnmarshal
316+
//
317+
// Allowing for flexibility in using another json library for decoding
318+
// Default: json.Unmarshal
319+
JSONDecoder utils.JSONUnmarshal `json:"-"`
320+
321+
// XMLEncoder set by an external client of Fiber it will use the provided implementation of a
322+
// XMLMarshal
323+
//
324+
// Allowing for flexibility in using another XML library for encoding
325+
// Default: xml.Marshal
326+
XMLEncoder utils.XMLMarshal `json:"-"`
327+
352328
// If you find yourself behind some sort of proxy, like a load balancer,
353329
// then certain header information may be sent to you using special X-Forwarded-* headers or the Forwarded header.
354330
// For example, the Host HTTP header is usually used to return the requested host.
@@ -371,13 +347,36 @@ type Config struct {
371347
// Default: false
372348
EnableTrustedProxyCheck bool `json:"enable_trusted_proxy_check"`
373349

350+
// Read EnableTrustedProxyCheck doc.
351+
//
352+
// Default: []string
353+
TrustedProxies []string `json:"trusted_proxies"`
354+
trustedProxiesMap map[string]struct{}
355+
trustedProxyRanges []*net.IPNet
356+
374357
// If set to true, c.IP() and c.IPs() will validate IP addresses before returning them.
375358
// Also, c.IP() will return only the first valid IP rather than just the raw header
376359
// WARNING: this has a performance cost associated with it.
377360
//
378361
// Default: false
379362
EnableIPValidation bool `json:"enable_ip_validation"`
380363

364+
// You can define custom color scheme. They'll be used for startup message, route list and some middlewares.
365+
//
366+
// Optional. Default: DefaultColors
367+
ColorScheme Colors `json:"color_scheme"`
368+
369+
// If you want to validate header/form/query... automatically when to bind, you can define struct validator.
370+
// Fiber doesn't have default validator, so it'll skip validator step if you don't use any validator.
371+
//
372+
// Default: nil
373+
StructValidator StructValidator
374+
375+
// RequestMethods provides customizibility for HTTP methods. You can add/remove methods as you wish.
376+
//
377+
// Optional. Default: DefaultMethods
378+
RequestMethods []string
379+
381380
// EnableSplittingOnParsers splits the query/body/header parameters by comma when it's true.
382381
// For example, you can use it to parse multiple values from a query parameter like this:
383382
// /api?foo=bar,baz == foo[]=bar&foo[]=baz

0 commit comments

Comments
 (0)