Skip to content

Commit

Permalink
Update comment formatting and func and var names (#55)
Browse files Browse the repository at this point in the history
  • Loading branch information
gammazero authored Jun 13, 2023
1 parent ccf2367 commit 7dbe17b
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 13 deletions.
14 changes: 8 additions & 6 deletions find/client/dhash_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,14 @@ func NewDHashClient(stiURL string, options ...Option) (*DHashClient, error) {
return nil, err
}

sURL, err := parseUrl(stiURL)
sURL, err := parseURL(stiURL)
if err != nil {
return nil, err
}

dhsURL := sURL
if len(opts.dhstoreUrl) > 0 {
dhsURL, err = parseUrl(opts.dhstoreUrl)
if len(opts.dhstoreURL) > 0 {
dhsURL, err = parseURL(opts.dhstoreURL)
if err != nil {
return nil, err
}
Expand All @@ -69,7 +69,8 @@ func NewDHashClient(stiURL string, options ...Option) (*DHashClient, error) {
}, nil
}

// Find launches FindAsync in a separate go routine and assembles the result into FindResponse as if it was a synchronous invocation.
// Find launches FindAsync in a separate go routine and assembles the result
// into FindResponse as if it was a synchronous invocation.
func (c *DHashClient) Find(ctx context.Context, mh multihash.Multihash) (*model.FindResponse, error) {
resChan := make(chan model.ProviderResult)
errChan := make(chan error, 1)
Expand Down Expand Up @@ -135,7 +136,8 @@ func (c *DHashClient) FindAsync(ctx context.Context, mh multihash.Multihash, res
for _, emhrs := range encResponse.EncryptedMultihashResults {
for _, evk := range emhrs.EncryptedValueKeys {
vk, err := dhash.DecryptValueKey(evk, mh)
// skip errors as we don't want to fail the whole query, warn instead. Same applies to the rest of the loop.
// skip errors as we don't want to fail the whole query, warn
// instead. Same applies to the rest of the loop.
if err != nil {
log.Warnw("Error decrypting value key", "multihash", mh.B58String(), "evk", b58.Encode(evk), "err", err)
continue
Expand Down Expand Up @@ -213,7 +215,7 @@ func (c *DHashClient) fetchMetadata(ctx context.Context, vk []byte) ([]byte, err
return dhash.DecryptMetadata(findResponse.EncryptedMetadata, vk)
}

func parseUrl(su string) (*url.URL, error) {
func parseURL(su string) (*url.URL, error) {
if !strings.HasPrefix(su, "http://") && !strings.HasPrefix(su, "https://") {
su = "http://" + su
}
Expand Down
2 changes: 1 addition & 1 deletion find/client/http/old_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@ type DHashClient = client.DHashClient

// Deprecated: Use github.com/ipni/go-libipni/find/client
func NewDHashClient(dhstoreURL, stiURL string, options ...client.Option) (*client.DHashClient, error) {
return client.NewDHashClient(stiURL, append(options, client.WithDHStoreUrl(dhstoreURL))...)
return client.NewDHashClient(stiURL, append(options, client.WithDHStoreURL(dhstoreURL))...)
}
14 changes: 8 additions & 6 deletions find/client/option.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (

type config struct {
httpClient *http.Client
dhstoreUrl string
dhstoreURL string
}

// Option is a function that sets a value in a config.
Expand Down Expand Up @@ -35,12 +35,14 @@ func WithClient(c *http.Client) Option {
}
}

// WithDHStoreUrl allows specifying different URLs for dhstore (/multihash and /metadata endpoints) and storetheindex (/providers endpoint).
// This might be useful as dhstore and storetheindex are different services that might not necessarily be behind the same URL. However
// the data from both of them is required to assemble results.
func WithDHStoreUrl(u string) Option {
// WithDHStoreURL allows specifying different URLs for dhstore (/multihash and
// /metadata endpoints) and storetheindex (/providers endpoint). This might be
// useful as dhstore and storetheindex are different services that might not
// necessarily be behind the same URL. However the data from both of them is
// required to assemble results.
func WithDHStoreURL(u string) Option {
return func(cfg *config) error {
cfg.dhstoreUrl = u
cfg.dhstoreURL = u
return nil
}
}

0 comments on commit 7dbe17b

Please sign in to comment.