Fix whoAmI to use json marshalling instead of string concatenation
also add a a comment to formatjsonpull/15/head
parent
898c97700f
commit
f3e0c1bd61
33
actor.go
33
actor.go
|
@ -286,22 +286,25 @@ func (a *Actor) save() error {
|
|||
}
|
||||
|
||||
func (a *Actor) whoAmI() string {
|
||||
return `{"@context":["https://www.w3.org/ns/activitystreams"],
|
||||
"type": "` + a.actorType + `",
|
||||
"id": "` + baseURL + a.Name + `",
|
||||
"name": "` + a.Name + `",
|
||||
"preferredUsername": "` + a.Name + `",
|
||||
"summary": "` + a.summary + `",
|
||||
"inbox": "` + baseURL + a.Name + `/inbox",
|
||||
"outbox": "` + baseURL + a.Name + `/outbox",
|
||||
"followers": "` + baseURL + a.Name + `/peers/followers",
|
||||
"following": "` + baseURL + a.Name + `/peers/following",
|
||||
"publicKey": {
|
||||
"id": "` + baseURL + a.Name + `#main-key",
|
||||
"owner": "` + baseURL + a.Name + `",
|
||||
"publicKeyPem": "` + strings.ReplaceAll(a.publicKeyPem, "\n", "\\n") + `"
|
||||
|
||||
self := make(map[string]interface{})
|
||||
self["@context"] = context()
|
||||
self["type"] = a.actorType
|
||||
self["id"] = baseURL + a.Name
|
||||
self["name"] = a.Name
|
||||
self["preferredUsername"] = a.Name
|
||||
self["summary"] = a.summary
|
||||
self["inbox"] = baseURL + a.Name + "/inbox"
|
||||
self["outbox"] = baseURL + a.Name + "/outbox"
|
||||
self["followers"] = baseURL + a.Name + "/peers/followers"
|
||||
self["following"] = baseURL + a.Name + "/peers/following"
|
||||
self["publicKey"] = map[string]string{
|
||||
"id" : baseURL + a.Name + "#main-key",
|
||||
"owner" : baseURL + a.Name,
|
||||
"publicKeyPem" : strings.ReplaceAll(a.publicKeyPem, "\n", "\\n"),
|
||||
}
|
||||
}`
|
||||
selfString, _ := json.Marshal(self)
|
||||
return string(selfString)
|
||||
}
|
||||
|
||||
func (a *Actor) newItemID() (hash string, url string) {
|
||||
|
|
|
@ -1,12 +1,13 @@
|
|||
package activityserve
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"github.com/gologme/log"
|
||||
"net/http"
|
||||
"encoding/json"
|
||||
"bytes"
|
||||
|
||||
"github.com/gologme/log"
|
||||
)
|
||||
|
||||
// RemoteActor is a type that holds an actor
|
||||
|
@ -60,7 +61,7 @@ func get(iri string) (info map[string]interface{}, err error) {
|
|||
log.Info(err)
|
||||
return
|
||||
}
|
||||
req.Header.Add("Accept", "application/activity+json; profile=\"https://www.w3.org/ns/activitystreams\"")
|
||||
req.Header.Add("Accept", "application/activity+json")
|
||||
req.Header.Add("User-Agent", userAgent+" "+version)
|
||||
req.Header.Add("Accept-Charset", "utf-8")
|
||||
|
||||
|
|
Loading…
Reference in New Issue