mirror of
https://gitlab.melroy.org/melroy/fediresolve.git
synced 2025-06-07 20:08:57 +00:00
Clean up code
This commit is contained in:
parent
cd2f554e50
commit
e3381774b1
3 changed files with 108 additions and 112 deletions
|
@ -6,8 +6,8 @@ import (
|
|||
"os"
|
||||
"strings"
|
||||
|
||||
"gitlab.melroy.org/melroy/fediresolve/resolver"
|
||||
"github.com/spf13/cobra"
|
||||
"gitlab.melroy.org/melroy/fediresolve/resolver"
|
||||
)
|
||||
|
||||
var rootCmd = &cobra.Command{
|
||||
|
@ -48,7 +48,3 @@ The tool supports both direct URLs to posts/comments/threads and Fediverse handl
|
|||
func Execute() error {
|
||||
return rootCmd.Execute()
|
||||
}
|
||||
|
||||
func init() {
|
||||
// Here you can define flags and configuration settings
|
||||
}
|
||||
|
|
|
@ -5,14 +5,14 @@ import (
|
|||
"crypto/rsa"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"io"
|
||||
"net/http"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"gitlab.melroy.org/melroy/fediresolve/formatter"
|
||||
"github.com/go-fed/httpsig"
|
||||
"github.com/tidwall/gjson"
|
||||
"gitlab.melroy.org/melroy/fediresolve/formatter"
|
||||
)
|
||||
|
||||
// Define common constants
|
||||
|
@ -93,12 +93,12 @@ func (r *Resolver) fetchActivityPubObjectWithSignature(objectURL string) (string
|
|||
}
|
||||
|
||||
// Read body for error info
|
||||
body, _ := ioutil.ReadAll(resp.Body)
|
||||
body, _ := io.ReadAll(resp.Body)
|
||||
return "", fmt.Errorf("signed request failed with status: %s, body: %s", resp.Status, string(body))
|
||||
}
|
||||
|
||||
// Read and parse the response
|
||||
body, err := ioutil.ReadAll(resp.Body)
|
||||
body, err := io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("error reading response: %v", err)
|
||||
}
|
||||
|
@ -168,12 +168,12 @@ func (r *Resolver) fetchActivityPubObjectDirect(objectURL string) (string, error
|
|||
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
// Read body for error info
|
||||
body, _ := ioutil.ReadAll(resp.Body)
|
||||
body, _ := io.ReadAll(resp.Body)
|
||||
return "", fmt.Errorf("request failed with status: %s, body: %s", resp.Status, string(body))
|
||||
}
|
||||
|
||||
// Read and parse the response
|
||||
body, err := ioutil.ReadAll(resp.Body)
|
||||
body, err := io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("error reading response: %v", err)
|
||||
}
|
||||
|
@ -251,12 +251,12 @@ func (r *Resolver) fetchWithSignature(objectURL string) (string, error) {
|
|||
fmt.Printf("Received response with status: %s\n", resp.Status)
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
// Read body for error info
|
||||
body, _ := ioutil.ReadAll(resp.Body)
|
||||
body, _ := io.ReadAll(resp.Body)
|
||||
return "", fmt.Errorf("signed request failed with status: %s, body: %s", resp.Status, string(body))
|
||||
}
|
||||
|
||||
// Read and parse the response
|
||||
body, err := ioutil.ReadAll(resp.Body)
|
||||
body, err := io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("error reading response: %v", err)
|
||||
}
|
||||
|
@ -373,7 +373,7 @@ func (r *Resolver) fetchActorData(actorURL string) (map[string]interface{}, erro
|
|||
}
|
||||
|
||||
// Read and parse the response
|
||||
body, err := ioutil.ReadAll(resp.Body)
|
||||
body, err := io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error reading actor response: %v", err)
|
||||
}
|
||||
|
@ -478,7 +478,7 @@ func (r *Resolver) resolveActorViaWebFinger(username, domain string) (string, er
|
|||
}
|
||||
|
||||
// Read and parse the response
|
||||
body, err := ioutil.ReadAll(resp.Body)
|
||||
body, err := io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("error reading WebFinger response: %v", err)
|
||||
}
|
||||
|
|
|
@ -3,7 +3,7 @@ package resolver
|
|||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"io"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strings"
|
||||
|
@ -118,7 +118,7 @@ func (r *Resolver) resolveHandle(handle string) (string, error) {
|
|||
}
|
||||
|
||||
// Read and parse the WebFinger response
|
||||
body, err := ioutil.ReadAll(resp.Body)
|
||||
body, err := io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("error reading WebFinger response: %v", err)
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue