loading up the forgejo repo on tangled to test page performance
at forgejo 1.3 kB view raw
1// Copyright 2023 The Forgejo Authors. All rights reserved. 2// SPDX-License-Identifier: MIT 3 4package forgefed 5 6import ( 7 ap "github.com/go-ap/activitypub" 8 "github.com/valyala/fastjson" 9) 10 11const ForgeFedNamespaceURI = "https://forgefed.org/ns" 12 13// GetItemByType instantiates a new ForgeFed object if the type matches 14// otherwise it defaults to existing activitypub package typer function. 15func GetItemByType(typ ap.ActivityVocabularyType) (ap.Item, error) { 16 switch typ { 17 case RepositoryType: 18 return RepositoryNew(""), nil 19 default: 20 return ap.GetItemByType(typ) 21 } 22} 23 24// JSONUnmarshalerFn is the function that will load the data from a fastjson.Value into an Item 25// that the go-ap/activitypub package doesn't know about. 26func JSONUnmarshalerFn(typ ap.ActivityVocabularyType, val *fastjson.Value, i ap.Item) error { 27 switch typ { 28 case RepositoryType: 29 return OnRepository(i, func(r *Repository) error { 30 return JSONLoadRepository(val, r) 31 }) 32 default: 33 return nil 34 } 35} 36 37// NotEmpty is the function that checks if an object is empty 38func NotEmpty(i ap.Item) bool { 39 if ap.IsNil(i) { 40 return false 41 } 42 switch i.GetType() { 43 case RepositoryType: 44 r, err := ToRepository(i) 45 if err != nil { 46 return false 47 } 48 return ap.NotEmpty(r.Actor) 49 default: 50 return ap.NotEmpty(i) 51 } 52}