Lasa is a stateless proxy that generates a RSS or an Atom feed from a Standard.site publication. lasa.anhgelus.world
rss atom atprotocol standard-site atproto
2
fork

Configure Feed

Select the types of activity you want to include in your feed.

feat(cli): load config

+34 -3
+7
cmd/lasad/context.go
··· 1 + package main 2 + 3 + type Key uint 4 + 5 + const ( 6 + keyCfg = iota 7 + )
+27 -3
cmd/lasad/run.go
··· 2 2 3 3 import ( 4 4 "context" 5 + "fmt" 6 + "log/slog" 5 7 "net/http" 6 8 "os" 7 9 "os/signal" 8 10 "syscall" 9 11 10 12 "tangled.org/anhgelus.world/lasa/cmd/internal" 13 + "tangled.org/anhgelus.world/lasa/cmd/lasad/config" 11 14 ) 12 15 13 16 func handleRunHelp() { ··· 33 36 ctx, cancel := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGINT, syscall.SIGTERM) 34 37 defer cancel() 35 38 39 + slog.Info("loading config...", "path", configPath) 40 + cfg, err := config.Load(configPath) 41 + if err != nil { 42 + panic(err) 43 + } 44 + ctx = context.WithValue(ctx, keyCfg, cfg) 45 + 36 46 mux := http.NewServeMux() 37 47 38 48 ch := make(chan error, 1) 39 49 40 50 go func() { 41 - ch <- http.ListenAndServe(":8000", mux) 51 + slog.Info("starting...") 52 + ch <- http.ListenAndServe(fmt.Sprintf(":%d", cfg.Port), middlewares(mux, ctx)) 42 53 }() 43 - var err error 44 54 select { 45 55 case <-ctx.Done(): 46 - err = ctx.Err() 56 + err = context.Cause(ctx) 47 57 case err = <-ch: 48 58 } 59 + slog.Info("exiting") 49 60 if err != nil { 50 61 panic(err) 51 62 } 52 63 } 64 + 65 + func middlewares(h http.Handler, ctx context.Context) http.Handler { 66 + return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { 67 + slog.Debug("request", "path", r.URL.Path) 68 + defer func() { 69 + if err := recover(); err != nil { 70 + slog.Error("panic!", "err", err) 71 + w.WriteHeader(http.StatusInternalServerError) 72 + } 73 + }() 74 + h.ServeHTTP(w, r.WithContext(ctx)) 75 + }) 76 + }