From 8aff1113367b2875a33f31aef3dad8afabadb246 Mon Sep 17 00:00:00 2001 From: Farhan Khan Date: Mon, 14 Dec 2020 21:50:31 +0000 Subject: [PATCH] intermediate parsing web received --- engine/web.go | 50 +++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 41 insertions(+), 9 deletions(-) diff --git a/engine/web.go b/engine/web.go index 799886f..2be0bbb 100644 --- a/engine/web.go +++ b/engine/web.go @@ -9,13 +9,20 @@ import ( "os" ) -type InboxContent struct { -// AtContext string `json:"@context"` +type CreateObject struct { Actor string `json:"actor"` Cc []string `json:"cc"` - Context string `json:"content"` + Content string `json:"content"` + To []string `json:"to"` + Type string `json:"type"` +} + +type FindType struct { + Actor string `json:"actor"` + Cc []string `json:"cc"` + //Object interface{} `json:"Object"` + Object json.RawMessage `json:"Object"` Id string `json:"id"` - //Object string `json:"object"` Published string `json:"published"` To []string `json:"to"` Type string `json:"type"` @@ -93,11 +100,36 @@ func inbox(w http.ResponseWriter, r *http.Request) { return } - var q InboxContent - err = json.Unmarshal(body, &q) - fmt.Println(err) - fmt.Println(q.Cc) - fmt.Println(q) + var findtype FindType + err = json.Unmarshal(body, &findtype) + + fmt.Println(findtype.Type) + + switch findtype.Type { + case "Create": + var createobject CreateObject + + err = json.Unmarshal(findtype.Object, &createobject) + if err != nil { + fmt.Println("Ignore the post here") + } + fmt.Println("Content: ", createobject.Content) + case "Like": + case "Announcement": + case "Delete": + case "Undo": + default: + fmt.Println("Others --> " + findtype.Type) + } + + fmt.Println("Actor: ", findtype.Actor) + fmt.Println("Cc: ", findtype.Cc) + fmt.Println("Id: ", findtype.Id) + fmt.Println("Published: ", findtype.Published) + fmt.Println("To: ", findtype.To) + fmt.Println("Type: ", findtype.Type) + + fmt.Println("Object: ", string(findtype.Object)) } func users_fedilogue_followers(w http.ResponseWriter, r *http.Request) {