Skip to content

Commit c02c8b2

Browse files
committed
refactor: fix linter #289
1 parent 3017d8a commit c02c8b2

26 files changed

+187
-147
lines changed

.golangci.yml

-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@ linters:
8383
issues:
8484
new: false
8585
fix: false
86-
new-from-rev: 2399c75fbd6c738c4cddf38a3ad7f5f97367e5ec
8786
exclude-rules:
8887
- path: _test\.go
8988
linters:

app.go

+32-27
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package flamingo
22

33
import (
44
"context"
5+
"errors"
56
"flag"
67
"fmt"
78
"log"
@@ -109,12 +110,13 @@ func NewApplication(modules []dingo.Module, options ...ApplicationOption) (*Appl
109110
option(app)
110111
}
111112

113+
var flamingoConfig arrayFlags
114+
112115
app.flagset = flag.NewFlagSet("flamingo", flag.ContinueOnError)
113116
dingoTraceCircular := app.flagset.Bool("dingo-trace-circular", false, "enable dingo circular tracing")
114117
flamingoConfigLog := app.flagset.Bool("flamingo-config-log", false, "enable flamingo config logging")
115118
flamingoConfigCueDebug := app.flagset.String("flamingo-config-cue-debug", "", "query the flamingo cue config loader (use . for root)")
116119
flamingoContext := app.flagset.String("flamingo-context", app.defaultContext, "set flamingo execution context")
117-
var flamingoConfig arrayFlags
118120
app.flagset.Var(&flamingoConfig, "flamingo-config", "add additional flamingo yaml config")
119121
dingoInspect := app.flagset.Bool("dingo-inspect", false, "inspect dingo")
120122

@@ -218,52 +220,54 @@ func (app *Application) Run() error {
218220
return fmt.Errorf("get initialized injector: %w", err)
219221
}
220222

221-
i, err := injector.GetAnnotatedInstance(new(cobra.Command), "flamingo")
223+
instance, err := injector.GetAnnotatedInstance(new(cobra.Command), "flamingo")
222224
if err != nil {
223225
return fmt.Errorf("app: get flamingo cobra.Command: %w", err)
224226
}
225227

226-
rootCmd := i.(*cobra.Command)
228+
rootCmd := instance.(*cobra.Command)
227229
rootCmd.SetArgs(app.flagset.Args())
228230

229-
i, err = injector.GetInstance(new(eventRouterProvider))
231+
instance, err = injector.GetInstance(new(eventRouterProvider))
230232
if err != nil {
231233
return fmt.Errorf("app: get eventRouterProvider: %w", err)
232234
}
233-
i.(eventRouterProvider)().Dispatch(context.Background(), new(flamingo.StartupEvent))
235+
instance.(eventRouterProvider)().Dispatch(context.Background(), new(flamingo.StartupEvent))
234236

235237
return rootCmd.Execute()
236238
}
237239

