github.com/git-amp/amp-sdk-go@v0.7.5/amp/api.assets.go (about) 1 package amp 2 3 import ( 4 "io" 5 "time" 6 7 "github.com/git-amp/amp-sdk-go/stdlib/task" 8 ) 9 10 // Options when publishing an asset 11 type PublishOpts struct { 12 Expiry time.Duration // If <= 0, the publisher chooses the expiration period 13 HostAddr string // Domain or IP address used in the generated URL; if empty -> "localhost" 14 } 15 16 // AssetPublisher publishes a MediaAsset to a randomly generated URL until the idle expiration is reached. 17 // If idleExpiry == 0, the publisher will choose an expiration period. 18 type AssetPublisher interface { 19 PublishAsset(asset MediaAsset, opts PublishOpts) (URL string, err error) 20 } 21 22 // MediaAsset is a flexible wrapper for any data asset that can be streamed -- often audio or video. 23 type MediaAsset interface { 24 25 // Short name or description of this asset used for logging / debugging. 26 Label() string 27 28 // Returns the media (MIME) type of the asset. 29 MediaType() string 30 31 // OnStart is called when this asset is live within the given context. 32 // This MediaAsset should call ctx.Close() if a fatal error occurs or its underlying asset becomes unavailable. 33 OnStart(ctx task.Context) error 34 35 // Called when this asset is requested by a client for read access 36 NewAssetReader() (AssetReader, error) 37 } 38 39 // AssetReader provides read and seek access to its parent MediaAsset. 40 // 41 // Close() is called when: 42 // - the AssetReader is no longer needed (called externally), or 43 // - the AssetReader's parent MediaAsset becomes unavailable. 44 // 45 // Close() could be called at any time from a goroutine outside of a Read() or Seek() call. 46 type AssetReader interface { 47 io.ReadSeekCloser 48 }