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.

refactor(cache): replace valkey-go by valkey-glide

Interface of valkey-go is ugly.

+43 -52
+2 -2
client.go
··· 6 6 "net/http" 7 7 "time" 8 8 9 - "github.com/valkey-io/valkey-go" 9 + glide "github.com/valkey-io/valkey-glide/go/v2" 10 10 site "tangled.org/anhgelus.world/goat-site" 11 11 "tangled.org/anhgelus.world/xrpc" 12 12 "tangled.org/anhgelus.world/xrpc/atproto" ··· 15 15 func NewClient( 16 16 client *http.Client, 17 17 resolver *net.Resolver, 18 - cache valkey.Client, 18 + cache *glide.Client, 19 19 dur time.Duration, 20 20 host string, 21 21 ) xrpc.Client {
+12 -13
cmd/lasad/config/config.go
··· 1 1 package config 2 2 3 3 import ( 4 - "fmt" 5 4 "os" 6 5 7 6 "github.com/BurntSushi/toml" 8 - "github.com/valkey-io/valkey-go" 7 + glide "github.com/valkey-io/valkey-glide/go/v2" 8 + "github.com/valkey-io/valkey-glide/go/v2/config" 9 9 ) 10 10 11 11 const DefaultPath = "/etc/lasad.toml" ··· 30 30 ClientName string `toml:"client_name"` 31 31 } 32 32 33 - func (c *Cache) Connect() (valkey.Client, error) { 34 - addr := c.Host 35 - if c.Port > 0 { 36 - addr += fmt.Sprintf(":%d", c.Port) 33 + func (c *Cache) Connect() (*glide.Client, error) { 34 + cfg := config.NewClientConfiguration(). 35 + WithAddress(&config.NodeAddress{Host: c.Host, Port: int(c.Port)}) 36 + if c.Auth.Password != "" { 37 + if c.Auth.Username != "" { 38 + cfg = cfg.WithCredentials(config.NewServerCredentials(c.Auth.Username, c.Auth.Password)) 39 + } else { 40 + cfg = cfg.WithCredentials(config.NewServerCredentialsWithDefaultUsername(c.Auth.Password)) 41 + } 37 42 } 38 - return valkey.NewClient(valkey.ClientOption{ 39 - InitAddress: []string{addr}, 40 - SelectDB: int(c.DB), 41 - Username: c.Auth.Username, 42 - Password: c.Auth.Password, 43 - ClientName: c.Auth.ClientName, 44 - }) 43 + return glide.NewClient(cfg) 45 44 } 46 45 47 46 func Load(path string) (*Config, error) {
+2 -2
cmd/lasad/run.go
··· 14 14 "syscall" 15 15 "time" 16 16 17 - "github.com/valkey-io/valkey-go" 17 + glide "github.com/valkey-io/valkey-glide/go/v2" 18 18 site "tangled.org/anhgelus.world/goat-site" 19 19 "tangled.org/anhgelus.world/lasa" 20 20 "tangled.org/anhgelus.world/lasa/cmd/internal" ··· 61 61 } 62 62 ctx = context.WithValue(ctx, keyCfg, cfg) 63 63 64 - var cache valkey.Client 64 + var cache *glide.Client 65 65 var dur time.Duration 66 66 if cfg.Cache != nil { 67 67 cache, err = cfg.Cache.Connect()
+10 -23
directory.go
··· 7 7 "log/slog" 8 8 "time" 9 9 10 - "github.com/valkey-io/valkey-go" 10 + glide "github.com/valkey-io/valkey-glide/go/v2" 11 11 "tangled.org/anhgelus.world/xrpc/atproto" 12 12 ) 13 13 14 14 type Directory struct { 15 15 inner atproto.Directory 16 - cache valkey.Client 16 + cache *glide.Client 17 17 duration time.Duration 18 18 limiter *limitManyRequests[*atproto.DIDDocument] 19 19 } 20 20 21 - func NewDirectory(dir atproto.Directory, cache valkey.Client, dur time.Duration) *Directory { 21 + func NewDirectory(dir atproto.Directory, cache *glide.Client, dur time.Duration) *Directory { 22 22 return &Directory{ 23 23 inner: dir, 24 24 cache: cache, ··· 31 31 if d.cache == nil { 32 32 return nil 33 33 } 34 - resp := d.cache.Do(ctx, d.cache.B().Get().Key(key).Build()) 35 - err := resp.Error() 34 + resp, err := d.cache.Get(ctx, key) 36 35 var doc *atproto.DIDDocument 37 36 if err == nil { 38 - b, err := resp.AsBytes() 37 + b := resp.Value() 38 + err = json.Unmarshal([]byte(b), &doc) 39 39 if err == nil { 40 - err = json.Unmarshal(b, &doc) 41 - if err == nil { 42 - return doc 43 - } else { 44 - slog.Warn("cannot unmarshal cache response into DIDDocument", "resp", b) 45 - } 40 + return doc 46 41 } else { 47 - slog.Warn("cannot convert cache response into bytes", "resp", resp) 42 + slog.Warn("cannot unmarshal cache response into DIDDocument", "resp", b) 48 43 } 49 44 } 50 45 return nil ··· 59 54 slog.Warn("cannot marshal DIDDocument", "document", doc, "error", err) 60 55 return 61 56 } 62 - cache := d.cache 63 - err = cache.Do(ctx, cache.B().Set().Key(key).Value(string(b)).Build()).Error() 57 + _, err = d.cache.Set(ctx, key, string(b)) 64 58 if err != nil { 65 59 slog.Warn("cannot set DIDDocument in cache", "document", doc, "error", err) 66 60 return 67 61 } 68 62 slog.Debug("DIDDocument set in cache") 69 - err = cache.Do( 70 - ctx, 71 - cache.B(). 72 - Expireat(). 73 - Key(key). 74 - Timestamp(time.Now().Add(d.duration).Unix()). 75 - Build(), 76 - ).Error() 63 + _, err = d.cache.ExpireAt(ctx, key, time.Now().Add(d.duration)) 77 64 if err != nil { 78 65 slog.Warn("cannot set DIDDocument expire at", "document", doc, "error", err) 79 66 }
+3 -2
go.mod
··· 4 4 5 5 require ( 6 6 github.com/BurntSushi/toml v1.6.0 7 - github.com/valkey-io/valkey-go v1.0.73 7 + github.com/valkey-io/valkey-glide/go/v2 v2.3.1 8 8 tangled.org/anhgelus.world/goat-site v0.1.1 9 9 tangled.org/anhgelus.world/xrpc v0.2.0 10 10 ) 11 11 12 12 require ( 13 + github.com/google/go-cmp v0.7.0 // indirect 13 14 golang.org/x/net v0.52.0 // indirect 14 - golang.org/x/sys v0.42.0 // indirect 15 + google.golang.org/protobuf v1.33.0 // indirect 15 16 )
+14 -10
go.sum
··· 1 1 github.com/BurntSushi/toml v1.6.0 h1:dRaEfpa2VI55EwlIW72hMRHdWouJeRF7TPYhI+AUQjk= 2 2 github.com/BurntSushi/toml v1.6.0/go.mod h1:ukJfTF/6rtPPRCnwkur4qwRxa8vTRFBF0uk2lLoLwho= 3 + github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= 4 + github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 3 5 github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8= 4 6 github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU= 5 - github.com/onsi/gomega v1.38.3 h1:eTX+W6dobAYfFeGC2PV6RwXRu/MyT+cQguijutvkpSM= 6 - github.com/onsi/gomega v1.38.3/go.mod h1:ZCU1pkQcXDO5Sl9/VVEGlDyp+zm0m1cmeG5TOzLgdh4= 7 - github.com/valkey-io/valkey-go v1.0.73 h1:lztOPT0amtR6mwUkeNDcLepdYFdgVpJe/99EohfrmJ4= 8 - github.com/valkey-io/valkey-go v1.0.73/go.mod h1:VGhZ6fs68Qrn2+OhH+6waZH27bjpgQOiLyUQyXuYK5k= 9 - go.yaml.in/yaml/v3 v3.0.4 h1:tfq32ie2Jv2UxXFdLJdh3jXuOzWiL1fo0bu/FbuKpbc= 10 - go.yaml.in/yaml/v3 v3.0.4/go.mod h1:DhzuOOF2ATzADvBadXxruRBLzYTpT36CKvDb3+aBEFg= 7 + github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= 8 + github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= 9 + github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= 10 + github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= 11 + github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= 12 + github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= 13 + github.com/valkey-io/valkey-glide/go/v2 v2.3.1 h1:SB4wY7IjhmRh8WIBAgugoXimoW0mw9ZiGxDbKKhSagU= 14 + github.com/valkey-io/valkey-glide/go/v2 v2.3.1/go.mod h1:LK5zmODJa5xnxZndarh1trntExb3GVGJXz4GwDCagho= 11 15 golang.org/x/net v0.52.0 h1:He/TN1l0e4mmR3QqHMT2Xab3Aj3L9qjbhRm78/6jrW0= 12 16 golang.org/x/net v0.52.0/go.mod h1:R1MAz7uMZxVMualyPXb+VaqGSa3LIaUqk0eEt3w36Sw= 13 - golang.org/x/sys v0.42.0 h1:omrd2nAlyT5ESRdCLYdm3+fMfNFE/+Rf4bDIQImRJeo= 14 - golang.org/x/sys v0.42.0/go.mod h1:4GL1E5IUh+htKOUEOaiffhrAeqysfVGipDYzABqnCmw= 15 - golang.org/x/text v0.35.0 h1:JOVx6vVDFokkpaq1AEptVzLTpDe9KGpj5tR4/X+ybL8= 16 - golang.org/x/text v0.35.0/go.mod h1:khi/HExzZJ2pGnjenulevKNX1W67CUy0AsXcNubPGCA= 17 + google.golang.org/protobuf v1.33.0 h1:uNO2rsAINq/JlFpSdYEKIZ0uKD/R9cpdv0T+yoGwGmI= 18 + google.golang.org/protobuf v1.33.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos= 19 + gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= 20 + gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= 17 21 pgregory.net/rapid v1.2.0 h1:keKAYRcjm+e1F0oAuU5F5+YPAWcyxNNRK2wud503Gnk= 18 22 pgregory.net/rapid v1.2.0/go.mod h1:PY5XlDGj0+V1FCq0o192FdRhpKHGTRIWBgqjDBTrq04= 19 23 tangled.org/anhgelus.world/goat-site v0.1.1 h1:sjjTqrB/xLOAHIiLFay//3vf0fallJCV7jz9sTTsHHI=