@@ -23,13 +23,16 @@ const (
2323
2424var rApplicationJSON = regexp .MustCompile (`^application/(\w*\+)?json$` )
2525
26+ // ErrCacheMiss is an error when there is no info in cache
2627var ErrCacheMiss = errors .New ("cache miss" )
2728
29+ // CacheEngine is engine interface for cache storages
2830type CacheEngine interface {
2931 Get (key string ) (doc * ld.RemoteDocument , expireTime time.Time , err error )
3032 Set (key string , doc * ld.RemoteDocument , expireTime time.Time ) error
3133}
3234
35+ // IPFSClient interface
3336type IPFSClient interface {
3437 Cat (url string ) (io.ReadCloser , error )
3538}
@@ -42,8 +45,10 @@ type documentLoader struct {
4245 httpClient * http.Client
4346}
4447
48+ // DocumentLoaderOption is an option for document loader
4549type DocumentLoaderOption func (* documentLoader )
4650
51+ // WithCacheEngine is an option for setting cache
4752func WithCacheEngine (cacheEngine CacheEngine ) DocumentLoaderOption {
4853 return func (loader * documentLoader ) {
4954 if cacheEngine == nil {
@@ -55,6 +60,7 @@ func WithCacheEngine(cacheEngine CacheEngine) DocumentLoaderOption {
5560 }
5661}
5762
63+ // WithHTTPClient is an option for setting http client
5864func WithHTTPClient (httpClient * http.Client ) DocumentLoaderOption {
5965 return func (loader * documentLoader ) {
6066 loader .httpClient = httpClient
@@ -82,6 +88,7 @@ func NewDocumentLoader(ipfsCli IPFSClient, ipfsGW string,
8288 return loader
8389}
8490
91+ // LoadDocument loads document from ipfs or http / https source
8592func (d * documentLoader ) LoadDocument (
8693 u string ) (doc * ld.RemoteDocument , err error ) {
8794
0 commit comments