forked from tangled.org/core
Monorepo for Tangled

appview: use typed request helper for RepoIndexResponse

authored by oppi.li and committed by Tangled e1dc49bf fab20bf9

Changed files
+6 -18
appview
state
knotclient
+2 -16
appview/state/repo.go
··· 54 54 return 55 55 } 56 56 57 - resp, err := us.Index(f.OwnerDid(), f.RepoName, ref) 57 + result, err := us.Index(f.OwnerDid(), f.RepoName, ref) 58 58 if err != nil { 59 59 s.pages.Error503(w) 60 60 log.Println("failed to reach knotserver", err) 61 - return 62 - } 63 - defer resp.Body.Close() 64 - 65 - body, err := io.ReadAll(resp.Body) 66 - if err != nil { 67 - log.Printf("Error reading response body: %v", err) 68 - return 69 - } 70 - 71 - var result types.RepoIndexResponse 72 - err = json.Unmarshal(body, &result) 73 - if err != nil { 74 - log.Printf("Error unmarshalling response body: %v", err) 75 61 return 76 62 } 77 63 ··· 155 141 LoggedInUser: user, 156 142 RepoInfo: repoInfo, 157 143 TagMap: tagMap, 158 - RepoIndexResponse: result, 144 + RepoIndexResponse: *result, 159 145 CommitsTrunc: commitsTrunc, 160 146 TagsTrunc: tagsTrunc, 161 147 ForkInfo: forkInfo,
+2
knotclient/signer.go
··· 7 7 "encoding/hex" 8 8 "encoding/json" 9 9 "fmt" 10 + "io" 11 + "log" 10 12 "net/http" 11 13 "net/url" 12 14 "time"
+2 -2
knotclient/unsigned.go
··· 75 75 return &result, nil 76 76 } 77 77 78 - func (us *UnsignedClient) Index(ownerDid, repoName, ref string) (*http.Response, error) { 78 + func (us *UnsignedClient) Index(ownerDid, repoName, ref string) (*types.RepoIndexResponse, error) { 79 79 const ( 80 80 Method = "GET" 81 81 ) ··· 90 90 return nil, err 91 91 } 92 92 93 - return us.client.Do(req) 93 + return do[types.RepoIndexResponse](us, req) 94 94 } 95 95 96 96 func (us *UnsignedClient) Log(ownerDid, repoName, ref string, page int) (*http.Response, error) {