238-
func typeName(of reflect.Type) string {
240+
func typeName(target reflect.Type) string {
239241
var name string
240242

241-
for of.Kind() == reflect.Ptr {
242-
of = of.Elem()
243+
for target.Kind() == reflect.Ptr {
244+
target = target.Elem()
243245
}
244246

245-
if of.Kind() == reflect.Slice {
247+
if target.Kind() == reflect.Slice {
246248
name += "[]"
247-
of = of.Elem()
249+
target = target.Elem()
248250
}
249251

250-
if of.Kind() == reflect.Ptr {
252+
if target.Kind() == reflect.Ptr {
251253
name += "*"
252-
of = of.Elem()
254+
target = target.Elem()
253255
}
254256

255-
if of.PkgPath() != "" {
256-
name += of.PkgPath() + "."
257+
if target.PkgPath() != "" {
258+
name += target.PkgPath() + "."
257259
}
258260

259-
name += of.Name()
261+
name += target.Name()
260262

261263
return name
262264
}
263265

266+
const truncMax = 25
267+
264268
func trunc(s string) string {
265-
if len(s) > 25 {
266-
return s[:25] + "..."
269+
if len(s) > truncMax {
270+
return s[:truncMax] + "..."
267271
}
268272
return s
269273
}
@@ -297,15 +301,15 @@ func inspect(injector *dingo.Injector) {
297301
fmt.Println("\nMultiBindings:")
298302
injector.Inspect(dingo.Inspector{
299303
InspectMultiBinding: func(of reflect.Type, index int, annotation string, to reflect.Type, provider, instance *reflect.Value, in dingo.Scope) {
300-
//fmt.Printf("%d: ", index)
304+
// fmt.Printf("%d: ", index)
301305
printBinding(of, annotation, to, provider, instance, in)
302306
},
303307
})
304308

305309
fmt.Println("\nMapBindings:")
306310
injector.Inspect(dingo.Inspector{
307311
InspectMapBinding: func(of reflect.Type, key string, annotation string, to reflect.Type, provider, instance *reflect.Value, in dingo.Scope) {
308-
//fmt.Printf("%s: ", key)
312+
// fmt.Printf("%s: ", key)
309313
printBinding(of, annotation, to, provider, instance, in)
310314
},
311315
})
@@ -341,7 +345,8 @@ func (a *servemodule) Inject(
341345
a.eventRouter = eventRouter
342346
a.logger = logger
343347
a.server = &http.Server{
344-
Addr: fmt.Sprintf(":%d", cfg.Port),
348+
Addr: fmt.Sprintf(":%d", cfg.Port),
349+
ReadHeaderTimeout: 10 * time.Second,
345350
}
346351
a.configuredSampler = configuredSampler
347352
a.publicEndpoint = cfg.PublicEndpoint
@@ -361,26 +366,26 @@ func (a *servemodule) CueConfig() string {
361366
return `core: serve: port: >= 0 & <= 65535 | *3322`
362367
}
363368

364-
func serveProvider(a *servemodule, logger flamingo.Logger) *cobra.Command {
369+
func serveProvider(serveModule *servemodule, logger flamingo.Logger) *cobra.Command {
365370
serveCmd := &cobra.Command{
366371
Use: "serve",
367372
Short: "Default serve command - starts on Port 3322",
368373
Run: func(cmd *cobra.Command, args []string) {
369-
a.server.Handler = &ochttp.Handler{IsPublicEndpoint: a.publicEndpoint, Handler: a.router.Handler(), GetStartOptions: a.configuredSampler.GetStartOptions()}
374+
serveModule.server.Handler = &ochttp.Handler{IsPublicEndpoint: serveModule.publicEndpoint, Handler: serveModule.router.Handler(), GetStartOptions: serveModule.configuredSampler.GetStartOptions()}
370375

371-
err := a.listenAndServe()
376+
err := serveModule.listenAndServe()
372377
if err != nil {
373-
if err == http.ErrServerClosed {
378+
if errors.Is(err, http.ErrServerClosed) {
374379
logger.Info(err)
375380
} else {
376381
logger.Fatal("unexpected error in serving:", err)
377382
}
378383
}
379384
},
380385
}
381-
serveCmd.Flags().StringVarP(&a.server.Addr, "addr", "a", a.server.Addr, "addr on which flamingo runs")
382-
serveCmd.Flags().StringVarP(&a.certFile, "certFile", "c", "", "certFile to enable HTTPS")
383-
serveCmd.Flags().StringVarP(&a.keyFile, "keyFile", "k", "", "keyFile to enable HTTPS")
386+
serveCmd.Flags().StringVarP(&serveModule.server.Addr, "addr", "a", serveModule.server.Addr, "addr on which flamingo runs")
387+
serveCmd.Flags().StringVarP(&serveModule.certFile, "certFile", "c", "", "certFile to enable HTTPS")
388+
serveCmd.Flags().StringVarP(&serveModule.keyFile, "keyFile", "k", "", "keyFile to enable HTTPS")
384389

385390
return serveCmd
386391
}

core/auth/debug.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ func (c *debugController) Inject(responder *web.Responder, identityService *WebI
2424
}
2525

2626
var tpl = template.Must(template.New("debug").Parse(
27-
//language=gohtml
27+
// language=gohtml
2828
`
2929
<h1>Auth Debug</h1><hr/>
3030
<h2>Registered RequestIdentifier:</h2>

core/auth/identity.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ func (p *securityRoleProvider) All(ctx context.Context, _ *web.Session) []domain
3434
for _, identity := range p.service.IdentifyAll(ctx, request) {
3535
_ = identity
3636
identified = true
37-
//if roler, ok := identity.(hasRoles); ok {
37+
// if roler, ok := identity.(hasRoles); ok {
3838
//roles = append(roles, roler.Roles()...)
3939
//}
4040
}

core/cache/cache.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ type (
2424
Backend interface {
2525
Get(key string) (entry *Entry, found bool) // Get a cache entry
2626
Set(key string, entry *Entry) error // Set a cache entry
27-
//Peek(key string) (entry *CacheEntry, found bool) // Peek for a cache entry, this should not trigger key-updates or weight/priorities to be changed
27+
// Peek(key string) (entry *CacheEntry, found bool) // Peek for a cache entry, this should not trigger key-updates or weight/priorities to be changed
2828
Purge(key string) error
2929
PurgeTags(tags []string) error
3030
Flush() error

core/cache/httpFrontend.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ func (hf *HTTPFrontend) load(ctx context.Context, key string, loader HTTPLoader,
198198

199199
span.AddAttributes(trace.StringAttribute("parenttrace", response.span.TraceID.String()))
200200
span.AddAttributes(trace.StringAttribute("parentspan", response.span.SpanID.String()))
201-
//span.AddLink(trace.Link{
201+
// span.AddLink(trace.Link{
202202
// SpanID: data.(loaderResponse).span.SpanID,
203203
// TraceID: data.(loaderResponse).span.TraceID,
204204
// Type: trace.LinkTypeChild,

core/locale/application/date_time_service.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ func (dts *DateTimeService) Inject(
5050

5151
// GetDateTimeFormatterFromIsoString Need string in format ISO: "2017-11-25T06:30:00Z"
5252
func (dts *DateTimeService) GetDateTimeFormatterFromIsoString(dateTimeString string) (*domain.DateTimeFormatter, error) {
53-
timeResult, err := time.Parse(time.RFC3339, dateTimeString) //"2006-01-02T15:04:05Z"
53+
timeResult, err := time.Parse(time.RFC3339, dateTimeString) // "2006-01-02T15:04:05Z"
5454
if err != nil {
5555
return nil, fmt.Errorf("could not parse date in defined format: %v: %w", dateTimeString, err)
5656
}

core/locale/infrastructure/translation_service.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -61,17 +61,17 @@ func (ts *TranslationService) TranslateLabel(label domain.Label) string {
6161
ts.reloadFilesIfNecessary()
6262
translatedString, err := ts.translateWithLib(label.GetLocaleCode(), label.GetKey(), label.GetCount(), label.GetTranslationArguments())
6363

64-
//while there is an error check fallBacks
64+
// while there is an error check fallBacks
6565
for _, fallbackLocale := range label.GetFallbackLocaleCodes() {
6666
if err != nil {
6767
translatedString, err = ts.translateWithLib(fallbackLocale, label.GetKey(), label.GetCount(), label.GetTranslationArguments())
6868
}
6969
}
7070
if err != nil {
71-
//default to key (=untranslated) if still an error
71+
// default to key (=untranslated) if still an error
7272
translatedString = label.GetKey()
7373
}
74-
//Fallback if label was not translated
74+
// Fallback if label was not translated
7575
if translatedString == label.GetKey() && label.GetDefaultLabel() != "" {
7676
return ts.parseDefaultLabel(label.GetDefaultLabel(), label.GetKey(), label.GetTranslationArguments())
7777
}
@@ -84,11 +84,11 @@ func (ts *TranslationService) Translate(key string, defaultLabel string, localeC
8484
label, err := ts.translateWithLib(localeCode, key, count, translationArguments)
8585

8686
if err != nil {
87-
//default to key (=untranslated) on error
87+
// default to key (=untranslated) on error
8888
label = key
8989
}
9090

91-
//Fallback if label was not translated
91+
// Fallback if label was not translated
9292
if label == key && defaultLabel != "" {
9393
return ts.parseDefaultLabel(defaultLabel, key, translationArguments)
9494
}

core/security/interface/middleware/securityMiddleware.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import (
1616
const (
1717
// ReferrerRedirectStrategy strategy to redirect to the supplied referrer
1818
ReferrerRedirectStrategy = "referrer"
19-
//PathRedirectStrategy strategy to redirect to the supplied path
19+
// PathRedirectStrategy strategy to redirect to the supplied path
2020
PathRedirectStrategy = "path"
2121
)
2222

framework/cmd/module.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ func (m *Module) Configure(injector *dingo.Injector) {
6767
},
6868
Example: `Run with -h or -help to see global debug flags`,
6969
}
70-
//rootCmd.SetHelpTemplate()
70+
// rootCmd.SetHelpTemplate()
7171
rootCmd.FParseErrWhitelist.UnknownFlags = true
7272
for _, set := range flagSetProvider() {
7373
rootCmd.PersistentFlags().AddFlagSet(set)

framework/config/config_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ func TestMapMapInto(t *testing.T) {
130130
}
131131
}
132132

133-
//fill the config map according to the resultType struct
133+
// fill the config map according to the resultType struct
134134
m := make(Map)
135135

136136
assert.NoError(t, m.Add(Map{

framework/config/configcmd.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,9 @@ func dumpConfigArea(a *Area) {
5656
fmt.Println("**************************")
5757
fmt.Println("Area: ", a.Name)
5858
fmt.Println("**************************")
59-
if false { //cuedump {
59+
if false { // cuedump {
6060
// build a cue runtime to verify the config
61-
//cueRuntime := new(cue.Runtime)
61+
// cueRuntime := new(cue.Runtime)
6262
//ci, err := cueRuntime.Build(a.cueBuildInstance)
6363
//if err != nil {
6464
// panic(err)
@@ -71,7 +71,7 @@ func dumpConfigArea(a *Area) {
7171
fmt.Println("")
7272
}
7373

74-
//d, _ := format.Node(ci.Value().Syntax(), format.Simplify())
74+
// d, _ := format.Node(ci.Value().Syntax(), format.Simplify())
7575
//fmt.Println(string(d))
7676
} else {
7777
x, _ := json.MarshalIndent(a.Configuration, "", " ")

framework/web/context.go

+2
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,14 @@ func RunWithDetachedContext(origCtx context.Context, fnc func(ctx context.Contex
1313

1414
request := RequestFromContext(origCtx)
1515
session := SessionFromContext(origCtx)
16+
1617
if request != nil && session == nil {
1718
session = request.Session()
1819
}
1920

2021
ctx := ContextWithRequest(trace.NewContext(context.Background(), span), request)
2122
ctx = ContextWithSession(ctx, session)
2223

24+
//nolint:contextcheck // we want a new context here
2325
fnc(ctx)
2426
}

framework/web/filter.go

+5-4
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ func (fc *FilterChain) Next(ctx context.Context, req *Request, w http.ResponseWr
6060

6161
next := fc.filters[0]
6262
fc.filters = fc.filters[1:]
63+
6364
return next.Filter(ctx, req, w, fc)
6465
}
6566

@@ -74,18 +75,18 @@ func (sf sortableFilers) Len() int {
7475
}
7576

7677
// Less supports implementation for sort.Interface
77-
func (sf sortableFilers) Less(i, j int) bool {
78+
func (sf sortableFilers) Less(indexLeft, indexRight int) bool {
7879
firstPriority := 0
79-
if filter, ok := sf[i].filter.(PrioritizedFilter); ok {
80+
if filter, ok := sf[indexLeft].filter.(PrioritizedFilter); ok {
8081
firstPriority = filter.Priority()
8182
}
8283

8384
secondPriority := 0
84-
if filter, ok := sf[j].filter.(PrioritizedFilter); ok {
85+
if filter, ok := sf[indexRight].filter.(PrioritizedFilter); ok {
8586
secondPriority = filter.Priority()
8687
}
8788

88-
return firstPriority < secondPriority || (firstPriority == secondPriority && sf[i].index > sf[j].index)
89+
return firstPriority < secondPriority || (firstPriority == secondPriority && sf[indexLeft].index > sf[indexRight].index)
8990
}
9091

9192
// Swap supports implementation for sort.Interface

0 commit comments

Comments
 (0)