From f3165ac7e77e396cab6e251ec87df1ac2dcd1e4e Mon Sep 17 00:00:00 2001 From: Jan-Lukas Else Date: Fri, 3 Mar 2023 11:20:32 +0100 Subject: [PATCH] Add 5sec timeout for requests to Photon API --- geo.go | 5 ++++- go.mod | 6 +++--- go.sum | 12 ++++++------ 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/geo.go b/geo.go index 8e65792..71acfd6 100644 --- a/geo.go +++ b/geo.go @@ -6,6 +6,7 @@ import ( "encoding/json" "fmt" "strings" + "time" gogeouri "git.jlel.se/jlelse/go-geouri" "github.com/carlmjohnson/requests" @@ -52,7 +53,9 @@ func (a *goBlog) photonReverse(lat, lon float64, lang string) (*geojson.FeatureC rb.Param("lat", fmt.Sprintf("%v", lat)).Param("lon", fmt.Sprintf("%v", lon)) rb.Param("lang", lo.If(lang == "de" || lang == "fr" || lang == "it", lang).Else("en")) // Photon only supports en, de, fr, it // Do request - if err := rb.Fetch(context.Background()); err != nil { + ctx, cancelFunc := context.WithTimeout(context.Background(), 5*time.Second) + defer cancelFunc() + if err := rb.Fetch(ctx); err != nil { return nil, err } // Cache response diff --git a/go.mod b/go.mod index 5ae2254..cf8c19c 100644 --- a/go.mod +++ b/go.mod @@ -20,8 +20,8 @@ require ( github.com/dmulholl/mp3lib v1.0.0 github.com/elnormous/contenttype v1.0.4 github.com/emersion/go-smtp v0.16.0 - github.com/go-ap/activitypub v0.0.0-20230218112952-bfb607b04799 - github.com/go-ap/client v0.0.0-20230218115938-0fe3ee2edd31 + github.com/go-ap/activitypub v0.0.0-20230301123505-7471bcd90729 + github.com/go-ap/client v0.0.0-20230302104023-08cd159ca918 github.com/go-ap/jsonld v0.0.0-20221030091449-f2a191312c73 github.com/go-chi/chi/v5 v5.0.8 github.com/go-fed/httpsig v1.1.0 @@ -105,7 +105,7 @@ require ( github.com/mmcdole/goxpp v1.1.0 // indirect github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect github.com/modern-go/reflect2 v1.0.2 // indirect - github.com/pelletier/go-toml/v2 v2.0.6 // indirect + github.com/pelletier/go-toml/v2 v2.0.7 // indirect github.com/pkg/errors v0.9.1 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect github.com/rs/xid v1.4.0 // indirect diff --git a/go.sum b/go.sum index c7095af..a52cad8 100644 --- a/go.sum +++ b/go.sum @@ -129,10 +129,10 @@ github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm github.com/gin-gonic/gin v1.6.3/go.mod h1:75u5sXoLsGZoRN5Sgbi1eraJ4GU3++wFwWzhwvtwp4M= github.com/gin-gonic/gin v1.7.7 h1:3DoBmSbJbZAWqXJC3SLjAPfutPJJRN1U5pALB7EeTTs= github.com/gin-gonic/gin v1.7.7/go.mod h1:axIBovoeJpVj8S3BwE0uPMTeReE4+AfFtqpqaZ1qq1U= -github.com/go-ap/activitypub v0.0.0-20230218112952-bfb607b04799 h1:zVZaYt1h4yWL7uRHvq2StewCu4ObtS+ws9gGgoZJ+2s= -github.com/go-ap/activitypub v0.0.0-20230218112952-bfb607b04799/go.mod h1:1oVD0h0aPT3OEE1ZoSUoym/UGKzxe+e0y8K2AkQ1Hqs= -github.com/go-ap/client v0.0.0-20230218115938-0fe3ee2edd31 h1:oXNZ+n4g3Mz5CKuhX1/pKCYMMiGyAYO8lTV6Pq7dgZc= -github.com/go-ap/client v0.0.0-20230218115938-0fe3ee2edd31/go.mod h1:JM15KH1UF66PPM0RgaIBZRuwWXAWMNky7njnXcfqdlI= +github.com/go-ap/activitypub v0.0.0-20230301123505-7471bcd90729 h1:M0FEFNfmS0ikej+oD5REsiFRRrP6HvvG1rqoj4dD3cM= +github.com/go-ap/activitypub v0.0.0-20230301123505-7471bcd90729/go.mod h1:1oVD0h0aPT3OEE1ZoSUoym/UGKzxe+e0y8K2AkQ1Hqs= +github.com/go-ap/client v0.0.0-20230302104023-08cd159ca918 h1:SDx9+NLFm4DGXELHbKPXL1OpYg3cZ6fkFn2RlxhMAWo= +github.com/go-ap/client v0.0.0-20230302104023-08cd159ca918/go.mod h1:wsghIsxDaai1Y27XKlMYm7eV8WCUsDGww1NfX9ceQ7s= github.com/go-ap/errors v0.0.0-20221205040414-01c1adfc98ea h1:ywGtLGVjJjMrq4mu35Qmu+NtlhlTk/gTayE6Bb4tQZk= github.com/go-ap/errors v0.0.0-20221205040414-01c1adfc98ea/go.mod h1:SaTNjEEkp0q+w3pUS1ccyEL/lUrHteORlDq/e21mCc8= github.com/go-ap/jsonld v0.0.0-20221030091449-f2a191312c73 h1:GMKIYXyXPGIp+hYiWOhfqK4A023HdgisDT4YGgf99mw= @@ -336,8 +336,8 @@ github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9G github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk= github.com/paulmach/go.geojson v1.4.0 h1:5x5moCkCtDo5x8af62P9IOAYGQcYHtxz2QJ3x1DoCgY= github.com/paulmach/go.geojson v1.4.0/go.mod h1:YaKx1hKpWF+T2oj2lFJPsW/t1Q5e1jQI61eoQSTwpIs= -github.com/pelletier/go-toml/v2 v2.0.6 h1:nrzqCb7j9cDFj2coyLNLaZuJTLjWjlaz6nvTvIwycIU= -github.com/pelletier/go-toml/v2 v2.0.6/go.mod h1:eumQOmlWiOPt5WriQQqoM5y18pDHwha2N+QD+EUNTek= +github.com/pelletier/go-toml/v2 v2.0.7 h1:muncTPStnKRos5dpVKULv2FVd4bMOhNePj9CjgDb8Us= +github.com/pelletier/go-toml/v2 v2.0.7/go.mod h1:eumQOmlWiOPt5WriQQqoM5y18pDHwha2N+QD+EUNTek= github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/sftp v1.13.1/go.mod h1:3HaPG6Dq1ILlpPZRO0HVMrsydcdLt6HRDccSgb87qRg=