Skip to content

Commit

Permalink
rename things per issue #1
Browse files Browse the repository at this point in the history
  • Loading branch information
thisisaaronland committed Jun 30, 2021
1 parent 362d831 commit 43ce8ec
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 92 deletions.
2 changes: 1 addition & 1 deletion cmd/lookupd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
)

import (
_ "github.com/aaronland/gocloud-blob-s3"
_ "github.com/aaronland/gocloud-blob-s3"
_ "github.com/whosonfirst/go-cache-blob"
_ "github.com/whosonfirst/go-whosonfirst-findingaid/repo"
)
Expand Down
94 changes: 94 additions & 0 deletions repo/cache.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,106 @@
package repo

import (
"context"
"encoding/json"
"errors"
"fmt"
"github.com/whosonfirst/go-cache"
"github.com/whosonfirst/go-whosonfirst-findingaid"
"github.com/whosonfirst/go-whosonfirst-uri"
_ "log"
"net/url"
"path/filepath"
"strings"
)

// CacheResolver is a struct that implements the findingaid.Resolver interface for information about Who's On First repositories.
type CacheResolver struct {
findingaid.Resolver
cache cache.Cache
}

func init() {

ctx := context.Background()

schemes := []string{
"repo", // deprecated
"repo-cache",
}

for _, s := range schemes {
err := findingaid.RegisterResolver(ctx, s, NewCacheResolver)

if err != nil {
panic(err)
}
}
}

// NewCacheResolver returns a findingaid.Resolver instance for exposing information about Who's On First repositories
func NewCacheResolver(ctx context.Context, uri string) (findingaid.Resolver, error) {

u, err := url.Parse(uri)

if err != nil {
return nil, err
}

q := u.Query()

cache_uri := q.Get("cache")

if cache_uri == "" {
return nil, errors.New("Missing cache URI")
}

_, err = url.Parse(cache_uri)

if err != nil {
return nil, err
}

c, err := cache.NewCache(ctx, cache_uri)

if err != nil {
return nil, err
}

fa := &CacheResolver{
cache: c,
}

return fa, nil
}

// ResolveURI will return 'repo.FindingAidResponse' for 'str_response' if it present in the finding aid.
func (fa *CacheResolver) ResolveURI(ctx context.Context, str_uri string) (interface{}, error) {

key, err := cacheKeyFromURI(str_uri)

if err != nil {
return nil, err
}

fh, err := fa.cache.Get(ctx, key)

if err != nil {
return nil, err
}

var rsp *FindingAidResponse

dec := json.NewDecoder(fh)
err = dec.Decode(&rsp)

if err != nil {
return nil, err
}

return rsp, nil
}

func cacheKeyFromURI(str_uri string) (string, error) {

id, uri_args, err := uri.ParseURI(str_uri)
Expand Down
1 change: 0 additions & 1 deletion repo/cache/docstore.go

This file was deleted.

90 changes: 0 additions & 90 deletions repo/resolver.go

This file was deleted.

0 comments on commit 43ce8ec

Please sign in to comment.