refactor: address linter issues
5 files changed, 20 insertions(+), 14 deletions(-)
M cmd/searchix-web/main.go → cmd/searchix-web/main.go
@@ -163,8 +163,10 @@ wg := &sync.WaitGroup{} wg.Add(1) go func() { + sCtx, cancel := context.WithCancel(ctx) defer wg.Done() - err := s.Start(*dev) + defer cancel() + err := s.Start(sCtx, *dev) if err != nil && !errors.Is(err, context.Canceled) { // Error starting or closing listener: logger.Fatal("error", "error", err)
M internal/importer/options.go → internal/importer/options.go
@@ -122,10 +122,10 @@ continue } kv := mv.Value.(jstream.KV) - x := kv.Value.(map[string]interface{}) + x := kv.Value.(map[string]any) var decls []*nix.Link - for _, decl := range x["declarations"].([]interface{}) { + for _, decl := range x["declarations"].([]any) { switch decl := reflect.ValueOf(decl); decl.Kind() { case reflect.String: s := decl.String()@@ -139,7 +139,7 @@ continue } decls = append(decls, link) case reflect.Map: - v := decl.Interface().(map[string]interface{}) + v := decl.Interface().(map[string]any) link := nix.Link{ Name: v["name"].(string), URL: v["url"].(string),
M internal/importer/package.go → internal/importer/package.go
@@ -159,23 +159,23 @@ continue } kv := mv.Value.(jstream.KV) - x := kv.Value.(map[string]interface{}) + x := kv.Value.(map[string]any) - meta := x["meta"].(map[string]interface{}) + meta := x["meta"].(map[string]any) var licenses []nix.License if meta["license"] != nil { switch v := reflect.ValueOf(meta["license"]); v.Kind() { case reflect.Map: - licenses = append(licenses, *convertToLicense(v.Interface().(map[string]interface{}))) + licenses = append(licenses, *convertToLicense(v.Interface().(map[string]any))) case reflect.Array, reflect.Slice: licenses = make([]nix.License, v.Len()) - for i, v := range v.Interface().([]interface{}) { + for i, v := range v.Interface().([]any) { switch v := reflect.ValueOf(v); v.Kind() { case reflect.String: licenses[i] = makeAdhocLicense(v.String()) case reflect.Map: - licenses[i] = *convertToLicense(v.Interface().(map[string]interface{})) + licenses[i] = *convertToLicense(v.Interface().(map[string]any)) default: errs <- fault.Newf( "don't know how to handle sublicense of type %s: %v",@@ -199,7 +199,7 @@ if meta["platforms"] != nil { plats := make([]any, len(meta["platforms"].([]any))) i := 0 - for _, plat := range meta["platforms"].([]interface{}) { + for _, plat := range meta["platforms"].([]any) { switch v := reflect.ValueOf(plat); v.Kind() { case reflect.String: plats[i] = v.String()
M internal/server/server.go → internal/server/server.go
@@ -58,9 +58,12 @@ }, }, nil } -func (s *Server) Start() error { +func (s *Server) Start(ctx context.Context) error { listenAddress := net.JoinHostPort(s.cfg.Web.ListenAddress, strconv.Itoa(s.cfg.Web.Port)) - l, err := net.Listen("tcp", listenAddress) + lc := net.ListenConfig{ + KeepAlive: 5 * time.Minute, + } + l, err := lc.Listen(ctx, "tcp", listenAddress) if err != nil { return fault.Wrap( err, fmsg.Withf("could not listen on address %s and port %d",
M web/searchix.go → web/searchix.go
@@ -1,6 +1,7 @@ package web import ( + "context" "time" "alin.ovh/searchix/internal/config"@@ -39,14 +40,14 @@ options: options, }, nil } -func (s *Server) Start(liveReload bool) error { +func (s *Server) Start(ctx context.Context, liveReload bool) error { var err error s.sv, err = server.New(s.cfg, s.options, s.log.Named("server"), liveReload) if err != nil { return fault.Wrap(err, fmsg.With("error setting up server")) } - err = s.sv.Start() + err = s.sv.Start(ctx) if err != nil { return fault.Wrap(err, fmsg.With("error starting server")) }