github.com/storacha/go-ucanto@v0.7.2/examples/retrieval/capabilities/content/serve.go (about) 1 package content 2 3 import ( 4 ipldprime "github.com/ipld/go-ipld-prime" 5 "github.com/storacha/go-ucanto/core/ipld" 6 "github.com/storacha/go-ucanto/core/schema" 7 "github.com/storacha/go-ucanto/testing/helpers" 8 "github.com/storacha/go-ucanto/validator" 9 ) 10 11 type ServeCaveats struct { 12 Digest []byte 13 Range []int 14 } 15 16 var ServeTypeSystem = helpers.Must(ipldprime.LoadSchemaBytes([]byte(` 17 type ServeCaveats struct { 18 digest Bytes 19 range [Int] 20 } 21 type ServeOk struct { 22 digest Bytes 23 range [Int] 24 } 25 `))) 26 27 func (sc ServeCaveats) ToIPLD() (ipld.Node, error) { 28 return ipld.WrapWithRecovery(&sc, ServeTypeSystem.TypeByName("ServeCaveats")) 29 } 30 31 type ServeOk struct { 32 Digest []byte 33 Range []int 34 } 35 36 func (so ServeOk) ToIPLD() (ipld.Node, error) { 37 return ipld.WrapWithRecovery(&so, ServeTypeSystem.TypeByName("ServeOk")) 38 } 39 40 var ServeCaveatsReader = schema.Struct[ServeCaveats](ServeTypeSystem.TypeByName("ServeCaveats"), nil) 41 42 var Serve = validator.NewCapability( 43 "content/serve", 44 schema.DIDString(), 45 ServeCaveatsReader, 46 validator.DefaultDerives, 47 )