Skip to content

Commit

Permalink
resolve url by id
Browse files Browse the repository at this point in the history
  • Loading branch information
asim committed Sep 2, 2022
1 parent 3604044 commit 63be799
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 7 deletions.
4 changes: 4 additions & 0 deletions url/handler/url.go
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,10 @@ func (e *Url) List(ctx context.Context, req *url.ListRequest, rsp *url.ListRespo
func (e *Url) Resolve(ctx context.Context, req *url.ResolveRequest, rsp *url.ResolveResponse) error {
id := strings.Replace(req.ShortURL, e.hostPrefix, "", -1)

if len(req.Id) > 0 {
id = req.Id
}

records, err := store.Read("url/" + id)
if err != nil {
return err
Expand Down
22 changes: 16 additions & 6 deletions url/proto/url.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion url/proto/url.proto
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,10 @@ message UpdateResponse {}

// Resolve returns the destination URL of a short URL.
message ResolveRequest {
// resolve by id
string id = 1;
// short url to resolve
string shortURL = 1;
string shortURL = 2;
}

message ResolveResponse {
Expand Down

0 comments on commit 63be799

Please sign in to comment.