mirror of
https://github.com/kevin-DL/services.git
synced 2026-01-11 19:04:35 +00:00
meme gen
This commit is contained in:
2
meme/.gitignore
vendored
Normal file
2
meme/.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
|
||||
meme
|
||||
3
meme/Dockerfile
Normal file
3
meme/Dockerfile
Normal file
@@ -0,0 +1,3 @@
|
||||
FROM alpine
|
||||
ADD meme /meme
|
||||
ENTRYPOINT [ "/meme" ]
|
||||
27
meme/Makefile
Normal file
27
meme/Makefile
Normal file
@@ -0,0 +1,27 @@
|
||||
|
||||
GOPATH:=$(shell go env GOPATH)
|
||||
.PHONY: init
|
||||
init:
|
||||
go install github.com/golang/protobuf/protoc-gen-go@latest
|
||||
go install github.com/micro/micro/v3/cmd/protoc-gen-micro@latest
|
||||
go install github.com/micro/micro/v3/cmd/protoc-gen-openapi@latest
|
||||
|
||||
.PHONY: api
|
||||
api:
|
||||
protoc --openapi_out=. --proto_path=. proto/meme.proto
|
||||
|
||||
.PHONY: proto
|
||||
proto:
|
||||
protoc --proto_path=. --micro_out=. --go_out=:. proto/meme.proto
|
||||
|
||||
.PHONY: build
|
||||
build:
|
||||
go build -o meme *.go
|
||||
|
||||
.PHONY: test
|
||||
test:
|
||||
go test -v ./... -cover
|
||||
|
||||
.PHONY: docker
|
||||
docker:
|
||||
docker build . -t meme:latest
|
||||
7
meme/README.md
Normal file
7
meme/README.md
Normal file
@@ -0,0 +1,7 @@
|
||||
Meme generator
|
||||
|
||||
# Meme Service
|
||||
|
||||
Generate meme. That's it.
|
||||
|
||||
Powered by [Imgflip](https://imgflip.com/api)
|
||||
42
meme/examples.json
Normal file
42
meme/examples.json
Normal file
@@ -0,0 +1,42 @@
|
||||
|
||||
{
|
||||
"templates": [{
|
||||
"title": "Meme templates",
|
||||
"description": "List of meme templates",
|
||||
"run_check": false,
|
||||
"request": {},
|
||||
"response": {
|
||||
"templates": [
|
||||
{
|
||||
"id": "181913649",
|
||||
"name": "Drake Hotline Bling",
|
||||
"url": "https://i.imgflip.com/30b1gx.jpg",
|
||||
"width": 1200,
|
||||
"height": 1200,
|
||||
"box_count": 2
|
||||
},
|
||||
{
|
||||
"id": "87743020",
|
||||
"name": "Two Buttons",
|
||||
"url": "https://i.imgflip.com/1g8my4.jpg",
|
||||
"width": 600,
|
||||
"height": 908,
|
||||
"box_count": 3
|
||||
}
|
||||
]
|
||||
}
|
||||
}],
|
||||
"generate": [{
|
||||
"title": "Generate a meme",
|
||||
"description": "Generate a meme from a template",
|
||||
"run_check": false,
|
||||
"request": {
|
||||
"id": "444501",
|
||||
"top_text": "WTF",
|
||||
"bottom_text": "Huh?"
|
||||
},
|
||||
"response": {
|
||||
"url": "https://i.imgflip.com/65ymjs.jpg"
|
||||
}
|
||||
}]
|
||||
}
|
||||
3
meme/generate.go
Normal file
3
meme/generate.go
Normal file
@@ -0,0 +1,3 @@
|
||||
package main
|
||||
|
||||
//go:generate make proto
|
||||
92
meme/handler/meme.go
Normal file
92
meme/handler/meme.go
Normal file
@@ -0,0 +1,92 @@
|
||||
package handler
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"net/url"
|
||||
|
||||
"github.com/micro/micro/v3/service/config"
|
||||
"github.com/micro/micro/v3/service/errors"
|
||||
"github.com/micro/micro/v3/service/logger"
|
||||
pb "github.com/micro/services/meme/proto"
|
||||
"github.com/micro/services/pkg/api"
|
||||
)
|
||||
|
||||
type Meme struct {
|
||||
username string
|
||||
password string
|
||||
}
|
||||
|
||||
func New() *Meme {
|
||||
v, err := config.Get("imgflip.username")
|
||||
if err != nil {
|
||||
logger.Fatalf("imgflip.username config not found: %v", err)
|
||||
}
|
||||
username := v.String("")
|
||||
if len(username) == 0 {
|
||||
logger.Fatal("imgflip.username config not found")
|
||||
}
|
||||
v, err = config.Get("imgflip.password")
|
||||
if err != nil {
|
||||
logger.Fatalf("imgflip.password config not found: %v", err)
|
||||
}
|
||||
password := v.String("")
|
||||
if len(password) == 0 {
|
||||
logger.Fatal("imgflip.password config not found")
|
||||
}
|
||||
return &Meme{
|
||||
username: username,
|
||||
password: password,
|
||||
}
|
||||
}
|
||||
|
||||
type TemplateRequest struct {
|
||||
Success bool `json:"success"`
|
||||
Data Data `json":data"`
|
||||
}
|
||||
|
||||
type Data struct {
|
||||
Memes []*pb.Template `json:"memes"`
|
||||
}
|
||||
|
||||
func (m *Meme) Templates(ctx context.Context, req *pb.TemplatesRequest, rsp *pb.TemplatesResponse) error {
|
||||
templateRsp := new(TemplateRequest)
|
||||
if err := api.Get("https://api.imgflip.com/get_memes", templateRsp); err != nil {
|
||||
return errors.InternalServerError("meme.templates", err.Error())
|
||||
}
|
||||
rsp.Templates = templateRsp.Data.Memes
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *Meme) Generate(ctx context.Context, req *pb.GenerateRequest, rsp *pb.GenerateResponse) error {
|
||||
vals := url.Values{}
|
||||
vals.Set("template_id", req.Id)
|
||||
vals.Set("text0", req.TopText)
|
||||
vals.Set("text1", req.BottomText)
|
||||
vals.Set("font", req.Font)
|
||||
vals.Set("max_font_size", req.MaxFontSize)
|
||||
vals.Set("username", m.username)
|
||||
vals.Set("password", m.password)
|
||||
|
||||
genRsp := map[string]interface{}{}
|
||||
|
||||
resp, err := http.PostForm("https://api.imgflip.com/caption_image", vals)
|
||||
if err != nil {
|
||||
return errors.InternalServerError("meme.generate", err.Error())
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
b, _ := ioutil.ReadAll(resp.Body)
|
||||
json.Unmarshal(b, &genRsp)
|
||||
|
||||
success := genRsp["success"].(bool)
|
||||
if !success {
|
||||
return errors.BadRequest("meme.generate", genRsp["error_message"].(string))
|
||||
}
|
||||
|
||||
// set response url
|
||||
rsp.Url = genRsp["data"].(map[string]interface{})["url"].(string)
|
||||
return nil
|
||||
}
|
||||
24
meme/main.go
Normal file
24
meme/main.go
Normal file
@@ -0,0 +1,24 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/micro/micro/v3/service"
|
||||
"github.com/micro/micro/v3/service/logger"
|
||||
"github.com/micro/services/meme/handler"
|
||||
pb "github.com/micro/services/meme/proto"
|
||||
)
|
||||
|
||||
func main() {
|
||||
// Create service
|
||||
srv := service.New(
|
||||
service.Name("meme"),
|
||||
service.Version("latest"),
|
||||
)
|
||||
|
||||
// Register handler
|
||||
pb.RegisterMemeHandler(srv.Server(), handler.New())
|
||||
|
||||
// Run service
|
||||
if err := srv.Run(); err != nil {
|
||||
logger.Fatal(err)
|
||||
}
|
||||
}
|
||||
1
meme/micro.mu
Normal file
1
meme/micro.mu
Normal file
@@ -0,0 +1 @@
|
||||
service meme
|
||||
619
meme/proto/meme.pb.go
Normal file
619
meme/proto/meme.pb.go
Normal file
@@ -0,0 +1,619 @@
|
||||
// Code generated by protoc-gen-go. DO NOT EDIT.
|
||||
// versions:
|
||||
// protoc-gen-go v1.27.1
|
||||
// protoc v3.15.6
|
||||
// source: proto/meme.proto
|
||||
|
||||
package meme
|
||||
|
||||
import (
|
||||
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
|
||||
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
|
||||
reflect "reflect"
|
||||
sync "sync"
|
||||
)
|
||||
|
||||
const (
|
||||
// Verify that this generated code is sufficiently up-to-date.
|
||||
_ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion)
|
||||
// Verify that runtime/protoimpl is sufficiently up-to-date.
|
||||
_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20)
|
||||
)
|
||||
|
||||
type Template struct {
|
||||
state protoimpl.MessageState
|
||||
sizeCache protoimpl.SizeCache
|
||||
unknownFields protoimpl.UnknownFields
|
||||
|
||||
// id of the meme
|
||||
Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"`
|
||||
// name of the meme
|
||||
Name string `protobuf:"bytes,2,opt,name=name,proto3" json:"name,omitempty"`
|
||||
// url of the meme
|
||||
Url string `protobuf:"bytes,3,opt,name=url,proto3" json:"url,omitempty"`
|
||||
// width in pixels
|
||||
Width int32 `protobuf:"varint,4,opt,name=width,proto3" json:"width,omitempty"`
|
||||
// height in pixels
|
||||
Height int32 `protobuf:"varint,5,opt,name=height,proto3" json:"height,omitempty"`
|
||||
// number of boxes used
|
||||
BoxCount int32 `protobuf:"varint,6,opt,name=box_count,json=boxCount,proto3" json:"box_count,omitempty"`
|
||||
}
|
||||
|
||||
func (x *Template) Reset() {
|
||||
*x = Template{}
|
||||
if protoimpl.UnsafeEnabled {
|
||||
mi := &file_proto_meme_proto_msgTypes[0]
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
}
|
||||
|
||||
func (x *Template) String() string {
|
||||
return protoimpl.X.MessageStringOf(x)
|
||||
}
|
||||
|
||||
func (*Template) ProtoMessage() {}
|
||||
|
||||
func (x *Template) ProtoReflect() protoreflect.Message {
|
||||
mi := &file_proto_meme_proto_msgTypes[0]
|
||||
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 Template.ProtoReflect.Descriptor instead.
|
||||
func (*Template) Descriptor() ([]byte, []int) {
|
||||
return file_proto_meme_proto_rawDescGZIP(), []int{0}
|
||||
}
|
||||
|
||||
func (x *Template) GetId() string {
|
||||
if x != nil {
|
||||
return x.Id
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (x *Template) GetName() string {
|
||||
if x != nil {
|
||||
return x.Name
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (x *Template) GetUrl() string {
|
||||
if x != nil {
|
||||
return x.Url
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (x *Template) GetWidth() int32 {
|
||||
if x != nil {
|
||||
return x.Width
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func (x *Template) GetHeight() int32 {
|
||||
if x != nil {
|
||||
return x.Height
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func (x *Template) GetBoxCount() int32 {
|
||||
if x != nil {
|
||||
return x.BoxCount
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
type Box struct {
|
||||
state protoimpl.MessageState
|
||||
sizeCache protoimpl.SizeCache
|
||||
unknownFields protoimpl.UnknownFields
|
||||
|
||||
// text to display
|
||||
Text string `protobuf:"bytes,1,opt,name=text,proto3" json:"text,omitempty"`
|
||||
// x axis position
|
||||
X int32 `protobuf:"varint,2,opt,name=x,proto3" json:"x,omitempty"`
|
||||
// y axis position
|
||||
Y int32 `protobuf:"varint,3,opt,name=y,proto3" json:"y,omitempty"`
|
||||
// width in pixels
|
||||
Width int32 `protobuf:"varint,4,opt,name=width,proto3" json:"width,omitempty"`
|
||||
// height in pixels
|
||||
Height int32 `protobuf:"varint,5,opt,name=height,proto3" json:"height,omitempty"`
|
||||
// colour hex code
|
||||
Color string `protobuf:"bytes,6,opt,name=color,proto3" json:"color,omitempty"`
|
||||
// outline color hex code
|
||||
Outline string `protobuf:"bytes,7,opt,name=outline,proto3" json:"outline,omitempty"`
|
||||
}
|
||||
|
||||
func (x *Box) Reset() {
|
||||
*x = Box{}
|
||||
if protoimpl.UnsafeEnabled {
|
||||
mi := &file_proto_meme_proto_msgTypes[1]
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
}
|
||||
|
||||
func (x *Box) String() string {
|
||||
return protoimpl.X.MessageStringOf(x)
|
||||
}
|
||||
|
||||
func (*Box) ProtoMessage() {}
|
||||
|
||||
func (x *Box) ProtoReflect() protoreflect.Message {
|
||||
mi := &file_proto_meme_proto_msgTypes[1]
|
||||
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 Box.ProtoReflect.Descriptor instead.
|
||||
func (*Box) Descriptor() ([]byte, []int) {
|
||||
return file_proto_meme_proto_rawDescGZIP(), []int{1}
|
||||
}
|
||||
|
||||
func (x *Box) GetText() string {
|
||||
if x != nil {
|
||||
return x.Text
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (x *Box) GetX() int32 {
|
||||
if x != nil {
|
||||
return x.X
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func (x *Box) GetY() int32 {
|
||||
if x != nil {
|
||||
return x.Y
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func (x *Box) GetWidth() int32 {
|
||||
if x != nil {
|
||||
return x.Width
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func (x *Box) GetHeight() int32 {
|
||||
if x != nil {
|
||||
return x.Height
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func (x *Box) GetColor() string {
|
||||
if x != nil {
|
||||
return x.Color
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (x *Box) GetOutline() string {
|
||||
if x != nil {
|
||||
return x.Outline
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
// List the available templates
|
||||
type TemplatesRequest struct {
|
||||
state protoimpl.MessageState
|
||||
sizeCache protoimpl.SizeCache
|
||||
unknownFields protoimpl.UnknownFields
|
||||
}
|
||||
|
||||
func (x *TemplatesRequest) Reset() {
|
||||
*x = TemplatesRequest{}
|
||||
if protoimpl.UnsafeEnabled {
|
||||
mi := &file_proto_meme_proto_msgTypes[2]
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
}
|
||||
|
||||
func (x *TemplatesRequest) String() string {
|
||||
return protoimpl.X.MessageStringOf(x)
|
||||
}
|
||||
|
||||
func (*TemplatesRequest) ProtoMessage() {}
|
||||
|
||||
func (x *TemplatesRequest) ProtoReflect() protoreflect.Message {
|
||||
mi := &file_proto_meme_proto_msgTypes[2]
|
||||
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 TemplatesRequest.ProtoReflect.Descriptor instead.
|
||||
func (*TemplatesRequest) Descriptor() ([]byte, []int) {
|
||||
return file_proto_meme_proto_rawDescGZIP(), []int{2}
|
||||
}
|
||||
|
||||
type TemplatesResponse struct {
|
||||
state protoimpl.MessageState
|
||||
sizeCache protoimpl.SizeCache
|
||||
unknownFields protoimpl.UnknownFields
|
||||
|
||||
Templates []*Template `protobuf:"bytes,1,rep,name=templates,proto3" json:"templates,omitempty"`
|
||||
}
|
||||
|
||||
func (x *TemplatesResponse) Reset() {
|
||||
*x = TemplatesResponse{}
|
||||
if protoimpl.UnsafeEnabled {
|
||||
mi := &file_proto_meme_proto_msgTypes[3]
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
}
|
||||
|
||||
func (x *TemplatesResponse) String() string {
|
||||
return protoimpl.X.MessageStringOf(x)
|
||||
}
|
||||
|
||||
func (*TemplatesResponse) ProtoMessage() {}
|
||||
|
||||
func (x *TemplatesResponse) ProtoReflect() protoreflect.Message {
|
||||
mi := &file_proto_meme_proto_msgTypes[3]
|
||||
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 TemplatesResponse.ProtoReflect.Descriptor instead.
|
||||
func (*TemplatesResponse) Descriptor() ([]byte, []int) {
|
||||
return file_proto_meme_proto_rawDescGZIP(), []int{3}
|
||||
}
|
||||
|
||||
func (x *TemplatesResponse) GetTemplates() []*Template {
|
||||
if x != nil {
|
||||
return x.Templates
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
type GenerateRequest struct {
|
||||
state protoimpl.MessageState
|
||||
sizeCache protoimpl.SizeCache
|
||||
unknownFields protoimpl.UnknownFields
|
||||
|
||||
// the template id to use
|
||||
Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"`
|
||||
// top text
|
||||
TopText string `protobuf:"bytes,2,opt,name=top_text,json=topText,proto3" json:"top_text,omitempty"`
|
||||
// bottom text
|
||||
BottomText string `protobuf:"bytes,3,opt,name=bottom_text,json=bottomText,proto3" json:"bottom_text,omitempty"`
|
||||
// font: arial or impact
|
||||
Font string `protobuf:"bytes,4,opt,name=font,proto3" json:"font,omitempty"`
|
||||
// font size; defaults to 50px
|
||||
MaxFontSize string `protobuf:"bytes,5,opt,name=max_font_size,json=maxFontSize,proto3" json:"max_font_size,omitempty"`
|
||||
}
|
||||
|
||||
func (x *GenerateRequest) Reset() {
|
||||
*x = GenerateRequest{}
|
||||
if protoimpl.UnsafeEnabled {
|
||||
mi := &file_proto_meme_proto_msgTypes[4]
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
}
|
||||
|
||||
func (x *GenerateRequest) String() string {
|
||||
return protoimpl.X.MessageStringOf(x)
|
||||
}
|
||||
|
||||
func (*GenerateRequest) ProtoMessage() {}
|
||||
|
||||
func (x *GenerateRequest) ProtoReflect() protoreflect.Message {
|
||||
mi := &file_proto_meme_proto_msgTypes[4]
|
||||
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 GenerateRequest.ProtoReflect.Descriptor instead.
|
||||
func (*GenerateRequest) Descriptor() ([]byte, []int) {
|
||||
return file_proto_meme_proto_rawDescGZIP(), []int{4}
|
||||
}
|
||||
|
||||
func (x *GenerateRequest) GetId() string {
|
||||
if x != nil {
|
||||
return x.Id
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (x *GenerateRequest) GetTopText() string {
|
||||
if x != nil {
|
||||
return x.TopText
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (x *GenerateRequest) GetBottomText() string {
|
||||
if x != nil {
|
||||
return x.BottomText
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (x *GenerateRequest) GetFont() string {
|
||||
if x != nil {
|
||||
return x.Font
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (x *GenerateRequest) GetMaxFontSize() string {
|
||||
if x != nil {
|
||||
return x.MaxFontSize
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
type GenerateResponse struct {
|
||||
state protoimpl.MessageState
|
||||
sizeCache protoimpl.SizeCache
|
||||
unknownFields protoimpl.UnknownFields
|
||||
|
||||
// url of the meme
|
||||
Url string `protobuf:"bytes,1,opt,name=url,proto3" json:"url,omitempty"`
|
||||
}
|
||||
|
||||
func (x *GenerateResponse) Reset() {
|
||||
*x = GenerateResponse{}
|
||||
if protoimpl.UnsafeEnabled {
|
||||
mi := &file_proto_meme_proto_msgTypes[5]
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
}
|
||||
|
||||
func (x *GenerateResponse) String() string {
|
||||
return protoimpl.X.MessageStringOf(x)
|
||||
}
|
||||
|
||||
func (*GenerateResponse) ProtoMessage() {}
|
||||
|
||||
func (x *GenerateResponse) ProtoReflect() protoreflect.Message {
|
||||
mi := &file_proto_meme_proto_msgTypes[5]
|
||||
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 GenerateResponse.ProtoReflect.Descriptor instead.
|
||||
func (*GenerateResponse) Descriptor() ([]byte, []int) {
|
||||
return file_proto_meme_proto_rawDescGZIP(), []int{5}
|
||||
}
|
||||
|
||||
func (x *GenerateResponse) GetUrl() string {
|
||||
if x != nil {
|
||||
return x.Url
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
var File_proto_meme_proto protoreflect.FileDescriptor
|
||||
|
||||
var file_proto_meme_proto_rawDesc = []byte{
|
||||
0x0a, 0x10, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x6d, 0x65, 0x6d, 0x65, 0x2e, 0x70, 0x72, 0x6f,
|
||||
0x74, 0x6f, 0x12, 0x04, 0x6d, 0x65, 0x6d, 0x65, 0x22, 0x8b, 0x01, 0x0a, 0x08, 0x54, 0x65, 0x6d,
|
||||
0x70, 0x6c, 0x61, 0x74, 0x65, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28,
|
||||
0x09, 0x52, 0x02, 0x69, 0x64, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x02, 0x20,
|
||||
0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x10, 0x0a, 0x03, 0x75, 0x72, 0x6c,
|
||||
0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x75, 0x72, 0x6c, 0x12, 0x14, 0x0a, 0x05, 0x77,
|
||||
0x69, 0x64, 0x74, 0x68, 0x18, 0x04, 0x20, 0x01, 0x28, 0x05, 0x52, 0x05, 0x77, 0x69, 0x64, 0x74,
|
||||
0x68, 0x12, 0x16, 0x0a, 0x06, 0x68, 0x65, 0x69, 0x67, 0x68, 0x74, 0x18, 0x05, 0x20, 0x01, 0x28,
|
||||
0x05, 0x52, 0x06, 0x68, 0x65, 0x69, 0x67, 0x68, 0x74, 0x12, 0x1b, 0x0a, 0x09, 0x62, 0x6f, 0x78,
|
||||
0x5f, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x18, 0x06, 0x20, 0x01, 0x28, 0x05, 0x52, 0x08, 0x62, 0x6f,
|
||||
0x78, 0x43, 0x6f, 0x75, 0x6e, 0x74, 0x22, 0x93, 0x01, 0x0a, 0x03, 0x42, 0x6f, 0x78, 0x12, 0x12,
|
||||
0x0a, 0x04, 0x74, 0x65, 0x78, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x74, 0x65,
|
||||
0x78, 0x74, 0x12, 0x0c, 0x0a, 0x01, 0x78, 0x18, 0x02, 0x20, 0x01, 0x28, 0x05, 0x52, 0x01, 0x78,
|
||||
0x12, 0x0c, 0x0a, 0x01, 0x79, 0x18, 0x03, 0x20, 0x01, 0x28, 0x05, 0x52, 0x01, 0x79, 0x12, 0x14,
|
||||
0x0a, 0x05, 0x77, 0x69, 0x64, 0x74, 0x68, 0x18, 0x04, 0x20, 0x01, 0x28, 0x05, 0x52, 0x05, 0x77,
|
||||
0x69, 0x64, 0x74, 0x68, 0x12, 0x16, 0x0a, 0x06, 0x68, 0x65, 0x69, 0x67, 0x68, 0x74, 0x18, 0x05,
|
||||
0x20, 0x01, 0x28, 0x05, 0x52, 0x06, 0x68, 0x65, 0x69, 0x67, 0x68, 0x74, 0x12, 0x14, 0x0a, 0x05,
|
||||
0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x18, 0x06, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x63, 0x6f, 0x6c,
|
||||
0x6f, 0x72, 0x12, 0x18, 0x0a, 0x07, 0x6f, 0x75, 0x74, 0x6c, 0x69, 0x6e, 0x65, 0x18, 0x07, 0x20,
|
||||
0x01, 0x28, 0x09, 0x52, 0x07, 0x6f, 0x75, 0x74, 0x6c, 0x69, 0x6e, 0x65, 0x22, 0x12, 0x0a, 0x10,
|
||||
0x54, 0x65, 0x6d, 0x70, 0x6c, 0x61, 0x74, 0x65, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74,
|
||||
0x22, 0x41, 0x0a, 0x11, 0x54, 0x65, 0x6d, 0x70, 0x6c, 0x61, 0x74, 0x65, 0x73, 0x52, 0x65, 0x73,
|
||||
0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x2c, 0x0a, 0x09, 0x74, 0x65, 0x6d, 0x70, 0x6c, 0x61, 0x74,
|
||||
0x65, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x0e, 0x2e, 0x6d, 0x65, 0x6d, 0x65, 0x2e,
|
||||
0x54, 0x65, 0x6d, 0x70, 0x6c, 0x61, 0x74, 0x65, 0x52, 0x09, 0x74, 0x65, 0x6d, 0x70, 0x6c, 0x61,
|
||||
0x74, 0x65, 0x73, 0x22, 0x95, 0x01, 0x0a, 0x0f, 0x47, 0x65, 0x6e, 0x65, 0x72, 0x61, 0x74, 0x65,
|
||||
0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20,
|
||||
0x01, 0x28, 0x09, 0x52, 0x02, 0x69, 0x64, 0x12, 0x19, 0x0a, 0x08, 0x74, 0x6f, 0x70, 0x5f, 0x74,
|
||||
0x65, 0x78, 0x74, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x74, 0x6f, 0x70, 0x54, 0x65,
|
||||
0x78, 0x74, 0x12, 0x1f, 0x0a, 0x0b, 0x62, 0x6f, 0x74, 0x74, 0x6f, 0x6d, 0x5f, 0x74, 0x65, 0x78,
|
||||
0x74, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, 0x62, 0x6f, 0x74, 0x74, 0x6f, 0x6d, 0x54,
|
||||
0x65, 0x78, 0x74, 0x12, 0x12, 0x0a, 0x04, 0x66, 0x6f, 0x6e, 0x74, 0x18, 0x04, 0x20, 0x01, 0x28,
|
||||
0x09, 0x52, 0x04, 0x66, 0x6f, 0x6e, 0x74, 0x12, 0x22, 0x0a, 0x0d, 0x6d, 0x61, 0x78, 0x5f, 0x66,
|
||||
0x6f, 0x6e, 0x74, 0x5f, 0x73, 0x69, 0x7a, 0x65, 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b,
|
||||
0x6d, 0x61, 0x78, 0x46, 0x6f, 0x6e, 0x74, 0x53, 0x69, 0x7a, 0x65, 0x22, 0x24, 0x0a, 0x10, 0x47,
|
||||
0x65, 0x6e, 0x65, 0x72, 0x61, 0x74, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12,
|
||||
0x10, 0x0a, 0x03, 0x75, 0x72, 0x6c, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x75, 0x72,
|
||||
0x6c, 0x32, 0x83, 0x01, 0x0a, 0x04, 0x4d, 0x65, 0x6d, 0x65, 0x12, 0x3e, 0x0a, 0x09, 0x54, 0x65,
|
||||
0x6d, 0x70, 0x6c, 0x61, 0x74, 0x65, 0x73, 0x12, 0x16, 0x2e, 0x6d, 0x65, 0x6d, 0x65, 0x2e, 0x54,
|
||||
0x65, 0x6d, 0x70, 0x6c, 0x61, 0x74, 0x65, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a,
|
||||
0x17, 0x2e, 0x6d, 0x65, 0x6d, 0x65, 0x2e, 0x54, 0x65, 0x6d, 0x70, 0x6c, 0x61, 0x74, 0x65, 0x73,
|
||||
0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x3b, 0x0a, 0x08, 0x47, 0x65,
|
||||
0x6e, 0x65, 0x72, 0x61, 0x74, 0x65, 0x12, 0x15, 0x2e, 0x6d, 0x65, 0x6d, 0x65, 0x2e, 0x47, 0x65,
|
||||
0x6e, 0x65, 0x72, 0x61, 0x74, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x16, 0x2e,
|
||||
0x6d, 0x65, 0x6d, 0x65, 0x2e, 0x47, 0x65, 0x6e, 0x65, 0x72, 0x61, 0x74, 0x65, 0x52, 0x65, 0x73,
|
||||
0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x42, 0x0e, 0x5a, 0x0c, 0x2e, 0x2f, 0x70, 0x72, 0x6f,
|
||||
0x74, 0x6f, 0x3b, 0x6d, 0x65, 0x6d, 0x65, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
|
||||
}
|
||||
|
||||
var (
|
||||
file_proto_meme_proto_rawDescOnce sync.Once
|
||||
file_proto_meme_proto_rawDescData = file_proto_meme_proto_rawDesc
|
||||
)
|
||||
|
||||
func file_proto_meme_proto_rawDescGZIP() []byte {
|
||||
file_proto_meme_proto_rawDescOnce.Do(func() {
|
||||
file_proto_meme_proto_rawDescData = protoimpl.X.CompressGZIP(file_proto_meme_proto_rawDescData)
|
||||
})
|
||||
return file_proto_meme_proto_rawDescData
|
||||
}
|
||||
|
||||
var file_proto_meme_proto_msgTypes = make([]protoimpl.MessageInfo, 6)
|
||||
var file_proto_meme_proto_goTypes = []interface{}{
|
||||
(*Template)(nil), // 0: meme.Template
|
||||
(*Box)(nil), // 1: meme.Box
|
||||
(*TemplatesRequest)(nil), // 2: meme.TemplatesRequest
|
||||
(*TemplatesResponse)(nil), // 3: meme.TemplatesResponse
|
||||
(*GenerateRequest)(nil), // 4: meme.GenerateRequest
|
||||
(*GenerateResponse)(nil), // 5: meme.GenerateResponse
|
||||
}
|
||||
var file_proto_meme_proto_depIdxs = []int32{
|
||||
0, // 0: meme.TemplatesResponse.templates:type_name -> meme.Template
|
||||
2, // 1: meme.Meme.Templates:input_type -> meme.TemplatesRequest
|
||||
4, // 2: meme.Meme.Generate:input_type -> meme.GenerateRequest
|
||||
3, // 3: meme.Meme.Templates:output_type -> meme.TemplatesResponse
|
||||
5, // 4: meme.Meme.Generate:output_type -> meme.GenerateResponse
|
||||
3, // [3:5] is the sub-list for method output_type
|
||||
1, // [1:3] is the sub-list for method input_type
|
||||
1, // [1:1] is the sub-list for extension type_name
|
||||
1, // [1:1] is the sub-list for extension extendee
|
||||
0, // [0:1] is the sub-list for field type_name
|
||||
}
|
||||
|
||||
func init() { file_proto_meme_proto_init() }
|
||||
func file_proto_meme_proto_init() {
|
||||
if File_proto_meme_proto != nil {
|
||||
return
|
||||
}
|
||||
if !protoimpl.UnsafeEnabled {
|
||||
file_proto_meme_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} {
|
||||
switch v := v.(*Template); i {
|
||||
case 0:
|
||||
return &v.state
|
||||
case 1:
|
||||
return &v.sizeCache
|
||||
case 2:
|
||||
return &v.unknownFields
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
file_proto_meme_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} {
|
||||
switch v := v.(*Box); i {
|
||||
case 0:
|
||||
return &v.state
|
||||
case 1:
|
||||
return &v.sizeCache
|
||||
case 2:
|
||||
return &v.unknownFields
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
file_proto_meme_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} {
|
||||
switch v := v.(*TemplatesRequest); i {
|
||||
case 0:
|
||||
return &v.state
|
||||
case 1:
|
||||
return &v.sizeCache
|
||||
case 2:
|
||||
return &v.unknownFields
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
file_proto_meme_proto_msgTypes[3].Exporter = func(v interface{}, i int) interface{} {
|
||||
switch v := v.(*TemplatesResponse); i {
|
||||
case 0:
|
||||
return &v.state
|
||||
case 1:
|
||||
return &v.sizeCache
|
||||
case 2:
|
||||
return &v.unknownFields
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
file_proto_meme_proto_msgTypes[4].Exporter = func(v interface{}, i int) interface{} {
|
||||
switch v := v.(*GenerateRequest); i {
|
||||
case 0:
|
||||
return &v.state
|
||||
case 1:
|
||||
return &v.sizeCache
|
||||
case 2:
|
||||
return &v.unknownFields
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
file_proto_meme_proto_msgTypes[5].Exporter = func(v interface{}, i int) interface{} {
|
||||
switch v := v.(*GenerateResponse); 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{
|
||||
File: protoimpl.DescBuilder{
|
||||
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
|
||||
RawDescriptor: file_proto_meme_proto_rawDesc,
|
||||
NumEnums: 0,
|
||||
NumMessages: 6,
|
||||
NumExtensions: 0,
|
||||
NumServices: 1,
|
||||
},
|
||||
GoTypes: file_proto_meme_proto_goTypes,
|
||||
DependencyIndexes: file_proto_meme_proto_depIdxs,
|
||||
MessageInfos: file_proto_meme_proto_msgTypes,
|
||||
}.Build()
|
||||
File_proto_meme_proto = out.File
|
||||
file_proto_meme_proto_rawDesc = nil
|
||||
file_proto_meme_proto_goTypes = nil
|
||||
file_proto_meme_proto_depIdxs = nil
|
||||
}
|
||||
110
meme/proto/meme.pb.micro.go
Normal file
110
meme/proto/meme.pb.micro.go
Normal file
@@ -0,0 +1,110 @@
|
||||
// Code generated by protoc-gen-micro. DO NOT EDIT.
|
||||
// source: proto/meme.proto
|
||||
|
||||
package meme
|
||||
|
||||
import (
|
||||
fmt "fmt"
|
||||
proto "github.com/golang/protobuf/proto"
|
||||
math "math"
|
||||
)
|
||||
|
||||
import (
|
||||
context "context"
|
||||
api "github.com/micro/micro/v3/service/api"
|
||||
client "github.com/micro/micro/v3/service/client"
|
||||
server "github.com/micro/micro/v3/service/server"
|
||||
)
|
||||
|
||||
// Reference imports to suppress errors if they are not otherwise used.
|
||||
var _ = proto.Marshal
|
||||
var _ = fmt.Errorf
|
||||
var _ = math.Inf
|
||||
|
||||
// This is a compile-time assertion to ensure that this generated file
|
||||
// is compatible with the proto package it is being compiled against.
|
||||
// A compilation error at this line likely means your copy of the
|
||||
// proto package needs to be updated.
|
||||
const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package
|
||||
|
||||
// Reference imports to suppress errors if they are not otherwise used.
|
||||
var _ api.Endpoint
|
||||
var _ context.Context
|
||||
var _ client.Option
|
||||
var _ server.Option
|
||||
|
||||
// Api Endpoints for Meme service
|
||||
|
||||
func NewMemeEndpoints() []*api.Endpoint {
|
||||
return []*api.Endpoint{}
|
||||
}
|
||||
|
||||
// Client API for Meme service
|
||||
|
||||
type MemeService interface {
|
||||
Templates(ctx context.Context, in *TemplatesRequest, opts ...client.CallOption) (*TemplatesResponse, error)
|
||||
Generate(ctx context.Context, in *GenerateRequest, opts ...client.CallOption) (*GenerateResponse, error)
|
||||
}
|
||||
|
||||
type memeService struct {
|
||||
c client.Client
|
||||
name string
|
||||
}
|
||||
|
||||
func NewMemeService(name string, c client.Client) MemeService {
|
||||
return &memeService{
|
||||
c: c,
|
||||
name: name,
|
||||
}
|
||||
}
|
||||
|
||||
func (c *memeService) Templates(ctx context.Context, in *TemplatesRequest, opts ...client.CallOption) (*TemplatesResponse, error) {
|
||||
req := c.c.NewRequest(c.name, "Meme.Templates", in)
|
||||
out := new(TemplatesResponse)
|
||||
err := c.c.Call(ctx, req, out, opts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (c *memeService) Generate(ctx context.Context, in *GenerateRequest, opts ...client.CallOption) (*GenerateResponse, error) {
|
||||
req := c.c.NewRequest(c.name, "Meme.Generate", in)
|
||||
out := new(GenerateResponse)
|
||||
err := c.c.Call(ctx, req, out, opts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
// Server API for Meme service
|
||||
|
||||
type MemeHandler interface {
|
||||
Templates(context.Context, *TemplatesRequest, *TemplatesResponse) error
|
||||
Generate(context.Context, *GenerateRequest, *GenerateResponse) error
|
||||
}
|
||||
|
||||
func RegisterMemeHandler(s server.Server, hdlr MemeHandler, opts ...server.HandlerOption) error {
|
||||
type meme interface {
|
||||
Templates(ctx context.Context, in *TemplatesRequest, out *TemplatesResponse) error
|
||||
Generate(ctx context.Context, in *GenerateRequest, out *GenerateResponse) error
|
||||
}
|
||||
type Meme struct {
|
||||
meme
|
||||
}
|
||||
h := &memeHandler{hdlr}
|
||||
return s.Handle(s.NewHandler(&Meme{h}, opts...))
|
||||
}
|
||||
|
||||
type memeHandler struct {
|
||||
MemeHandler
|
||||
}
|
||||
|
||||
func (h *memeHandler) Templates(ctx context.Context, in *TemplatesRequest, out *TemplatesResponse) error {
|
||||
return h.MemeHandler.Templates(ctx, in, out)
|
||||
}
|
||||
|
||||
func (h *memeHandler) Generate(ctx context.Context, in *GenerateRequest, out *GenerateResponse) error {
|
||||
return h.MemeHandler.Generate(ctx, in, out)
|
||||
}
|
||||
68
meme/proto/meme.proto
Normal file
68
meme/proto/meme.proto
Normal file
@@ -0,0 +1,68 @@
|
||||
syntax = "proto3";
|
||||
|
||||
package meme;
|
||||
|
||||
option go_package = "./proto;meme";
|
||||
|
||||
service Meme {
|
||||
rpc Templates(TemplatesRequest) returns (TemplatesResponse) {}
|
||||
rpc Generate(GenerateRequest) returns (GenerateResponse) {}
|
||||
}
|
||||
|
||||
message Template {
|
||||
// id of the meme
|
||||
string id = 1;
|
||||
// name of the meme
|
||||
string name = 2;
|
||||
// url of the meme
|
||||
string url = 3;
|
||||
// width in pixels
|
||||
int32 width = 4;
|
||||
// height in pixels
|
||||
int32 height = 5;
|
||||
// number of boxes used
|
||||
int32 box_count = 6;
|
||||
}
|
||||
|
||||
message Box {
|
||||
// text to display
|
||||
string text = 1;
|
||||
// x axis position
|
||||
int32 x = 2;
|
||||
// y axis position
|
||||
int32 y = 3;
|
||||
// width in pixels
|
||||
int32 width = 4;
|
||||
// height in pixels
|
||||
int32 height = 5;
|
||||
// colour hex code
|
||||
string color = 6;
|
||||
// outline color hex code
|
||||
string outline = 7;
|
||||
}
|
||||
|
||||
// List the available templates
|
||||
message TemplatesRequest {}
|
||||
|
||||
message TemplatesResponse {
|
||||
repeated Template templates = 1;
|
||||
}
|
||||
|
||||
message GenerateRequest {
|
||||
// the template id to use
|
||||
string id = 1;
|
||||
// top text
|
||||
string top_text = 2;
|
||||
// bottom text
|
||||
string bottom_text = 3;
|
||||
// font: arial or impact
|
||||
string font = 4;
|
||||
// font size; defaults to 50px
|
||||
string max_font_size = 5;
|
||||
}
|
||||
|
||||
message GenerateResponse {
|
||||
// url of the meme
|
||||
string url = 1;
|
||||
}
|
||||
|
||||
6
meme/publicapi.json
Normal file
6
meme/publicapi.json
Normal file
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"name": "meme",
|
||||
"icon": "🤦",
|
||||
"category": "social",
|
||||
"display_name": "Meme Generator"
|
||||
}
|
||||
Reference in New Issue
Block a user