123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121 |
- package kinds
- import (
- "errors"
- "net/url"
- "mimicry/shared"
- "mimicry/request"
- )
- type Object interface {
- String() string
- Kind() (string, error)
- Identifier() (*url.URL, error)
- Category() string
- }
- func Create(input any, source *url.URL) (Object, error) {
- unstructured, ok := input.(shared.JSON)
- if !ok {
- return nil, errors.New("Cannot construct with a non-object JSON")
- }
- kind, err := shared.Get[string](unstructured, "type")
- if err != nil {
- return nil, err
- }
- id, err := shared.GetURL(unstructured, "id")
- if err != nil {
- return nil, err
- }
-
-
-
- if source != nil && source.Hostname() != id.Hostname() || len(unstructured) <= 2 {
- response, err := request.Fetch(id)
- if err != nil {
- return nil, err
- }
- return Create(response, nil)
- }
-
-
- switch kind {
- case "Article":
- fallthrough
- case "Audio":
- fallthrough
- case "Document":
- fallthrough
- case "Image":
- fallthrough
- case "Note":
- fallthrough
- case "Page":
- fallthrough
- case "Video":
-
- post := Post{}
- post = unstructured
- return post, nil
-
-
-
-
-
-
-
-
-
-
- case "Application":
- fallthrough
- case "Group":
- fallthrough
- case "Organization":
- fallthrough
- case "Person":
- fallthrough
- case "Service":
-
- actor := Actor{}
- actor = unstructured
- return actor, nil
-
-
-
-
-
-
-
-
-
-
- default:
- return nil, errors.New("Object of Type " + kind + " unsupported")
- }
- }
|