Add image/delete endpoint (#258)

This commit is contained in:
Dominic Wong
2021-11-04 12:14:05 +00:00
committed by GitHub
parent 93a5efaee4
commit d0456884c8
7 changed files with 223 additions and 43 deletions

1
go.mod
View File

@@ -30,7 +30,6 @@ require (
github.com/kevinburke/twilio-go v0.0.0-20210327194925-1623146bcf73
github.com/lib/pq v1.9.0 // indirect
github.com/m3o/goduckgo v0.0.0-20210630141545-c760fe67b945
github.com/m3o/m3o-go/client v0.0.0-20210421144725-8bfd7992ada3
github.com/mattheath/base62 v0.0.0-20150408093626-b80cdc656a7a // indirect
github.com/mattheath/kala v0.0.0-20171219141654-d6276794bf0e
github.com/micro/micro-go v0.0.0-20211101221015-79ab982f8163

3
go.sum
View File

@@ -319,7 +319,6 @@ github.com/gorilla/handlers v1.4.2/go.mod h1:Qkdc/uu4tH4g6mTK6auzZ766c4CA0Ng8+o/
github.com/gorilla/handlers v1.5.1/go.mod h1:t8XrUpc4KVXb7HGyJ4/cEnwQiaxrX/hz1Zv/4g96P1Q=
github.com/gorilla/mux v1.6.2/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2zaAs=
github.com/gorilla/mux v1.7.3/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2zaAs=
github.com/gorilla/websocket v1.4.1/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
github.com/gorilla/websocket v1.4.2 h1:+/TMaTYc4QFitKJxsQ7Yye35DkWvkdLcvGKqM+x0Ufc=
github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
github.com/grpc-ecosystem/grpc-gateway v1.8.5/go.mod h1:vNeuVxBJEsws4ogUvrchl83t/GYV9WGTSLVdBhOQFDY=
@@ -459,8 +458,6 @@ github.com/linode/linodego v0.10.0/go.mod h1:cziNP7pbvE3mXIPneHj0oRY8L1WtGEIKlZ8
github.com/liquidweb/liquidweb-go v1.6.0/go.mod h1:UDcVnAMDkZxpw4Y7NOHkqoeiGacVLEIG/i5J9cyixzQ=
github.com/m3o/goduckgo v0.0.0-20210630141545-c760fe67b945 h1:jcOqgh+pYNSaPoPOgDaaU5t9j45JzHG3wOBLXUMBfQ0=
github.com/m3o/goduckgo v0.0.0-20210630141545-c760fe67b945/go.mod h1:wQOw7PY6509VQbepPrclbyXfbQ5lpOtIoHdBKbB+OGc=
github.com/m3o/m3o-go/client v0.0.0-20210421144725-8bfd7992ada3 h1:RVt7rqWl4al36BH9OY9k7IXnnooOP0Feanu1bed6X2s=
github.com/m3o/m3o-go/client v0.0.0-20210421144725-8bfd7992ada3/go.mod h1:vmeaYrKYpgVNhny/l7iH8mXS88S7ijUiYni3gZUrCq0=
github.com/markbates/oncer v0.0.0-20181203154359-bf2de49a0be2/go.mod h1:Ld9puTsIW75CHf65OeIOkyKbteujpZVXDpWK6YGZbxE=
github.com/markbates/safe v1.0.1/go.mod h1:nAqgmRi7cY2nqMc92/bSEeQA+R4OheNU2T1kNSCBdG0=
github.com/mattheath/base62 v0.0.0-20150408093626-b80cdc656a7a h1:rnrxZue85aKdMU4nJ50GgKA31lCaVbft+7Xl8OXj55U=

View File

@@ -66,8 +66,7 @@
"run_check": false,
"request": {
"base64": "data:image/png;base64, iVBORw0KGgoAAAANSUhEUgAAADIAAAAyCAYAAAAeP4ixAAAAx0lEQVR4nOzaMaoDMQyE4ZHj+x82vVdhwQoTkzKQEcwP5r0ihT7sbjUTeAJ4HCegXQJYfOYefOyjDuBiz3yjwJBoCIl6QZOeUjTC1Ix1IxEJXF9+0KWsf2bD4bn37OO/c/wuQ9QyRC1D1DJELUPUMkQtQ9QyRC1D1DJELUPUMkQtQ9QyRC1D1DJELUPUMkQtQ9Sa/NG94Tf3j4WBdaxudMEkn4IM2rZBA0wBrvo7aOcpj2emXvLeVt0IGm0GVXUj91mvAAAA//+V2CZl+4AKXwAAAABJRU5ErkJggg==",
"name": "cat.jpeg",
"outputURL": true
"name": "cat.jpeg"
},
"response": {
"url": "cdn.images.m3o.com/your-account-id/cat.jpeg"
@@ -84,5 +83,15 @@
"url": "cdn.images.m3o.com/your-account-id/cat.jpeg"
}
}
],
"delete": [
{
"title": "Delete an uploaded image",
"run_check": false,
"request": {
"url": "https://cdn.m3ocontent.com/micro/images/micro/41e23b39-48dd-42b6-9738-79a313414bb8/cat.png"
},
"response": {}
}
]
}

