Add basic webfinger check utility
This commit is contained in:
parent
b5047f2607
commit
30bbc1de33
55
cmd/ap-find/main.go
Normal file
55
cmd/ap-find/main.go
Normal file
@ -0,0 +1,55 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func main() {
|
||||
if len(os.Args) < 2 {
|
||||
log.Fatalln("usage: ap-inspect HANDLE")
|
||||
}
|
||||
handle := strings.TrimLeft(os.Args[1], "@")
|
||||
parts := strings.Split(handle, "@")
|
||||
if len(parts) < 2 {
|
||||
log.Fatalln("invalid handle (expected @handle@host.name)")
|
||||
}
|
||||
|
||||
// Set up request
|
||||
wfURL := "https://" + parts[1] + "/.well-known/webfinger?resource=acct:" + handle
|
||||
log.Printf("Webfinger: %s", wfURL)
|
||||
req, err := http.NewRequest("GET", wfURL, nil)
|
||||
if err != nil {
|
||||
log.Fatalln(err)
|
||||
}
|
||||
|
||||
// Send request
|
||||
client := &http.Client{}
|
||||
resp, err := client.Do(req)
|
||||
if err != nil {
|
||||
log.Fatalln(err)
|
||||
}
|
||||
if resp != nil && resp.Body != nil {
|
||||
defer resp.Body.Close()
|
||||
}
|
||||
|
||||
body, err := ioutil.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
log.Fatalln(err)
|
||||
}
|
||||
fmt.Printf("Status : %s\n", resp.Status)
|
||||
|
||||
// Pretty-print the response
|
||||
var fmttd bytes.Buffer
|
||||
err = json.Indent(&fmttd, body, "", " ")
|
||||
if err != nil {
|
||||
log.Fatalln(err)
|
||||
}
|
||||
fmt.Printf("Response:\n%s\n", fmttd.String())
|
||||
}
|
Loading…
Reference in New Issue
Block a user