Files
job-search/cmd/jobsearch/main.go
T
bwilliams c9f42b62ad Added websocket hub for handling websocket clients, with a wsserve command
which runs a plain TCP server for receiving websocket hub clients, with
server config, CSRF and rate limit middleware.

- internal/websocket: Hub pushing messages to WebSocket clients (ServeHTTP,
  example.com/ws upgrade with optional CSRF check) and plain TCP clients (ServeTCP,
  newline-delimited JSON envelopes); ping/pong keepalive, per-client message
  rate limit, slow consumer handling, graceful Shutdown, debug logging of
  messages sent and received
- internal/websocket/tcpserver: standalone TCP server for a hub, with accept
  back-off, a per-IP connection limit (server.websocket.connection_limit) and
  graceful shutdown
- internal/cli/wsserve: `wsserve` command running the TCP server, with
  --listen/--host/--port overrides
- internal/middleware: keyed token bucket rate limiter, real client IP from
  trusted proxies
- internal/httpx: RFC 9457 problem responses, request IDs in context
- internal/config: server section (host, port, shutdown timeout, rate limiter
  idle TTL, websocket); util.ByteSize settings (e.g. "32KiB"); lists of
  sections as single keys; empty lists stored as nil; isExplicitlySet for
  printLoadedConfig; JobSearchConfigSource renamed to JSCSourcesSource;
  TestSections checks every section's methods
- internal/util: ByteSize, parsed and formatted with go-humanize
2026-10-14 15:55:25 +01:00

91 lines
2.4 KiB
Go

/*
Copyright © 2026 Craig Williams <craig@avsdev.uk>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
// Command job-search. Run `job-search --help` for usage.
package main
import (
"fmt"
"log/slog"
"os"
"strings"
"git.avsdev.uk/Go/job-search/internal/cli"
"git.avsdev.uk/Go/job-search/internal/cli/config"
"git.avsdev.uk/Go/job-search/internal/cli/fetch"
"git.avsdev.uk/Go/job-search/internal/cli/migrate"
"git.avsdev.uk/Go/job-search/internal/cli/version"
"git.avsdev.uk/Go/job-search/internal/cli/wsserve"
"github.com/spf13/cobra"
)
// newRootCmd builds the command tree. It returns a fresh tree on each call so
// tests can run commands in isolation.
func newRootCmd() *cobra.Command {
opts := &cli.Options{}
root := &cobra.Command{
Use: "job-search",
Short: "JobSearch - AVSDev Future Opportunities!",
Long: `JobSearch is a scraping tool for searching for possible contract
opportunities.
`,
SilenceUsage: true, // don't print usage on runtime errors
SilenceErrors: true, // main prints the error once
CompletionOptions: cobra.CompletionOptions{
HiddenDefaultCmd: true,
},
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
cli.SetupInitialLogging(cmd)
slog.Debug("root.PersistentPreRun")
slog.Debug(
"command: \"" +
strings.Join(strings.Split(cmd.CommandPath(), " ")[1:], " ") +
"\"",
)
return nil
},
PersistentPostRunE: func(cmd *cobra.Command, args []string) error {
slog.Debug("root.PersistentPostRun")
return opts.Finish()
},
}
cobra.EnableTraverseRunHooks = true
opts.Bind(root)
root.AddCommand(
version.NewCommand(),
config.NewCommand(opts),
fetch.NewCommand(opts),
migrate.NewCommand(opts),
wsserve.NewCommand(opts),
)
return root
}
func main() {
if err := newRootCmd().Execute(); err != nil {
fmt.Fprintln(os.Stderr, "job-search:", err)
os.Exit(1)
}
}