View File

@@ -11,11 +11,13 @@ import (
"image/png"
"net/http"
"net/url"
"regexp"
"strings"
"github.com/disintegration/imaging"
"github.com/micro/micro/v3/service/config"
merrors "github.com/micro/micro/v3/service/errors"
"github.com/micro/micro/v3/service/logger"
"github.com/micro/micro/v3/service/store"
img "github.com/micro/services/image/proto"
"github.com/micro/services/pkg/tenant"
@@ -45,7 +47,7 @@ func NewImage() *Image {
func (e *Image) Upload(ctx context.Context, req *img.UploadRequest, rsp *img.UploadResponse) error {
tenantID, ok := tenant.FromContext(ctx)
if !ok {
return errors.New("Not authorized")
return merrors.Unauthorized("image.Upload", "Not authorized")
}
var srcImage image.Image
var err error
@@ -134,7 +136,7 @@ func base64ToImage(b64 string) (image.Image, string, error) {
func (e *Image) Resize(ctx context.Context, req *img.ResizeRequest, rsp *img.ResizeResponse) error {
tenantID, ok := tenant.FromContext(ctx)
if !ok {
return errors.New("Not authorized")
return merrors.Unauthorized("image.Resize", "Not authorized")
}
var srcImage image.Image
var err error
@@ -225,7 +227,7 @@ func (e *Image) Resize(ctx context.Context, req *img.ResizeRequest, rsp *img.Res
func (e *Image) Convert(ctx context.Context, req *img.ConvertRequest, rsp *img.ConvertResponse) error {
tenantID, ok := tenant.FromContext(ctx)
if !ok {
return errors.New("Not authorized")
return merrors.Unauthorized("image.Convert", "Not authorized")
}
var srcImage image.Image
var err error
@@ -285,3 +287,30 @@ func (e *Image) Convert(ctx context.Context, req *img.ConvertRequest, rsp *img.C
}
return nil
}
func (e *Image) Delete(ctx context.Context, request *img.DeleteRequest, response *img.DeleteResponse) error {
tenantID, ok := tenant.FromContext(ctx)
if !ok {
return merrors.Unauthorized("image.Delete", "Not authorized")
}
if len(request.Url) == 0 {
return merrors.BadRequest("image.Delete", "Missing URL parameter")
}
// parse the url <hostprefix>/micro/images/<tenantid>/<name>
match, err := regexp.MatchString(fmt.Sprintf("^%s/micro/images/%s/.*", e.hostPrefix, tenantID), request.Url)
if err != nil {
logger.Errorf("Error matching req url %s", err)
return merrors.InternalServerError("image.Delete", "Error processing delete")
}
if !match {
logger.Infof("No match %s", request.Url, tenantID)
return merrors.BadRequest("image.Delete", "URL not recognised for user")
}
tenantAndName := strings.TrimPrefix(request.Url, fmt.Sprintf("%s/micro/images/", e.hostPrefix))
blobKey := fmt.Sprintf("%s/%s", pathPrefix, tenantAndName)
if err := store.DefaultBlobStore.Delete(blobKey); err != nil {
logger.Errorf("Error deleting key %s", err)
return merrors.InternalServerError("image.Delete", "Error processing delete")
}
return nil
}

View File

@@ -1,7 +1,7 @@
// Code generated by protoc-gen-go. DO NOT EDIT.
// versions:
// protoc-gen-go v1.26.0
// protoc v3.15.6
// protoc v3.15.5
// source: proto/image.proto
package image
@@ -28,7 +28,6 @@ type UploadRequest struct {
unknownFields protoimpl.UnknownFields
// Base64 encoded image to upload,
// ie. "data:image/png;base64, iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg=="
Base64 string `protobuf:"bytes,1,opt,name=base64,proto3" json:"base64,omitempty"`
// URL of the image to upload
Url string `protobuf:"bytes,2,opt,name=url,proto3" json:"url,omitempty"`
@@ -324,7 +323,6 @@ type ResizeRequest struct {
unknownFields protoimpl.UnknownFields
// base64 encoded image to resize,
// ie. "data:image/png;base64, iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg=="
Base64 string `protobuf:"bytes,1,opt,name=base64,proto3" json:"base64,omitempty"`
// url of the image to resize
Url string `protobuf:"bytes,2,opt,name=url,proto3" json:"url,omitempty"`
@@ -484,7 +482,6 @@ type ConvertRequest struct {
unknownFields protoimpl.UnknownFields
// base64 encoded image to resize,
// ie. "data:image/png;base64, iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg=="
Base64 string `protobuf:"bytes,1,opt,name=base64,proto3" json:"base64,omitempty"`
// url of the image to resize
Url string `protobuf:"bytes,2,opt,name=url,proto3" json:"url,omitempty"`
@@ -609,6 +606,93 @@ func (x *ConvertResponse) GetUrl() string {
return ""
}
// Delete an image previously uploaded.
type DeleteRequest struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
// url of the image to delete e.g. https://cdn.m3ocontent.com/micro/images/micro/41e23b39-48dd-42b6-9738-79a313414bb8/cat.jpeg
Url string `protobuf:"bytes,1,opt,name=url,proto3" json:"url,omitempty"`
}
func (x *DeleteRequest) Reset() {
*x = DeleteRequest{}
if protoimpl.UnsafeEnabled {
mi := &file_proto_image_proto_msgTypes[9]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
}
func (x *DeleteRequest) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*DeleteRequest) ProtoMessage() {}
func (x *DeleteRequest) ProtoReflect() protoreflect.Message {
mi := &file_proto_image_proto_msgTypes[9]
if protoimpl.UnsafeEnabled && x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use DeleteRequest.ProtoReflect.Descriptor instead.
func (*DeleteRequest) Descriptor() ([]byte, []int) {
return file_proto_image_proto_rawDescGZIP(), []int{9}
}
func (x *DeleteRequest) GetUrl() string {
if x != nil {
return x.Url
}
return ""
}
type DeleteResponse struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
}
func (x *DeleteResponse) Reset() {
*x = DeleteResponse{}
if protoimpl.UnsafeEnabled {
mi := &file_proto_image_proto_msgTypes[10]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
}
func (x *DeleteResponse) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*DeleteResponse) ProtoMessage() {}
func (x *DeleteResponse) ProtoReflect() protoreflect.Message {
mi := &file_proto_image_proto_msgTypes[10]
if protoimpl.UnsafeEnabled && x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use DeleteResponse.ProtoReflect.Descriptor instead.
func (*DeleteResponse) Descriptor() ([]byte, []int) {
return file_proto_image_proto_rawDescGZIP(), []int{10}
}
var File_proto_image_proto protoreflect.FileDescriptor
var file_proto_image_proto_rawDesc = []byte{
@@ -660,20 +744,27 @@ var file_proto_image_proto_rawDesc = []byte{
0x22, 0x3b, 0x0a, 0x0f, 0x43, 0x6f, 0x6e, 0x76, 0x65, 0x72, 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f,
0x6e, 0x73, 0x65, 0x12, 0x16, 0x0a, 0x06, 0x62, 0x61, 0x73, 0x65, 0x36, 0x34, 0x18, 0x01, 0x20,
0x01, 0x28, 0x09, 0x52, 0x06, 0x62, 0x61, 0x73, 0x65, 0x36, 0x34, 0x12, 0x10, 0x0a, 0x03, 0x75,
0x72, 0x6c, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x75, 0x72, 0x6c, 0x32, 0xb5, 0x01,
0x0a, 0x05, 0x49, 0x6d, 0x61, 0x67, 0x65, 0x12, 0x37, 0x0a, 0x06, 0x55, 0x70, 0x6c, 0x6f, 0x61,
0x64, 0x12, 0x14, 0x2e, 0x69, 0x6d, 0x61, 0x67, 0x65, 0x2e, 0x55, 0x70, 0x6c, 0x6f, 0x61, 0x64,
0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x15, 0x2e, 0x69, 0x6d, 0x61, 0x67, 0x65, 0x2e,
0x55, 0x70, 0x6c, 0x6f, 0x61, 0x64, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00,
0x12, 0x37, 0x0a, 0x06, 0x52, 0x65, 0x73, 0x69, 0x7a, 0x65, 0x12, 0x14, 0x2e, 0x69, 0x6d, 0x61,
0x67, 0x65, 0x2e, 0x52, 0x65, 0x73, 0x69, 0x7a, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74,
0x1a, 0x15, 0x2e, 0x69, 0x6d, 0x61, 0x67, 0x65, 0x2e, 0x52, 0x65, 0x73, 0x69, 0x7a, 0x65, 0x52,
0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x3a, 0x0a, 0x07, 0x43, 0x6f, 0x6e,
0x76, 0x65, 0x72, 0x74, 0x12, 0x15, 0x2e, 0x69, 0x6d, 0x61, 0x67, 0x65, 0x2e, 0x43, 0x6f, 0x6e,
0x76, 0x65, 0x72, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x16, 0x2e, 0x69, 0x6d,
0x61, 0x67, 0x65, 0x2e, 0x43, 0x6f, 0x6e, 0x76, 0x65, 0x72, 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f,
0x6e, 0x73, 0x65, 0x22, 0x00, 0x42, 0x0f, 0x5a, 0x0d, 0x2e, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f,
0x3b, 0x69, 0x6d, 0x61, 0x67, 0x65, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
0x72, 0x6c, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x75, 0x72, 0x6c, 0x22, 0x21, 0x0a,
0x0d, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x10,
0x0a, 0x03, 0x75, 0x72, 0x6c, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x75, 0x72, 0x6c,
0x22, 0x10, 0x0a, 0x0e, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e,
0x73, 0x65, 0x32, 0xee, 0x01, 0x0a, 0x05, 0x49, 0x6d, 0x61, 0x67, 0x65, 0x12, 0x37, 0x0a, 0x06,
0x55, 0x70, 0x6c, 0x6f, 0x61, 0x64, 0x12, 0x14, 0x2e, 0x69, 0x6d, 0x61, 0x67, 0x65, 0x2e, 0x55,
0x70, 0x6c, 0x6f, 0x61, 0x64, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x15, 0x2e, 0x69,
0x6d, 0x61, 0x67, 0x65, 0x2e, 0x55, 0x70, 0x6c, 0x6f, 0x61, 0x64, 0x52, 0x65, 0x73, 0x70, 0x6f,
0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x37, 0x0a, 0x06, 0x52, 0x65, 0x73, 0x69, 0x7a, 0x65, 0x12,
0x14, 0x2e, 0x69, 0x6d, 0x61, 0x67, 0x65, 0x2e, 0x52, 0x65, 0x73, 0x69, 0x7a, 0x65, 0x52, 0x65,
0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x15, 0x2e, 0x69, 0x6d, 0x61, 0x67, 0x65, 0x2e, 0x52, 0x65,
0x73, 0x69, 0x7a, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x3a,
0x0a, 0x07, 0x43, 0x6f, 0x6e, 0x76, 0x65, 0x72, 0x74, 0x12, 0x15, 0x2e, 0x69, 0x6d, 0x61, 0x67,
0x65, 0x2e, 0x43, 0x6f, 0x6e, 0x76, 0x65, 0x72, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74,
0x1a, 0x16, 0x2e, 0x69, 0x6d, 0x61, 0x67, 0x65, 0x2e, 0x43, 0x6f, 0x6e, 0x76, 0x65, 0x72, 0x74,
0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x37, 0x0a, 0x06, 0x44, 0x65,
0x6c, 0x65, 0x74, 0x65, 0x12, 0x14, 0x2e, 0x69, 0x6d, 0x61, 0x67, 0x65, 0x2e, 0x44, 0x65, 0x6c,
0x65, 0x74, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x15, 0x2e, 0x69, 0x6d, 0x61,
0x67, 0x65, 0x2e, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73,
0x65, 0x22, 0x00, 0x42, 0x0f, 0x5a, 0x0d, 0x2e, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x3b, 0x69,
0x6d, 0x61, 0x67, 0x65, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
}
var (
@@ -688,7 +779,7 @@ func file_proto_image_proto_rawDescGZIP() []byte {
return file_proto_image_proto_rawDescData
}
var file_proto_image_proto_msgTypes = make([]protoimpl.MessageInfo, 9)
var file_proto_image_proto_msgTypes = make([]protoimpl.MessageInfo, 11)
var file_proto_image_proto_goTypes = []interface{}{
(*UploadRequest)(nil), // 0: image.UploadRequest
(*UploadResponse)(nil), // 1: image.UploadResponse
@@ -699,6 +790,8 @@ var file_proto_image_proto_goTypes = []interface{}{
(*ResizeResponse)(nil), // 6: image.ResizeResponse
(*ConvertRequest)(nil), // 7: image.ConvertRequest
(*ConvertResponse)(nil), // 8: image.ConvertResponse
(*DeleteRequest)(nil), // 9: image.DeleteRequest
(*DeleteResponse)(nil), // 10: image.DeleteResponse
}
var file_proto_image_proto_depIdxs = []int32{
2, // 0: image.Rectangle.min:type_name -> image.Point
@@ -707,11 +800,13 @@ var file_proto_image_proto_depIdxs = []int32{
0, // 3: image.Image.Upload:input_type -> image.UploadRequest
5, // 4: image.Image.Resize:input_type -> image.ResizeRequest
7, // 5: image.Image.Convert:input_type -> image.ConvertRequest
1, // 6: image.Image.Upload:output_type -> image.UploadResponse
6, // 7: image.Image.Resize:output_type -> image.ResizeResponse
8, // 8: image.Image.Convert:output_type -> image.ConvertResponse
6, // [6:9] is the sub-list for method output_type
3, // [3:6] is the sub-list for method input_type
9, // 6: image.Image.Delete:input_type -> image.DeleteRequest
1, // 7: image.Image.Upload:output_type -> image.UploadResponse
6, // 8: image.Image.Resize:output_type -> image.ResizeResponse
8, // 9: image.Image.Convert:output_type -> image.ConvertResponse
10, // 10: image.Image.Delete:output_type -> image.DeleteResponse
7, // [7:11] is the sub-list for method output_type
3, // [3:7] is the sub-list for method input_type
3, // [3:3] is the sub-list for extension type_name
3, // [3:3] is the sub-list for extension extendee
0, // [0:3] is the sub-list for field type_name
@@ -831,6 +926,30 @@ func file_proto_image_proto_init() {
return nil
}
}
file_proto_image_proto_msgTypes[9].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*DeleteRequest); i {
case 0:
return &v.state
case 1:
return &v.sizeCache
case 2:
return &v.unknownFields
default:
return nil
}
}
file_proto_image_proto_msgTypes[10].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*DeleteResponse); i {
case 0:
return &v.state
case 1:
return &v.sizeCache
case 2:
return &v.unknownFields
default:
return nil
}
}
}
type x struct{}
out := protoimpl.TypeBuilder{
@@ -838,7 +957,7 @@ func file_proto_image_proto_init() {
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: file_proto_image_proto_rawDesc,
NumEnums: 0,
NumMessages: 9,
NumMessages: 11,
NumExtensions: 0,
NumServices: 1,
},

View File

@@ -45,6 +45,7 @@ type ImageService interface {
Upload(ctx context.Context, in *UploadRequest, opts ...client.CallOption) (*UploadResponse, error)
Resize(ctx context.Context, in *ResizeRequest, opts ...client.CallOption) (*ResizeResponse, error)
Convert(ctx context.Context, in *ConvertRequest, opts ...client.CallOption) (*ConvertResponse, error)
Delete(ctx context.Context, in *DeleteRequest, opts ...client.CallOption) (*DeleteResponse, error)
}
type imageService struct {
@@ -89,12 +90,23 @@ func (c *imageService) Convert(ctx context.Context, in *ConvertRequest, opts ...
return out, nil
}
func (c *imageService) Delete(ctx context.Context, in *DeleteRequest, opts ...client.CallOption) (*DeleteResponse, error) {
req := c.c.NewRequest(c.name, "Image.Delete", in)
out := new(DeleteResponse)
err := c.c.Call(ctx, req, out, opts...)
if err != nil {
return nil, err
}
return out, nil
}
// Server API for Image service
type ImageHandler interface {
Upload(context.Context, *UploadRequest, *UploadResponse) error
Resize(context.Context, *ResizeRequest, *ResizeResponse) error
Convert(context.Context, *ConvertRequest, *ConvertResponse) error
Delete(context.Context, *DeleteRequest, *DeleteResponse) error
}
func RegisterImageHandler(s server.Server, hdlr ImageHandler, opts ...server.HandlerOption) error {
@@ -102,6 +114,7 @@ func RegisterImageHandler(s server.Server, hdlr ImageHandler, opts ...server.Han
Upload(ctx context.Context, in *UploadRequest, out *UploadResponse) error
Resize(ctx context.Context, in *ResizeRequest, out *ResizeResponse) error
Convert(ctx context.Context, in *ConvertRequest, out *ConvertResponse) error
Delete(ctx context.Context, in *DeleteRequest, out *DeleteResponse) error
}
type Image struct {
image
@@ -125,3 +138,7 @@ func (h *imageHandler) Resize(ctx context.Context, in *ResizeRequest, out *Resiz
func (h *imageHandler) Convert(ctx context.Context, in *ConvertRequest, out *ConvertResponse) error {
return h.ImageHandler.Convert(ctx, in, out)
}
func (h *imageHandler) Delete(ctx context.Context, in *DeleteRequest, out *DeleteResponse) error {
return h.ImageHandler.Delete(ctx, in, out)
}

View File

@@ -8,6 +8,7 @@ service Image {
rpc Upload(UploadRequest) returns (UploadResponse) {}
rpc Resize(ResizeRequest) returns (ResizeResponse) {}
rpc Convert(ConvertRequest) returns (ConvertResponse) {}
rpc Delete(DeleteRequest) returns (DeleteResponse) {}
}
// Upload an image by either sending a base64 encoded image to this endpoint or a URL.
@@ -89,3 +90,12 @@ message ConvertResponse {
string base64 = 1;
string url = 2;
}
// Delete an image previously uploaded.
message DeleteRequest {
// url of the image to delete e.g. https://cdn.m3ocontent.com/micro/images/micro/41e23b39-48dd-42b6-9738-79a313414bb8/cat.jpeg
string url = 1;
}
message DeleteResponse {
}