Files
ultrashorty/main.go
T

37 lines
752 B
Go
Raw Normal View History

2026-03-30 17:38:09 +01:00
package main
import (
"net"
"net/http"
"github.com/alecthomas/kong"
"github.com/rs/zerolog"
2026-03-30 21:42:52 +01:00
"gogs.home.aneur.in/go/ultrashorty/internal"
2026-03-30 17:38:09 +01:00
)
func main() {
2026-03-30 21:42:52 +01:00
cli := &internal.CLI{}
2026-03-30 21:51:48 +01:00
kong.Parse(cli, kong.Name("ultrashorty"), kong.Description("Really simple HTTP redirection using a CSV file."))
2026-03-30 17:38:09 +01:00
2026-03-30 21:42:52 +01:00
redirects, err := internal.ReadCsvRedirects(cli.File)
if err != nil {
panic(err)
}
srv := &internal.HttpServer{
CLI: cli,
Log: zerolog.New(zerolog.NewConsoleWriter()).With().Timestamp().Logger(),
Redirects: redirects,
2026-03-30 17:38:09 +01:00
}
addr := net.JoinHostPort(cli.Host, cli.Port)
errc := make(chan error)
go func() {
errc <- http.ListenAndServe(addr, srv)
}()
srv.Log.Info().Msgf("Listening at %s", addr)
2026-03-30 21:42:52 +01:00
err = <-errc
2026-03-30 17:38:09 +01:00
panic(err)
}