mirror of
https://github.com/kevin-DL/services.git
synced 2026-01-11 19:04:35 +00:00
rewrite url serfivce
This commit is contained in:
@@ -2,59 +2,47 @@ package handler
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/micro/micro/v3/service/config"
|
||||
"github.com/micro/micro/v3/service/logger"
|
||||
"github.com/micro/micro/v3/service/model"
|
||||
cache "github.com/patrickmn/go-cache"
|
||||
"github.com/teris-io/shortid"
|
||||
|
||||
"github.com/micro/micro/v3/service/errors"
|
||||
"github.com/micro/micro/v3/service/store"
|
||||
"github.com/micro/services/pkg/tenant"
|
||||
url "github.com/micro/services/url/proto"
|
||||
cache "github.com/patrickmn/go-cache"
|
||||
"github.com/teris-io/shortid"
|
||||
)
|
||||
|
||||
const hostPrefix = "https://m3o.one/u/"
|
||||
|
||||
type Url struct {
|
||||
pairs model.Model
|
||||
ownerIndex model.Index
|
||||
cache *cache.Cache
|
||||
hostPrefix string
|
||||
}
|
||||
|
||||
func NewUrl() *Url {
|
||||
var hp string
|
||||
|
||||
cfg, err := config.Get("micro.url.host_prefix")
|
||||
if err != nil {
|
||||
hp = cfg.String(hostPrefix)
|
||||
}
|
||||
|
||||
if len(strings.TrimSpace(hp)) == 0 {
|
||||
hp = hostPrefix
|
||||
}
|
||||
|
||||
ownerIndex := model.ByEquality("owner")
|
||||
ownerIndex.Order.Type = model.OrderTypeUnordered
|
||||
|
||||
m := model.NewModel(
|
||||
model.WithKey("shortURL"),
|
||||
model.WithIndexes(ownerIndex),
|
||||
)
|
||||
m.Register(&url.URLPair{})
|
||||
return &Url{
|
||||
pairs: m,
|
||||
ownerIndex: ownerIndex,
|
||||
hostPrefix: hp,
|
||||
cache: cache.New(cache.NoExpiration, cache.NoExpiration),
|
||||
hostPrefix: hp,
|
||||
}
|
||||
}
|
||||
|
||||
func (e *Url) Shorten(ctx context.Context, req *url.ShortenRequest, rsp *url.ShortenResponse) error {
|
||||
tenantID, ok := tenant.FromContext(ctx)
|
||||
tenantId, ok := tenant.FromContext(ctx)
|
||||
if !ok {
|
||||
return errors.New("Not authorized")
|
||||
return errors.Unauthorized("url.shorten", "not authorized")
|
||||
}
|
||||
sid, err := shortid.New(1, shortid.DefaultABC, 2342)
|
||||
if err != nil {
|
||||
@@ -66,75 +54,83 @@ func (e *Url) Shorten(ctx context.Context, req *url.ShortenRequest, rsp *url.Sho
|
||||
return err
|
||||
}
|
||||
|
||||
p := &url.URLPair{
|
||||
val := &url.URLPair{
|
||||
DestinationURL: req.DestinationURL,
|
||||
ShortURL: id,
|
||||
Owner: tenantID,
|
||||
Created: time.Now().Unix(),
|
||||
ShortURL: e.hostPrefix + id,
|
||||
Created: time.Now().Format(time.RFC3339Nano),
|
||||
}
|
||||
rsp.ShortURL = e.hostPrefix + id
|
||||
|
||||
return e.pairs.Create(p)
|
||||
// write a global key
|
||||
key := "url/" + id
|
||||
if err := store.Write(store.NewRecord(key, val)); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// write per owner key
|
||||
key = "urlOwner/" + tenantId + "/" + id
|
||||
if err := store.Write(store.NewRecord(key, val)); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (e *Url) List(ctx context.Context, req *url.ListRequest, rsp *url.ListResponse) error {
|
||||
tenantID, ok := tenant.FromContext(ctx)
|
||||
tenantId, ok := tenant.FromContext(ctx)
|
||||
if !ok {
|
||||
return errors.New("Not authorized")
|
||||
return errors.Unauthorized("url.shorten", "not authorized")
|
||||
}
|
||||
|
||||
rsp.UrlPairs = []*url.URLPair{}
|
||||
rsp.Urls = []*url.URLPair{}
|
||||
var err error
|
||||
if req.ShortURL != "" {
|
||||
err = e.pairs.Read(model.QueryEquals("shortURL", req.ShortURL), &rsp.UrlPairs)
|
||||
|
||||
key := "urlOwner/" + tenantId + "/"
|
||||
|
||||
var opts []store.ReadOption
|
||||
|
||||
if len(req.ShortURL) > 0 {
|
||||
id := strings.Replace(req.ShortURL, e.hostPrefix, "", -1)
|
||||
key += id
|
||||
} else {
|
||||
err = e.pairs.Read(e.ownerIndex.ToQuery(tenantID), &rsp.UrlPairs)
|
||||
opts = append(opts, store.ReadPrefix())
|
||||
}
|
||||
|
||||
records, err := store.Read(key, opts...)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for _, v := range rsp.UrlPairs {
|
||||
// get the counter and add it to db value to improve
|
||||
// accuracy
|
||||
// A thing to keep in mind is that in memory cache hits
|
||||
// from other nodes wont be added to this. Still, hopefully good enough
|
||||
count, ok := e.cache.Get(v.ShortURL)
|
||||
if ok {
|
||||
v.HitCount += count.(int64)
|
||||
|
||||
for _, rec := range records {
|
||||
uri := new(url.URLPair)
|
||||
|
||||
if err := rec.Decode(uri); err != nil {
|
||||
continue
|
||||
}
|
||||
v.ShortURL = e.hostPrefix + v.ShortURL
|
||||
|
||||
rsp.Urls = append(rsp.Urls, uri)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (e *Url) Proxy(ctx context.Context, req *url.ProxyRequest, rsp *url.ProxyResponse) error {
|
||||
var pair url.URLPair
|
||||
id := strings.Replace(req.ShortURL, e.hostPrefix, "", -1)
|
||||
err := e.pairs.Read(model.QueryEquals("shortURL", id), &pair)
|
||||
|
||||
records, err := store.Read("url/" + id)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
v, found := e.cache.Get(id)
|
||||
// @todo there is an ABA problem with this solution
|
||||
// when it comes to the hit counter
|
||||
if !found {
|
||||
e.cache.Set(id, int64(1), cache.NoExpiration)
|
||||
} else {
|
||||
// we null out the counter
|
||||
e.cache.Set(id, int64(0), cache.NoExpiration)
|
||||
if v.(int64)%10 == 0 {
|
||||
go func() {
|
||||
// We add instead of set in case the service runs in multiple
|
||||
// instances
|
||||
pair.HitCount += v.(int64) + int64(1)
|
||||
err = e.pairs.Update(pair)
|
||||
if err != nil {
|
||||
logger.Error(err)
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
||||
if len(records) == 0 {
|
||||
return errors.NotFound("url.proxy", "not found")
|
||||
}
|
||||
|
||||
rsp.DestinationURL = pair.DestinationURL
|
||||
uri := new(url.URLPair)
|
||||
if err := records[0].Decode(uri); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
rsp.DestinationURL = uri.DestinationURL
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
// Code generated by protoc-gen-go. DO NOT EDIT.
|
||||
// versions:
|
||||
// protoc-gen-go v1.26.0
|
||||
// protoc v3.6.1
|
||||
// protoc-gen-go v1.27.1
|
||||
// protoc v3.15.6
|
||||
// source: proto/url.proto
|
||||
|
||||
package url
|
||||
@@ -20,12 +20,13 @@ const (
|
||||
_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20)
|
||||
)
|
||||
|
||||
// Shortens a destination URL and returns a full short URL.
|
||||
// Shorten a long URL
|
||||
type ShortenRequest struct {
|
||||
state protoimpl.MessageState
|
||||
sizeCache protoimpl.SizeCache
|
||||
unknownFields protoimpl.UnknownFields
|
||||
|
||||
// the url to shorten
|
||||
DestinationURL string `protobuf:"bytes,1,opt,name=destinationURL,proto3" json:"destinationURL,omitempty"`
|
||||
}
|
||||
|
||||
@@ -73,6 +74,7 @@ type ShortenResponse struct {
|
||||
sizeCache protoimpl.SizeCache
|
||||
unknownFields protoimpl.UnknownFields
|
||||
|
||||
// the shortened url
|
||||
ShortURL string `protobuf:"bytes,1,opt,name=shortURL,proto3" json:"shortURL,omitempty"`
|
||||
}
|
||||
|
||||
@@ -120,11 +122,12 @@ type URLPair struct {
|
||||
sizeCache protoimpl.SizeCache
|
||||
unknownFields protoimpl.UnknownFields
|
||||
|
||||
// destination url
|
||||
DestinationURL string `protobuf:"bytes,1,opt,name=destinationURL,proto3" json:"destinationURL,omitempty"`
|
||||
ShortURL string `protobuf:"bytes,2,opt,name=shortURL,proto3" json:"shortURL,omitempty"`
|
||||
Owner string `protobuf:"bytes,3,opt,name=owner,proto3" json:"owner,omitempty"`
|
||||
Created int64 `protobuf:"varint,4,opt,name=created,proto3" json:"created,omitempty"`
|
||||
HitCount int64 `protobuf:"varint,5,opt,name=hitCount,proto3" json:"hitCount,omitempty"`
|
||||
// shortened url
|
||||
ShortURL string `protobuf:"bytes,2,opt,name=shortURL,proto3" json:"shortURL,omitempty"`
|
||||
// time of creation
|
||||
Created string `protobuf:"bytes,4,opt,name=created,proto3" json:"created,omitempty"`
|
||||
}
|
||||
|
||||
func (x *URLPair) Reset() {
|
||||
@@ -173,29 +176,14 @@ func (x *URLPair) GetShortURL() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
func (x *URLPair) GetOwner() string {
|
||||
func (x *URLPair) GetCreated() string {
|
||||
if x != nil {
|
||||
return x.Owner
|
||||
return x.Created
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (x *URLPair) GetCreated() int64 {
|
||||
if x != nil {
|
||||
return x.Created
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func (x *URLPair) GetHitCount() int64 {
|
||||
if x != nil {
|
||||
return x.HitCount
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
// List shortened URLs. It has no input parameters, as it will take
|
||||
// the user ID from the token and list the user's (caller's) shortened URLs.
|
||||
// List all the shortened URLs
|
||||
type ListRequest struct {
|
||||
state protoimpl.MessageState
|
||||
sizeCache protoimpl.SizeCache
|
||||
@@ -249,7 +237,7 @@ type ListResponse struct {
|
||||
sizeCache protoimpl.SizeCache
|
||||
unknownFields protoimpl.UnknownFields
|
||||
|
||||
UrlPairs []*URLPair `protobuf:"bytes,1,rep,name=urlPairs,proto3" json:"urlPairs,omitempty"`
|
||||
Urls []*URLPair `protobuf:"bytes,1,rep,name=urls,proto3" json:"urls,omitempty"`
|
||||
}
|
||||
|
||||
func (x *ListResponse) Reset() {
|
||||
@@ -284,16 +272,14 @@ func (*ListResponse) Descriptor() ([]byte, []int) {
|
||||
return file_proto_url_proto_rawDescGZIP(), []int{4}
|
||||
}
|
||||
|
||||
func (x *ListResponse) GetUrlPairs() []*URLPair {
|
||||
func (x *ListResponse) GetUrls() []*URLPair {
|
||||
if x != nil {
|
||||
return x.UrlPairs
|
||||
return x.Urls
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Proxy returns the destination URL of a short URL.
|
||||
// Proxy resolves even URLs not owned by the token holder,
|
||||
// unlike the List endpoint.
|
||||
type ProxyRequest struct {
|
||||
state protoimpl.MessageState
|
||||
sizeCache protoimpl.SizeCache
|
||||
@@ -401,42 +387,37 @@ var file_proto_url_proto_rawDesc = []byte{
|
||||
0x22, 0x2d, 0x0a, 0x0f, 0x53, 0x68, 0x6f, 0x72, 0x74, 0x65, 0x6e, 0x52, 0x65, 0x73, 0x70, 0x6f,
|
||||
0x6e, 0x73, 0x65, 0x12, 0x1a, 0x0a, 0x08, 0x73, 0x68, 0x6f, 0x72, 0x74, 0x55, 0x52, 0x4c, 0x18,
|
||||
0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x73, 0x68, 0x6f, 0x72, 0x74, 0x55, 0x52, 0x4c, 0x22,
|
||||
0x99, 0x01, 0x0a, 0x07, 0x55, 0x52, 0x4c, 0x50, 0x61, 0x69, 0x72, 0x12, 0x26, 0x0a, 0x0e, 0x64,
|
||||
0x65, 0x73, 0x74, 0x69, 0x6e, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x55, 0x52, 0x4c, 0x18, 0x01, 0x20,
|
||||
0x01, 0x28, 0x09, 0x52, 0x0e, 0x64, 0x65, 0x73, 0x74, 0x69, 0x6e, 0x61, 0x74, 0x69, 0x6f, 0x6e,
|
||||
0x55, 0x52, 0x4c, 0x12, 0x1a, 0x0a, 0x08, 0x73, 0x68, 0x6f, 0x72, 0x74, 0x55, 0x52, 0x4c, 0x18,
|
||||
0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x73, 0x68, 0x6f, 0x72, 0x74, 0x55, 0x52, 0x4c, 0x12,
|
||||
0x14, 0x0a, 0x05, 0x6f, 0x77, 0x6e, 0x65, 0x72, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05,
|
||||
0x6f, 0x77, 0x6e, 0x65, 0x72, 0x12, 0x18, 0x0a, 0x07, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x64,
|
||||
0x18, 0x04, 0x20, 0x01, 0x28, 0x03, 0x52, 0x07, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x64, 0x12,
|
||||
0x1a, 0x0a, 0x08, 0x68, 0x69, 0x74, 0x43, 0x6f, 0x75, 0x6e, 0x74, 0x18, 0x05, 0x20, 0x01, 0x28,
|
||||
0x03, 0x52, 0x08, 0x68, 0x69, 0x74, 0x43, 0x6f, 0x75, 0x6e, 0x74, 0x22, 0x29, 0x0a, 0x0b, 0x4c,
|
||||
0x69, 0x73, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x1a, 0x0a, 0x08, 0x73, 0x68,
|
||||
0x6f, 0x72, 0x74, 0x55, 0x52, 0x4c, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x73, 0x68,
|
||||
0x6f, 0x72, 0x74, 0x55, 0x52, 0x4c, 0x22, 0x38, 0x0a, 0x0c, 0x4c, 0x69, 0x73, 0x74, 0x52, 0x65,
|
||||
0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x28, 0x0a, 0x08, 0x75, 0x72, 0x6c, 0x50, 0x61, 0x69,
|
||||
0x72, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x0c, 0x2e, 0x75, 0x72, 0x6c, 0x2e, 0x55,
|
||||
0x52, 0x4c, 0x50, 0x61, 0x69, 0x72, 0x52, 0x08, 0x75, 0x72, 0x6c, 0x50, 0x61, 0x69, 0x72, 0x73,
|
||||
0x22, 0x2a, 0x0a, 0x0c, 0x50, 0x72, 0x6f, 0x78, 0x79, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74,
|
||||
0x12, 0x1a, 0x0a, 0x08, 0x73, 0x68, 0x6f, 0x72, 0x74, 0x55, 0x52, 0x4c, 0x18, 0x01, 0x20, 0x01,
|
||||
0x28, 0x09, 0x52, 0x08, 0x73, 0x68, 0x6f, 0x72, 0x74, 0x55, 0x52, 0x4c, 0x22, 0x37, 0x0a, 0x0d,
|
||||
0x50, 0x72, 0x6f, 0x78, 0x79, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x26, 0x0a,
|
||||
0x0e, 0x64, 0x65, 0x73, 0x74, 0x69, 0x6e, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x55, 0x52, 0x4c, 0x18,
|
||||
0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0e, 0x64, 0x65, 0x73, 0x74, 0x69, 0x6e, 0x61, 0x74, 0x69,
|
||||
0x6f, 0x6e, 0x55, 0x52, 0x4c, 0x32, 0x9e, 0x01, 0x0a, 0x03, 0x55, 0x72, 0x6c, 0x12, 0x36, 0x0a,
|
||||
0x07, 0x53, 0x68, 0x6f, 0x72, 0x74, 0x65, 0x6e, 0x12, 0x13, 0x2e, 0x75, 0x72, 0x6c, 0x2e, 0x53,
|
||||
0x68, 0x6f, 0x72, 0x74, 0x65, 0x6e, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x14, 0x2e,
|
||||
0x75, 0x72, 0x6c, 0x2e, 0x53, 0x68, 0x6f, 0x72, 0x74, 0x65, 0x6e, 0x52, 0x65, 0x73, 0x70, 0x6f,
|
||||
0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x2d, 0x0a, 0x04, 0x4c, 0x69, 0x73, 0x74, 0x12, 0x10, 0x2e,
|
||||
0x75, 0x72, 0x6c, 0x2e, 0x4c, 0x69, 0x73, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a,
|
||||
0x11, 0x2e, 0x75, 0x72, 0x6c, 0x2e, 0x4c, 0x69, 0x73, 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e,
|
||||
0x73, 0x65, 0x22, 0x00, 0x12, 0x30, 0x0a, 0x05, 0x50, 0x72, 0x6f, 0x78, 0x79, 0x12, 0x11, 0x2e,
|
||||
0x75, 0x72, 0x6c, 0x2e, 0x50, 0x72, 0x6f, 0x78, 0x79, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74,
|
||||
0x1a, 0x12, 0x2e, 0x75, 0x72, 0x6c, 0x2e, 0x50, 0x72, 0x6f, 0x78, 0x79, 0x52, 0x65, 0x73, 0x70,
|
||||
0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x42, 0x29, 0x5a, 0x27, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62,
|
||||
0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x6d, 0x69, 0x63, 0x72, 0x6f, 0x2f, 0x73, 0x65, 0x72, 0x76, 0x69,
|
||||
0x63, 0x65, 0x73, 0x2f, 0x75, 0x72, 0x6c, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x3b, 0x75, 0x72,
|
||||
0x6c, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
|
||||
0x67, 0x0a, 0x07, 0x55, 0x52, 0x4c, 0x50, 0x61, 0x69, 0x72, 0x12, 0x26, 0x0a, 0x0e, 0x64, 0x65,
|
||||
0x73, 0x74, 0x69, 0x6e, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x55, 0x52, 0x4c, 0x18, 0x01, 0x20, 0x01,
|
||||
0x28, 0x09, 0x52, 0x0e, 0x64, 0x65, 0x73, 0x74, 0x69, 0x6e, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x55,
|
||||
0x52, 0x4c, 0x12, 0x1a, 0x0a, 0x08, 0x73, 0x68, 0x6f, 0x72, 0x74, 0x55, 0x52, 0x4c, 0x18, 0x02,
|
||||
0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x73, 0x68, 0x6f, 0x72, 0x74, 0x55, 0x52, 0x4c, 0x12, 0x18,
|
||||
0x0a, 0x07, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x64, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52,
|
||||
0x07, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x64, 0x22, 0x29, 0x0a, 0x0b, 0x4c, 0x69, 0x73, 0x74,
|
||||
0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x1a, 0x0a, 0x08, 0x73, 0x68, 0x6f, 0x72, 0x74,
|
||||
0x55, 0x52, 0x4c, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x73, 0x68, 0x6f, 0x72, 0x74,
|
||||
0x55, 0x52, 0x4c, 0x22, 0x30, 0x0a, 0x0c, 0x4c, 0x69, 0x73, 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f,
|
||||
0x6e, 0x73, 0x65, 0x12, 0x20, 0x0a, 0x04, 0x75, 0x72, 0x6c, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28,
|
||||
0x0b, 0x32, 0x0c, 0x2e, 0x75, 0x72, 0x6c, 0x2e, 0x55, 0x52, 0x4c, 0x50, 0x61, 0x69, 0x72, 0x52,
|
||||
0x04, 0x75, 0x72, 0x6c, 0x73, 0x22, 0x2a, 0x0a, 0x0c, 0x50, 0x72, 0x6f, 0x78, 0x79, 0x52, 0x65,
|
||||
0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x1a, 0x0a, 0x08, 0x73, 0x68, 0x6f, 0x72, 0x74, 0x55, 0x52,
|
||||
0x4c, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x73, 0x68, 0x6f, 0x72, 0x74, 0x55, 0x52,
|
||||
0x4c, 0x22, 0x37, 0x0a, 0x0d, 0x50, 0x72, 0x6f, 0x78, 0x79, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e,
|
||||
0x73, 0x65, 0x12, 0x26, 0x0a, 0x0e, 0x64, 0x65, 0x73, 0x74, 0x69, 0x6e, 0x61, 0x74, 0x69, 0x6f,
|
||||
0x6e, 0x55, 0x52, 0x4c, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0e, 0x64, 0x65, 0x73, 0x74,
|
||||
0x69, 0x6e, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x55, 0x52, 0x4c, 0x32, 0x9e, 0x01, 0x0a, 0x03, 0x55,
|
||||
0x72, 0x6c, 0x12, 0x36, 0x0a, 0x07, 0x53, 0x68, 0x6f, 0x72, 0x74, 0x65, 0x6e, 0x12, 0x13, 0x2e,
|
||||
0x75, 0x72, 0x6c, 0x2e, 0x53, 0x68, 0x6f, 0x72, 0x74, 0x65, 0x6e, 0x52, 0x65, 0x71, 0x75, 0x65,
|
||||
0x73, 0x74, 0x1a, 0x14, 0x2e, 0x75, 0x72, 0x6c, 0x2e, 0x53, 0x68, 0x6f, 0x72, 0x74, 0x65, 0x6e,
|
||||
0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x2d, 0x0a, 0x04, 0x4c, 0x69,
|
||||
0x73, 0x74, 0x12, 0x10, 0x2e, 0x75, 0x72, 0x6c, 0x2e, 0x4c, 0x69, 0x73, 0x74, 0x52, 0x65, 0x71,
|
||||
0x75, 0x65, 0x73, 0x74, 0x1a, 0x11, 0x2e, 0x75, 0x72, 0x6c, 0x2e, 0x4c, 0x69, 0x73, 0x74, 0x52,
|
||||
0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x30, 0x0a, 0x05, 0x50, 0x72, 0x6f,
|
||||
0x78, 0x79, 0x12, 0x11, 0x2e, 0x75, 0x72, 0x6c, 0x2e, 0x50, 0x72, 0x6f, 0x78, 0x79, 0x52, 0x65,
|
||||
0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x12, 0x2e, 0x75, 0x72, 0x6c, 0x2e, 0x50, 0x72, 0x6f, 0x78,
|
||||
0x79, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x42, 0x0d, 0x5a, 0x0b, 0x2e,
|
||||
0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x3b, 0x75, 0x72, 0x6c, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74,
|
||||
0x6f, 0x33,
|
||||
}
|
||||
|
||||
var (
|
||||
@@ -462,7 +443,7 @@ var file_proto_url_proto_goTypes = []interface{}{
|
||||
(*ProxyResponse)(nil), // 6: url.ProxyResponse
|
||||
}
|
||||
var file_proto_url_proto_depIdxs = []int32{
|
||||
2, // 0: url.ListResponse.urlPairs:type_name -> url.URLPair
|
||||
2, // 0: url.ListResponse.urls:type_name -> url.URLPair
|
||||
0, // 1: url.Url.Shorten:input_type -> url.ShortenRequest
|
||||
3, // 2: url.Url.List:input_type -> url.ListRequest
|
||||
5, // 3: url.Url.Proxy:input_type -> url.ProxyRequest
|
||||
|
||||
@@ -2,7 +2,7 @@ syntax = "proto3";
|
||||
|
||||
package url;
|
||||
|
||||
option go_package = "github.com/micro/services/url/proto;url";
|
||||
option go_package = "./proto;url";
|
||||
|
||||
service Url {
|
||||
rpc Shorten(ShortenRequest) returns (ShortenResponse) {}
|
||||
@@ -10,34 +10,34 @@ service Url {
|
||||
rpc Proxy(ProxyRequest) returns (ProxyResponse) {}
|
||||
}
|
||||
|
||||
// Shortens a destination URL and returns a full short URL.
|
||||
// Shorten a long URL
|
||||
message ShortenRequest {
|
||||
// the url to shorten
|
||||
string destinationURL = 1;
|
||||
}
|
||||
|
||||
message ShortenResponse {
|
||||
// the shortened url
|
||||
string shortURL = 1;
|
||||
}
|
||||
|
||||
message URLPair {
|
||||
// destination url
|
||||
string destinationURL = 1;
|
||||
// shortened url
|
||||
string shortURL = 2;
|
||||
string owner = 3;
|
||||
int64 created = 4;
|
||||
// HitCount keeps track many times the short URL has been resolved.
|
||||
// Hitcount only gets saved to disk (database) after every 10th hit, so
|
||||
// its not intended to be 100% accurate, more like an almost correct estimate.
|
||||
int64 hitCount = 5;
|
||||
// time of creation
|
||||
string created = 4;
|
||||
}
|
||||
|
||||
// List information on all the shortened URLs that you have created
|
||||
// List all the shortened URLs
|
||||
message ListRequest {
|
||||
// filter by short URL, optional
|
||||
string shortURL = 2;
|
||||
}
|
||||
|
||||
message ListResponse {
|
||||
repeated URLPair urlPairs = 1;
|
||||
repeated URLPair urls = 1;
|
||||
}
|
||||
|
||||
// Proxy returns the destination URL of a short URL.
|
||||
|
||||
Reference in New Issue
Block a user