From 3c38d968813a8c53f80fc7c9338f13820a5e2f07 Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Wed, 29 Sep 2021 14:02:28 +0100 Subject: [PATCH] add notes (#218) * add notes * fix build * Commit from GitHub Actions (Publish APIs & Clients) Co-authored-by: asim --- clients/go/m3o.go | 3 + clients/go/notes/notes.go | 125 +++ clients/ts/index.ts | 3 + clients/ts/notes/index.ts | 120 +++ clients/ts/package.json | 3 +- examples/notes/create/curl/createANote.sh | 7 + examples/notes/create/go/createANote.go | 17 + examples/notes/create/node/createANote.js | 13 + examples/notes/delete/curl/deleteANote.sh | 6 + examples/notes/delete/go/deleteANote.go | 16 + examples/notes/delete/node/deleteANote.js | 12 + examples/notes/list/curl/listAllNotes.sh | 4 + examples/notes/list/go/listAllNotes.go | 14 + examples/notes/list/node/listAllNotes.js | 10 + examples/notes/read/curl/readANote.sh | 6 + examples/notes/read/go/readANote.go | 16 + examples/notes/read/node/readANote.js | 12 + examples/notes/update/curl/updateANote.sh | 10 + examples/notes/update/go/updateANote.go | 20 + examples/notes/update/node/updateANote.js | 16 + notes/Makefile | 29 + notes/README.md | 7 + notes/examples.json | 93 ++ notes/handler/notes.go | 284 ++++++ notes/main.go | 27 + notes/proto/notes.pb.go | 1002 +++++++++++++++++++++ notes/proto/notes.pb.micro.go | 253 ++++++ notes/proto/notes.proto | 91 ++ notes/publicapi.json | 5 + 29 files changed, 2223 insertions(+), 1 deletion(-) create mode 100755 clients/go/notes/notes.go create mode 100755 clients/ts/notes/index.ts create mode 100755 examples/notes/create/curl/createANote.sh create mode 100755 examples/notes/create/go/createANote.go create mode 100755 examples/notes/create/node/createANote.js create mode 100755 examples/notes/delete/curl/deleteANote.sh create mode 100755 examples/notes/delete/go/deleteANote.go create mode 100755 examples/notes/delete/node/deleteANote.js create mode 100755 examples/notes/list/curl/listAllNotes.sh create mode 100755 examples/notes/list/go/listAllNotes.go create mode 100755 examples/notes/list/node/listAllNotes.js create mode 100755 examples/notes/read/curl/readANote.sh create mode 100755 examples/notes/read/go/readANote.go create mode 100755 examples/notes/read/node/readANote.js create mode 100755 examples/notes/update/curl/updateANote.sh create mode 100755 examples/notes/update/go/updateANote.go create mode 100755 examples/notes/update/node/updateANote.js create mode 100644 notes/Makefile create mode 100644 notes/README.md create mode 100644 notes/examples.json create mode 100644 notes/handler/notes.go create mode 100644 notes/main.go create mode 100644 notes/proto/notes.pb.go create mode 100644 notes/proto/notes.pb.micro.go create mode 100644 notes/proto/notes.proto create mode 100644 notes/publicapi.json diff --git a/clients/go/m3o.go b/clients/go/m3o.go index 4cd5c97..12be1d7 100755 --- a/clients/go/m3o.go +++ b/clients/go/m3o.go @@ -18,6 +18,7 @@ import ( "github.com/micro/services/clients/go/image" "github.com/micro/services/clients/go/ip" "github.com/micro/services/clients/go/location" + "github.com/micro/services/clients/go/notes" "github.com/micro/services/clients/go/otp" "github.com/micro/services/clients/go/postcode" "github.com/micro/services/clients/go/prayer" @@ -59,6 +60,7 @@ func NewClient(token string) *Client { ImageService: image.NewImageService(token), IpService: ip.NewIpService(token), LocationService: location.NewLocationService(token), + NotesService: notes.NewNotesService(token), OtpService: otp.NewOtpService(token), PostcodeService: postcode.NewPostcodeService(token), PrayerService: prayer.NewPrayerService(token), @@ -100,6 +102,7 @@ type Client struct { ImageService *image.ImageService IpService *ip.IpService LocationService *location.LocationService + NotesService *notes.NotesService OtpService *otp.OtpService PostcodeService *postcode.PostcodeService PrayerService *prayer.PrayerService diff --git a/clients/go/notes/notes.go b/clients/go/notes/notes.go new file mode 100755 index 0000000..4c29b8b --- /dev/null +++ b/clients/go/notes/notes.go @@ -0,0 +1,125 @@ +package notes + +import ( + "github.com/m3o/m3o-go/client" +) + +func NewNotesService(token string) *NotesService { + return &NotesService{ + client: client.NewClient(&client.Options{ + Token: token, + }), + } +} + +type NotesService struct { + client *client.Client +} + +// Create a new note +func (t *NotesService) Create(request *CreateRequest) (*CreateResponse, error) { + rsp := &CreateResponse{} + return rsp, t.client.Call("notes", "Create", request, rsp) +} + +// Delete a note +func (t *NotesService) Delete(request *DeleteRequest) (*DeleteResponse, error) { + rsp := &DeleteResponse{} + return rsp, t.client.Call("notes", "Delete", request, rsp) +} + +// List all the notes +func (t *NotesService) List(request *ListRequest) (*ListResponse, error) { + rsp := &ListResponse{} + return rsp, t.client.Call("notes", "List", request, rsp) +} + +// Read a note +func (t *NotesService) Read(request *ReadRequest) (*ReadResponse, error) { + rsp := &ReadResponse{} + return rsp, t.client.Call("notes", "Read", request, rsp) +} + +// Specify the note to events +func (t *NotesService) Subscribe(request *SubscribeRequest) (*SubscribeResponse, error) { + rsp := &SubscribeResponse{} + return rsp, t.client.Call("notes", "Subscribe", request, rsp) +} + +// Update a note +func (t *NotesService) Update(request *UpdateRequest) (*UpdateResponse, error) { + rsp := &UpdateResponse{} + return rsp, t.client.Call("notes", "Update", request, rsp) +} + +type CreateRequest struct { + // note text + Text string `json:"text"` + // note title + Title string `json:"title"` +} + +type CreateResponse struct { + // The created note + Note *Note `json:"note"` +} + +type DeleteRequest struct { + // specify the id of the note + Id string `json:"id"` +} + +type DeleteResponse struct { + Note *Note `json:"note"` +} + +type ListRequest struct { +} + +type ListResponse struct { + // the list of notes + Notes []Note `json:"notes"` +} + +type Note struct { + // time at which the note was created + Created string `json:"created"` + // unique id for the note, generated if not specified + Id string `json:"id"` + // text within the note + Text string `json:"text"` + // title of the note + Title string `json:"title"` + // time at which the note was updated + Updated string `json:"updated"` +} + +type ReadRequest struct { + // the note id + Id string `json:"id"` +} + +type ReadResponse struct { + // The note + Note *Note `json:"note"` +} + +type SubscribeRequest struct { + // optionally specify a note id + Id string `json:"id"` +} + +type SubscribeResponse struct { + // the event which occured; created, deleted, updated + Event string `json:"event"` + // the note which the operation occured on + Note *Note `json:"note"` +} + +type UpdateRequest struct { + Note *Note `json:"note"` +} + +type UpdateResponse struct { + Note *Note `json:"note"` +} diff --git a/clients/ts/index.ts b/clients/ts/index.ts index 3522ec7..2f5ee6c 100755 --- a/clients/ts/index.ts +++ b/clients/ts/index.ts @@ -15,6 +15,7 @@ import * as id from "./id"; import * as image from "./image"; import * as ip from "./ip"; import * as location from "./location"; +import * as notes from "./notes"; import * as otp from "./otp"; import * as postcode from "./postcode"; import * as prayer from "./prayer"; @@ -53,6 +54,7 @@ export class Client { this.imageService = new image.ImageService(token); this.ipService = new ip.IpService(token); this.locationService = new location.LocationService(token); + this.notesService = new notes.NotesService(token); this.otpService = new otp.OtpService(token); this.postcodeService = new postcode.PostcodeService(token); this.prayerService = new prayer.PrayerService(token); @@ -90,6 +92,7 @@ export class Client { imageService: image.ImageService; ipService: ip.IpService; locationService: location.LocationService; + notesService: notes.NotesService; otpService: otp.OtpService; postcodeService: postcode.PostcodeService; prayerService: prayer.PrayerService; diff --git a/clients/ts/notes/index.ts b/clients/ts/notes/index.ts new file mode 100755 index 0000000..651fcc6 --- /dev/null +++ b/clients/ts/notes/index.ts @@ -0,0 +1,120 @@ +import * as m3o from "@m3o/m3o-node"; + +export class NotesService { + private client: m3o.Client; + + constructor(token: string) { + this.client = new m3o.Client({ token: token }); + } + // Create a new note + create(request: CreateRequest): Promise { + return this.client.call( + "notes", + "Create", + request + ) as Promise; + } + // Delete a note + delete(request: DeleteRequest): Promise { + return this.client.call( + "notes", + "Delete", + request + ) as Promise; + } + // List all the notes + list(request: ListRequest): Promise { + return this.client.call("notes", "List", request) as Promise; + } + // Read a note + read(request: ReadRequest): Promise { + return this.client.call("notes", "Read", request) as Promise; + } + // Specify the note to events + subscribe(request: SubscribeRequest): Promise { + return this.client.call( + "notes", + "Subscribe", + request + ) as Promise; + } + // Update a note + update(request: UpdateRequest): Promise { + return this.client.call( + "notes", + "Update", + request + ) as Promise; + } +} + +export interface CreateRequest { + // note text + text?: string; + // note title + title?: string; +} + +export interface CreateResponse { + // The created note + note?: { [key: string]: any }; +} + +export interface DeleteRequest { + // specify the id of the note + id?: string; +} + +export interface DeleteResponse { + note?: { [key: string]: any }; +} + +export interface ListRequest {} + +export interface ListResponse { + // the list of notes + notes?: Note[]; +} + +export interface Note { + // time at which the note was created + created?: string; + // unique id for the note, generated if not specified + id?: string; + // text within the note + text?: string; + // title of the note + title?: string; + // time at which the note was updated + updated?: string; +} + +export interface ReadRequest { + // the note id + id?: string; +} + +export interface ReadResponse { + // The note + note?: { [key: string]: any }; +} + +export interface SubscribeRequest { + // optionally specify a note id + id?: string; +} + +export interface SubscribeResponse { + // the event which occured; created, deleted, updated + event?: string; + // the note which the operation occured on + note?: { [key: string]: any }; +} + +export interface UpdateRequest { + note?: { [key: string]: any }; +} + +export interface UpdateResponse { + note?: { [key: string]: any }; +} diff --git a/clients/ts/package.json b/clients/ts/package.json index d0c5a72..0f64f52 100644 --- a/clients/ts/package.json +++ b/clients/ts/package.json @@ -26,6 +26,7 @@ "./image": "./dist/image/index.js", "./ip": "./dist/ip/index.js", "./location": "./dist/location/index.js", + "./notes": "./dist/notes/index.js", "./otp": "./dist/otp/index.js", "./pkg": "./dist/pkg/index.js", "./postcode": "./dist/postcode/index.js", @@ -61,5 +62,5 @@ }, "type": "module", "types": "dist/index.d.ts", - "version": "1.0.530" + "version": "1.0.531" } \ No newline at end of file diff --git a/examples/notes/create/curl/createANote.sh b/examples/notes/create/curl/createANote.sh new file mode 100755 index 0000000..ffda249 --- /dev/null +++ b/examples/notes/create/curl/createANote.sh @@ -0,0 +1,7 @@ +curl "https://api.m3o.com/v1/notes/Create" \ +-H "Content-Type: application/json" \ +-H "Authorization: Bearer $MICRO_API_TOKEN" \ +-d '{ + "text": "This is my note", + "title": "New Note" +}' \ No newline at end of file diff --git a/examples/notes/create/go/createANote.go b/examples/notes/create/go/createANote.go new file mode 100755 index 0000000..12b7029 --- /dev/null +++ b/examples/notes/create/go/createANote.go @@ -0,0 +1,17 @@ +package example + +import ( + "fmt" + "github.com/micro/services/clients/go/notes" + "os" +) + +// Create a new note +func CreateAnote() { + notesService := notes.NewNotesService(os.Getenv("MICRO_API_TOKEN")) + rsp, err := notesService.Create(¬es.CreateRequest{ + Text: "This is my note", + Title: "New Note", + }) + fmt.Println(rsp, err) +} diff --git a/examples/notes/create/node/createANote.js b/examples/notes/create/node/createANote.js new file mode 100755 index 0000000..54a1a49 --- /dev/null +++ b/examples/notes/create/node/createANote.js @@ -0,0 +1,13 @@ +import * as notes from "m3o/notes"; + +// Create a new note +async function CreateAnote() { + let notesService = new notes.NotesService(process.env.MICRO_API_TOKEN); + let rsp = await notesService.create({ + text: "This is my note", + title: "New Note", + }); + console.log(rsp); +} + +await CreateAnote(); diff --git a/examples/notes/delete/curl/deleteANote.sh b/examples/notes/delete/curl/deleteANote.sh new file mode 100755 index 0000000..f5fde0f --- /dev/null +++ b/examples/notes/delete/curl/deleteANote.sh @@ -0,0 +1,6 @@ +curl "https://api.m3o.com/v1/notes/Delete" \ +-H "Content-Type: application/json" \ +-H "Authorization: Bearer $MICRO_API_TOKEN" \ +-d '{ + "id": "63c0cdf8-2121-11ec-a881-0242e36f037a" +}' \ No newline at end of file diff --git a/examples/notes/delete/go/deleteANote.go b/examples/notes/delete/go/deleteANote.go new file mode 100755 index 0000000..bc55661 --- /dev/null +++ b/examples/notes/delete/go/deleteANote.go @@ -0,0 +1,16 @@ +package example + +import ( + "fmt" + "github.com/micro/services/clients/go/notes" + "os" +) + +// Delete a note +func DeleteAnote() { + notesService := notes.NewNotesService(os.Getenv("MICRO_API_TOKEN")) + rsp, err := notesService.Delete(¬es.DeleteRequest{ + Id: "63c0cdf8-2121-11ec-a881-0242e36f037a", + }) + fmt.Println(rsp, err) +} diff --git a/examples/notes/delete/node/deleteANote.js b/examples/notes/delete/node/deleteANote.js new file mode 100755 index 0000000..b94306b --- /dev/null +++ b/examples/notes/delete/node/deleteANote.js @@ -0,0 +1,12 @@ +import * as notes from "m3o/notes"; + +// Delete a note +async function DeleteAnote() { + let notesService = new notes.NotesService(process.env.MICRO_API_TOKEN); + let rsp = await notesService.delete({ + id: "63c0cdf8-2121-11ec-a881-0242e36f037a", + }); + console.log(rsp); +} + +await DeleteAnote(); diff --git a/examples/notes/list/curl/listAllNotes.sh b/examples/notes/list/curl/listAllNotes.sh new file mode 100755 index 0000000..80fbc10 --- /dev/null +++ b/examples/notes/list/curl/listAllNotes.sh @@ -0,0 +1,4 @@ +curl "https://api.m3o.com/v1/notes/List" \ +-H "Content-Type: application/json" \ +-H "Authorization: Bearer $MICRO_API_TOKEN" \ +-d '{}' \ No newline at end of file diff --git a/examples/notes/list/go/listAllNotes.go b/examples/notes/list/go/listAllNotes.go new file mode 100755 index 0000000..ef259d2 --- /dev/null +++ b/examples/notes/list/go/listAllNotes.go @@ -0,0 +1,14 @@ +package example + +import ( + "fmt" + "github.com/micro/services/clients/go/notes" + "os" +) + +// List all the notes +func ListAllNotes() { + notesService := notes.NewNotesService(os.Getenv("MICRO_API_TOKEN")) + rsp, err := notesService.List(¬es.ListRequest{}) + fmt.Println(rsp, err) +} diff --git a/examples/notes/list/node/listAllNotes.js b/examples/notes/list/node/listAllNotes.js new file mode 100755 index 0000000..be2867f --- /dev/null +++ b/examples/notes/list/node/listAllNotes.js @@ -0,0 +1,10 @@ +import * as notes from "m3o/notes"; + +// List all the notes +async function ListAllNotes() { + let notesService = new notes.NotesService(process.env.MICRO_API_TOKEN); + let rsp = await notesService.list({}); + console.log(rsp); +} + +await ListAllNotes(); diff --git a/examples/notes/read/curl/readANote.sh b/examples/notes/read/curl/readANote.sh new file mode 100755 index 0000000..31d499d --- /dev/null +++ b/examples/notes/read/curl/readANote.sh @@ -0,0 +1,6 @@ +curl "https://api.m3o.com/v1/notes/Read" \ +-H "Content-Type: application/json" \ +-H "Authorization: Bearer $MICRO_API_TOKEN" \ +-d '{ + "id": "63c0cdf8-2121-11ec-a881-0242e36f037a" +}' \ No newline at end of file diff --git a/examples/notes/read/go/readANote.go b/examples/notes/read/go/readANote.go new file mode 100755 index 0000000..c0af61d --- /dev/null +++ b/examples/notes/read/go/readANote.go @@ -0,0 +1,16 @@ +package example + +import ( + "fmt" + "github.com/micro/services/clients/go/notes" + "os" +) + +// Read a note +func ReadAnote() { + notesService := notes.NewNotesService(os.Getenv("MICRO_API_TOKEN")) + rsp, err := notesService.Read(¬es.ReadRequest{ + Id: "63c0cdf8-2121-11ec-a881-0242e36f037a", + }) + fmt.Println(rsp, err) +} diff --git a/examples/notes/read/node/readANote.js b/examples/notes/read/node/readANote.js new file mode 100755 index 0000000..47360ae --- /dev/null +++ b/examples/notes/read/node/readANote.js @@ -0,0 +1,12 @@ +import * as notes from "m3o/notes"; + +// Read a note +async function ReadAnote() { + let notesService = new notes.NotesService(process.env.MICRO_API_TOKEN); + let rsp = await notesService.read({ + id: "63c0cdf8-2121-11ec-a881-0242e36f037a", + }); + console.log(rsp); +} + +await ReadAnote(); diff --git a/examples/notes/update/curl/updateANote.sh b/examples/notes/update/curl/updateANote.sh new file mode 100755 index 0000000..7feb4ee --- /dev/null +++ b/examples/notes/update/curl/updateANote.sh @@ -0,0 +1,10 @@ +curl "https://api.m3o.com/v1/notes/Update" \ +-H "Content-Type: application/json" \ +-H "Authorization: Bearer $MICRO_API_TOKEN" \ +-d '{ + "note": { + "id": "63c0cdf8-2121-11ec-a881-0242e36f037a", + "text": "Updated note text", + "title": "Update Note" + } +}' \ No newline at end of file diff --git a/examples/notes/update/go/updateANote.go b/examples/notes/update/go/updateANote.go new file mode 100755 index 0000000..1341884 --- /dev/null +++ b/examples/notes/update/go/updateANote.go @@ -0,0 +1,20 @@ +package example + +import ( + "fmt" + "github.com/micro/services/clients/go/notes" + "os" +) + +// Update a note +func UpdateAnote() { + notesService := notes.NewNotesService(os.Getenv("MICRO_API_TOKEN")) + rsp, err := notesService.Update(¬es.UpdateRequest{ + Note: ¬es.Note{ + Id: "63c0cdf8-2121-11ec-a881-0242e36f037a", + Text: "Updated note text", + Title: "Update Note", + }, + }) + fmt.Println(rsp, err) +} diff --git a/examples/notes/update/node/updateANote.js b/examples/notes/update/node/updateANote.js new file mode 100755 index 0000000..0080358 --- /dev/null +++ b/examples/notes/update/node/updateANote.js @@ -0,0 +1,16 @@ +import * as notes from "m3o/notes"; + +// Update a note +async function UpdateAnote() { + let notesService = new notes.NotesService(process.env.MICRO_API_TOKEN); + let rsp = await notesService.update({ + note: { + id: "63c0cdf8-2121-11ec-a881-0242e36f037a", + text: "Updated note text", + title: "Update Note", + }, + }); + console.log(rsp); +} + +await UpdateAnote(); diff --git a/notes/Makefile b/notes/Makefile new file mode 100644 index 0000000..bcefe05 --- /dev/null +++ b/notes/Makefile @@ -0,0 +1,29 @@ + +GOPATH:=$(shell go env GOPATH) + +.PHONY: api +api: + protoc --openapi_out=. --proto_path=. proto/notes.proto + +.PHONY: init +init: + go get -u github.com/golang/protobuf/proto + go get -u github.com/golang/protobuf/protoc-gen-go + go get github.com/micro/micro/v3/cmd/protoc-gen-micro + go get github.com/micro/micro/v3/cmd/protoc-gen-openapi + +.PHONY: proto +proto: + protoc --proto_path=. --micro_out=. --go_out=:. proto/notes.proto + +.PHONY: build +build: + go build -o notes *.go + +.PHONY: test +test: + go test -v ./... -cover + +.PHONY: docker +docker: + docker build . -t notes:latest diff --git a/notes/README.md b/notes/README.md new file mode 100644 index 0000000..7f2850b --- /dev/null +++ b/notes/README.md @@ -0,0 +1,7 @@ +Store and retrieve notes + +# Notes Service + +The notes service lets you keep track of notes as first class objects. Subscribe to changes and +perform fast retrieval of all your notes. + diff --git a/notes/examples.json b/notes/examples.json new file mode 100644 index 0000000..549c07c --- /dev/null +++ b/notes/examples.json @@ -0,0 +1,93 @@ + +{ + "create": [{ + "title": "Create a note", + "description": "Create a simple text based note", + "run_check": true, + "request": { + "title": "New Note", + "text": "This is my note" + }, + "response": { + "note": { + "id": "63c0cdf8-2121-11ec-a881-0242e36f037a", + "created": "2021-09-29T13:33:03+01:00", + "updated": "2021-09-29T13:33:03+01:00", + "title": "New Note", + "text": "This is my note" + } + } + }], + "read": [{ + "title": "Read a note", + "description": "Read a note by its ID", + "run_check": true, + "request": { + "id": "63c0cdf8-2121-11ec-a881-0242e36f037a" + }, + "response": { + "note": { + "id": "63c0cdf8-2121-11ec-a881-0242e36f037a", + "created": "2021-09-29T13:33:03+01:00", + "updated": "2021-09-29T13:33:03+01:00", + "title": "New Note", + "text": "This is my note" + } + } + }], + "list": [{ + "title": "List all notes", + "description": "List all your available notes", + "run_check": true, + "request": {}, + "response": { + "notes": [ + { + "id": "63c0cdf8-2121-11ec-a881-0242e36f037a", + "created": "2021-09-29T13:33:03+01:00", + "updated": "2021-09-29T13:33:03+01:00", + "title": "New Note", + "text": "This is my note" + } + ] + } + }], + "update": [{ + "title": "Update a Note", + "description": "Update the note title and text", + "run_check": true, + "request": { + "note": { + "id": "63c0cdf8-2121-11ec-a881-0242e36f037a", + "title": "Update Note", + "text": "Updated note text" + } + }, + "response": { + "note": { + "id": "63c0cdf8-2121-11ec-a881-0242e36f037a", + "created": "2021-09-29T13:33:03+01:00", + "updated": "2021-09-29T13:50:20+01:00", + "title": "Update Note", + "text": "Updated note text" + } + } + }], + "delete": [{ + "title": "Delete a Note", + "description": "Delete a note by id", + "run_check": true, + "request": { + "id": "63c0cdf8-2121-11ec-a881-0242e36f037a" + }, + "response": { + "note": { + "id": "63c0cdf8-2121-11ec-a881-0242e36f037a", + "created": "2021-09-29T13:33:03+01:00", + "updated": "2021-09-29T13:50:20+01:00", + "title": "Update Note", + "text": "Updated note text" + } + } + }] +} diff --git a/notes/handler/notes.go b/notes/handler/notes.go new file mode 100644 index 0000000..54286b1 --- /dev/null +++ b/notes/handler/notes.go @@ -0,0 +1,284 @@ +package handler + +import ( + "context" + "fmt" + "time" + + "github.com/google/uuid" + "github.com/micro/micro/v3/service/client" + "github.com/micro/micro/v3/service/errors" + "github.com/micro/micro/v3/service/store" + pb "github.com/micro/services/notes/proto" + "github.com/micro/services/pkg/tenant" + streamPb "github.com/micro/services/stream/proto" + "google.golang.org/protobuf/types/known/structpb" +) + +// New returns an initialized Notes +func New(c client.Client) *Notes { + return &Notes{ + Stream: streamPb.NewStreamService("stream", c), + } +} + +// Notes implements the notes proto definition +type Notes struct { + Stream streamPb.StreamService +} + +func newMessage(ev map[string]interface{}) *structpb.Struct { + v, _ := structpb.NewStruct(ev) + return v +} + +// Create inserts a new note in the store +func (h *Notes) Create(ctx context.Context, req *pb.CreateRequest, rsp *pb.CreateResponse) error { + if len(req.Title) == 0 && len(req.Text) == 0 { + return errors.BadRequest("notes.create", "missing title and text") + } + + tnt, ok := tenant.FromContext(ctx) + if !ok { + tnt = "default" + } + + // generate a key (uuid v4) + id, err := uuid.NewUUID() + if err != nil { + return err + } + + t := time.Now().Format(time.RFC3339) + // set the generated fields on the note + note := &pb.Note{ + Id: id.String(), + Created: t, + Updated: t, + Title: req.Title, + Text: req.Text, + } + + key := fmt.Sprintf("%s:%s", tnt, id) + rec := store.NewRecord(key, note) + + if err = store.Write(rec); err != nil { + return errors.InternalServerError("notes.created", "failed to create note") + } + + // return the note in the response + rsp.Note = note + + go h.Stream.Publish(ctx, &streamPb.PublishRequest{ + Topic: "notes", + Message: newMessage(map[string]interface{}{ + "type": "create", + "note": note, + }), + }) + + return nil +} + +func (h *Notes) Read(ctx context.Context, req *pb.ReadRequest, rsp *pb.ReadResponse) error { + if len(req.Id) == 0 { + return errors.BadRequest("notes.read", "Missing Note ID") + } + + tnt, ok := tenant.FromContext(ctx) + if !ok { + tnt = "default" + } + + key := fmt.Sprintf("%s:%s", tnt, req.Id) + + // read the specific note + recs, err := store.Read(key) + if err == store.ErrNotFound { + return errors.NotFound("notes.read", "Note not found") + } else if err != nil { + return errors.InternalServerError("notes.read", "Error reading from store: %v", err.Error()) + } + + // Decode the note + var note *pb.Note + if err := recs[0].Decode(¬e); err != nil { + return errors.InternalServerError("notes.update", "Error unmarshaling JSON: %v", err.Error()) + } + + // return the note + rsp.Note = note + + return nil +} + +// Update is a unary API which updates a note in the store +func (h *Notes) Update(ctx context.Context, req *pb.UpdateRequest, rsp *pb.UpdateResponse) error { + // Validate the request + if req.Note == nil { + return errors.BadRequest("notes.update", "Missing Note") + } + if len(req.Note.Id) == 0 { + return errors.BadRequest("notes.update", "Missing Note ID") + } + + tnt, ok := tenant.FromContext(ctx) + if !ok { + tnt = "default" + } + + key := fmt.Sprintf("%s:%s", tnt, req.Note.Id) + + // read the specific note + recs, err := store.Read(key) + if err == store.ErrNotFound { + return errors.NotFound("notes.update", "Note not found") + } else if err != nil { + return errors.InternalServerError("notes.update", "Error reading from store: %v", err.Error()) + } + + // Decode the note + var note *pb.Note + if err := recs[0].Decode(¬e); err != nil { + return errors.InternalServerError("notes.update", "Error unmarshaling JSON: %v", err.Error()) + } + + // Update the notes title and text + note.Title = req.Note.Title + note.Text = req.Note.Text + note.Updated = time.Now().Format(time.RFC3339) + + rec := store.NewRecord(key, note) + + // Write the updated note to the store + if err = store.Write(rec); err != nil { + return errors.InternalServerError("notes.update", "Error writing to store: %v", err.Error()) + } + + go h.Stream.Publish(ctx, &streamPb.PublishRequest{ + Topic: "notes", + Message: newMessage(map[string]interface{}{ + "type": "update", + "note": note, + }), + }) + + rsp.Note = note + + return nil +} + +func (h *Notes) Subscribe(ctx context.Context, req *pb.SubscribeRequest, stream pb.Notes_SubscribeStream) error { + backendStream, err := h.Stream.Subscribe(ctx, &streamPb.SubscribeRequest{ + Topic: "notes", + }) + if err != nil { + return errors.InternalServerError("notes.subscribe", "Failed to subscribe to notes") + } + + for { + select { + case <-ctx.Done(): + return nil + default: + } + + // receive messages from the stream + msg, err := backendStream.Recv() + if err != nil { + return nil + } + + ev := msg.Message.AsMap() + note := ev["note"].(*pb.Note) + + // filter if necessary by id + if len(req.Id) > 0 && note.Id != req.Id { + continue + } + + // send back the event to the client + if err := stream.Send(&pb.SubscribeResponse{ + Event: ev["type"].(string), + Note: note, + }); err != nil { + return nil + } + } + + return nil +} + +// Delete removes the note from the store, looking up using ID +func (h *Notes) Delete(ctx context.Context, req *pb.DeleteRequest, rsp *pb.DeleteResponse) error { + // Validate the request + if len(req.Id) == 0 { + return errors.BadRequest("notes.delete", "Missing Note ID") + } + + tnt, ok := tenant.FromContext(ctx) + if !ok { + tnt = "default" + } + + key := fmt.Sprintf("%s:%s", tnt, req.Id) + + // read the specific note + recs, err := store.Read(key) + if err == store.ErrNotFound { + return nil + } else if err != nil { + return errors.InternalServerError("notes.delete", "Error reading from store: %v", err.Error()) + } + + // Decode the note + var note *pb.Note + if err := recs[0].Decode(¬e); err != nil { + return errors.InternalServerError("notes.delete", "Error unmarshaling JSON: %v", err.Error()) + } + + // now delete it + if err := store.Delete(key); err != nil && err != store.ErrNotFound { + return errors.InternalServerError("notes.delete", "Failed to delete note") + } + + go h.Stream.Publish(ctx, &streamPb.PublishRequest{ + Topic: "notes", + Message: newMessage(map[string]interface{}{ + "type": "delete", + "note": note, + }), + }) + + rsp.Note = note + + return nil +} + +// List returns all of the notes in the store +func (h *Notes) List(ctx context.Context, req *pb.ListRequest, rsp *pb.ListResponse) error { + tnt, ok := tenant.FromContext(ctx) + if !ok { + tnt = "default" + } + + key := fmt.Sprintf("%s:", tnt) + + // Retrieve all of the records in the store + recs, err := store.Read(key, store.ReadPrefix()) + if err != nil { + return errors.InternalServerError("notes.list", "Error reading from store: %v", err.Error()) + } + + // Initialize the response notes slice + rsp.Notes = make([]*pb.Note, len(recs)) + + // Unmarshal the notes into the response + for i, r := range recs { + if err := r.Decode(&rsp.Notes[i]); err != nil { + return errors.InternalServerError("notes.list", "Error decoding note: %v", err.Error()) + } + } + + return nil +} diff --git a/notes/main.go b/notes/main.go new file mode 100644 index 0000000..969a878 --- /dev/null +++ b/notes/main.go @@ -0,0 +1,27 @@ +package main + +import ( + "github.com/micro/micro/v3/service" + log "github.com/micro/micro/v3/service/logger" + "github.com/micro/services/notes/handler" + pb "github.com/micro/services/notes/proto" +) + +func main() { + // New Service + srv := service.New( + service.Name("notes"), + service.Version("latest"), + ) + + // Initialise service + srv.Init() + + // Register Handler + pb.RegisterNotesHandler(srv.Server(), handler.New(srv.Client())) + + // Run service + if err := srv.Run(); err != nil { + log.Fatal(err) + } +} diff --git a/notes/proto/notes.pb.go b/notes/proto/notes.pb.go new file mode 100644 index 0000000..00f5294 --- /dev/null +++ b/notes/proto/notes.pb.go @@ -0,0 +1,1002 @@ +// Code generated by protoc-gen-go. DO NOT EDIT. +// versions: +// protoc-gen-go v1.26.0 +// protoc v3.15.6 +// source: proto/notes.proto + +package notes + +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 Note struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + // unique id for the note, generated if not specified + Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"` + // time at which the note was created + Created string `protobuf:"bytes,2,opt,name=created,proto3" json:"created,omitempty"` + // time at which the note was updated + Updated string `protobuf:"bytes,3,opt,name=updated,proto3" json:"updated,omitempty"` + // title of the note + Title string `protobuf:"bytes,4,opt,name=title,proto3" json:"title,omitempty"` + // text within the note + Text string `protobuf:"bytes,5,opt,name=text,proto3" json:"text,omitempty"` +} + +func (x *Note) Reset() { + *x = Note{} + if protoimpl.UnsafeEnabled { + mi := &file_proto_notes_proto_msgTypes[0] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *Note) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*Note) ProtoMessage() {} + +func (x *Note) ProtoReflect() protoreflect.Message { + mi := &file_proto_notes_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 Note.ProtoReflect.Descriptor instead. +func (*Note) Descriptor() ([]byte, []int) { + return file_proto_notes_proto_rawDescGZIP(), []int{0} +} + +func (x *Note) GetId() string { + if x != nil { + return x.Id + } + return "" +} + +func (x *Note) GetCreated() string { + if x != nil { + return x.Created + } + return "" +} + +func (x *Note) GetUpdated() string { + if x != nil { + return x.Updated + } + return "" +} + +func (x *Note) GetTitle() string { + if x != nil { + return x.Title + } + return "" +} + +func (x *Note) GetText() string { + if x != nil { + return x.Text + } + return "" +} + +// Create a new note +type CreateRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + // note title + Title string `protobuf:"bytes,1,opt,name=title,proto3" json:"title,omitempty"` + // note text + Text string `protobuf:"bytes,2,opt,name=text,proto3" json:"text,omitempty"` +} + +func (x *CreateRequest) Reset() { + *x = CreateRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_proto_notes_proto_msgTypes[1] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *CreateRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*CreateRequest) ProtoMessage() {} + +func (x *CreateRequest) ProtoReflect() protoreflect.Message { + mi := &file_proto_notes_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 CreateRequest.ProtoReflect.Descriptor instead. +func (*CreateRequest) Descriptor() ([]byte, []int) { + return file_proto_notes_proto_rawDescGZIP(), []int{1} +} + +func (x *CreateRequest) GetTitle() string { + if x != nil { + return x.Title + } + return "" +} + +func (x *CreateRequest) GetText() string { + if x != nil { + return x.Text + } + return "" +} + +type CreateResponse struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + // The created note + Note *Note `protobuf:"bytes,1,opt,name=note,proto3" json:"note,omitempty"` +} + +func (x *CreateResponse) Reset() { + *x = CreateResponse{} + if protoimpl.UnsafeEnabled { + mi := &file_proto_notes_proto_msgTypes[2] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *CreateResponse) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*CreateResponse) ProtoMessage() {} + +func (x *CreateResponse) ProtoReflect() protoreflect.Message { + mi := &file_proto_notes_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 CreateResponse.ProtoReflect.Descriptor instead. +func (*CreateResponse) Descriptor() ([]byte, []int) { + return file_proto_notes_proto_rawDescGZIP(), []int{2} +} + +func (x *CreateResponse) GetNote() *Note { + if x != nil { + return x.Note + } + return nil +} + +// Read a note +type ReadRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + // the note id + Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"` +} + +func (x *ReadRequest) Reset() { + *x = ReadRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_proto_notes_proto_msgTypes[3] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *ReadRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*ReadRequest) ProtoMessage() {} + +func (x *ReadRequest) ProtoReflect() protoreflect.Message { + mi := &file_proto_notes_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 ReadRequest.ProtoReflect.Descriptor instead. +func (*ReadRequest) Descriptor() ([]byte, []int) { + return file_proto_notes_proto_rawDescGZIP(), []int{3} +} + +func (x *ReadRequest) GetId() string { + if x != nil { + return x.Id + } + return "" +} + +type ReadResponse struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + // The note + Note *Note `protobuf:"bytes,1,opt,name=note,proto3" json:"note,omitempty"` +} + +func (x *ReadResponse) Reset() { + *x = ReadResponse{} + if protoimpl.UnsafeEnabled { + mi := &file_proto_notes_proto_msgTypes[4] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *ReadResponse) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*ReadResponse) ProtoMessage() {} + +func (x *ReadResponse) ProtoReflect() protoreflect.Message { + mi := &file_proto_notes_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 ReadResponse.ProtoReflect.Descriptor instead. +func (*ReadResponse) Descriptor() ([]byte, []int) { + return file_proto_notes_proto_rawDescGZIP(), []int{4} +} + +func (x *ReadResponse) GetNote() *Note { + if x != nil { + return x.Note + } + return nil +} + +// Update a note +type UpdateRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Note *Note `protobuf:"bytes,1,opt,name=note,proto3" json:"note,omitempty"` +} + +func (x *UpdateRequest) Reset() { + *x = UpdateRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_proto_notes_proto_msgTypes[5] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *UpdateRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*UpdateRequest) ProtoMessage() {} + +func (x *UpdateRequest) ProtoReflect() protoreflect.Message { + mi := &file_proto_notes_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 UpdateRequest.ProtoReflect.Descriptor instead. +func (*UpdateRequest) Descriptor() ([]byte, []int) { + return file_proto_notes_proto_rawDescGZIP(), []int{5} +} + +func (x *UpdateRequest) GetNote() *Note { + if x != nil { + return x.Note + } + return nil +} + +type UpdateResponse struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Note *Note `protobuf:"bytes,1,opt,name=note,proto3" json:"note,omitempty"` +} + +func (x *UpdateResponse) Reset() { + *x = UpdateResponse{} + if protoimpl.UnsafeEnabled { + mi := &file_proto_notes_proto_msgTypes[6] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *UpdateResponse) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*UpdateResponse) ProtoMessage() {} + +func (x *UpdateResponse) ProtoReflect() protoreflect.Message { + mi := &file_proto_notes_proto_msgTypes[6] + 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 UpdateResponse.ProtoReflect.Descriptor instead. +func (*UpdateResponse) Descriptor() ([]byte, []int) { + return file_proto_notes_proto_rawDescGZIP(), []int{6} +} + +func (x *UpdateResponse) GetNote() *Note { + if x != nil { + return x.Note + } + return nil +} + +// Delete a note +type DeleteRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + // specify the id of the note + Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"` +} + +func (x *DeleteRequest) Reset() { + *x = DeleteRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_proto_notes_proto_msgTypes[7] + 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_notes_proto_msgTypes[7] + 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_notes_proto_rawDescGZIP(), []int{7} +} + +func (x *DeleteRequest) GetId() string { + if x != nil { + return x.Id + } + return "" +} + +type DeleteResponse struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Note *Note `protobuf:"bytes,1,opt,name=note,proto3" json:"note,omitempty"` +} + +func (x *DeleteResponse) Reset() { + *x = DeleteResponse{} + if protoimpl.UnsafeEnabled { + mi := &file_proto_notes_proto_msgTypes[8] + 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_notes_proto_msgTypes[8] + 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_notes_proto_rawDescGZIP(), []int{8} +} + +func (x *DeleteResponse) GetNote() *Note { + if x != nil { + return x.Note + } + return nil +} + +// List all the notes +type ListRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields +} + +func (x *ListRequest) Reset() { + *x = ListRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_proto_notes_proto_msgTypes[9] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *ListRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*ListRequest) ProtoMessage() {} + +func (x *ListRequest) ProtoReflect() protoreflect.Message { + mi := &file_proto_notes_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 ListRequest.ProtoReflect.Descriptor instead. +func (*ListRequest) Descriptor() ([]byte, []int) { + return file_proto_notes_proto_rawDescGZIP(), []int{9} +} + +type ListResponse struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + // the list of notes + Notes []*Note `protobuf:"bytes,1,rep,name=notes,proto3" json:"notes,omitempty"` +} + +func (x *ListResponse) Reset() { + *x = ListResponse{} + if protoimpl.UnsafeEnabled { + mi := &file_proto_notes_proto_msgTypes[10] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *ListResponse) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*ListResponse) ProtoMessage() {} + +func (x *ListResponse) ProtoReflect() protoreflect.Message { + mi := &file_proto_notes_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 ListResponse.ProtoReflect.Descriptor instead. +func (*ListResponse) Descriptor() ([]byte, []int) { + return file_proto_notes_proto_rawDescGZIP(), []int{10} +} + +func (x *ListResponse) GetNotes() []*Note { + if x != nil { + return x.Notes + } + return nil +} + +// Specify the note to events +type SubscribeRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + // optionally specify a note id + Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"` +} + +func (x *SubscribeRequest) Reset() { + *x = SubscribeRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_proto_notes_proto_msgTypes[11] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *SubscribeRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*SubscribeRequest) ProtoMessage() {} + +func (x *SubscribeRequest) ProtoReflect() protoreflect.Message { + mi := &file_proto_notes_proto_msgTypes[11] + 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 SubscribeRequest.ProtoReflect.Descriptor instead. +func (*SubscribeRequest) Descriptor() ([]byte, []int) { + return file_proto_notes_proto_rawDescGZIP(), []int{11} +} + +func (x *SubscribeRequest) GetId() string { + if x != nil { + return x.Id + } + return "" +} + +type SubscribeResponse struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + // the event which occured; created, deleted, updated + Event string `protobuf:"bytes,1,opt,name=event,proto3" json:"event,omitempty"` + // the note which the operation occured on + Note *Note `protobuf:"bytes,2,opt,name=note,proto3" json:"note,omitempty"` +} + +func (x *SubscribeResponse) Reset() { + *x = SubscribeResponse{} + if protoimpl.UnsafeEnabled { + mi := &file_proto_notes_proto_msgTypes[12] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *SubscribeResponse) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*SubscribeResponse) ProtoMessage() {} + +func (x *SubscribeResponse) ProtoReflect() protoreflect.Message { + mi := &file_proto_notes_proto_msgTypes[12] + 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 SubscribeResponse.ProtoReflect.Descriptor instead. +func (*SubscribeResponse) Descriptor() ([]byte, []int) { + return file_proto_notes_proto_rawDescGZIP(), []int{12} +} + +func (x *SubscribeResponse) GetEvent() string { + if x != nil { + return x.Event + } + return "" +} + +func (x *SubscribeResponse) GetNote() *Note { + if x != nil { + return x.Note + } + return nil +} + +var File_proto_notes_proto protoreflect.FileDescriptor + +var file_proto_notes_proto_rawDesc = []byte{ + 0x0a, 0x11, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x6e, 0x6f, 0x74, 0x65, 0x73, 0x2e, 0x70, 0x72, + 0x6f, 0x74, 0x6f, 0x12, 0x05, 0x6e, 0x6f, 0x74, 0x65, 0x73, 0x22, 0x74, 0x0a, 0x04, 0x4e, 0x6f, + 0x74, 0x65, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x02, + 0x69, 0x64, 0x12, 0x18, 0x0a, 0x07, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x64, 0x18, 0x02, 0x20, + 0x01, 0x28, 0x09, 0x52, 0x07, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x64, 0x12, 0x18, 0x0a, 0x07, + 0x75, 0x70, 0x64, 0x61, 0x74, 0x65, 0x64, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x75, + 0x70, 0x64, 0x61, 0x74, 0x65, 0x64, 0x12, 0x14, 0x0a, 0x05, 0x74, 0x69, 0x74, 0x6c, 0x65, 0x18, + 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x74, 0x69, 0x74, 0x6c, 0x65, 0x12, 0x12, 0x0a, 0x04, + 0x74, 0x65, 0x78, 0x74, 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x74, 0x65, 0x78, 0x74, + 0x22, 0x39, 0x0a, 0x0d, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, + 0x74, 0x12, 0x14, 0x0a, 0x05, 0x74, 0x69, 0x74, 0x6c, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, + 0x52, 0x05, 0x74, 0x69, 0x74, 0x6c, 0x65, 0x12, 0x12, 0x0a, 0x04, 0x74, 0x65, 0x78, 0x74, 0x18, + 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x74, 0x65, 0x78, 0x74, 0x22, 0x31, 0x0a, 0x0e, 0x43, + 0x72, 0x65, 0x61, 0x74, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x1f, 0x0a, + 0x04, 0x6e, 0x6f, 0x74, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0b, 0x2e, 0x6e, 0x6f, + 0x74, 0x65, 0x73, 0x2e, 0x4e, 0x6f, 0x74, 0x65, 0x52, 0x04, 0x6e, 0x6f, 0x74, 0x65, 0x22, 0x1d, + 0x0a, 0x0b, 0x52, 0x65, 0x61, 0x64, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x0e, 0x0a, + 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x02, 0x69, 0x64, 0x22, 0x2f, 0x0a, + 0x0c, 0x52, 0x65, 0x61, 0x64, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x1f, 0x0a, + 0x04, 0x6e, 0x6f, 0x74, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0b, 0x2e, 0x6e, 0x6f, + 0x74, 0x65, 0x73, 0x2e, 0x4e, 0x6f, 0x74, 0x65, 0x52, 0x04, 0x6e, 0x6f, 0x74, 0x65, 0x22, 0x30, + 0x0a, 0x0d, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, + 0x1f, 0x0a, 0x04, 0x6e, 0x6f, 0x74, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0b, 0x2e, + 0x6e, 0x6f, 0x74, 0x65, 0x73, 0x2e, 0x4e, 0x6f, 0x74, 0x65, 0x52, 0x04, 0x6e, 0x6f, 0x74, 0x65, + 0x22, 0x31, 0x0a, 0x0e, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, + 0x73, 0x65, 0x12, 0x1f, 0x0a, 0x04, 0x6e, 0x6f, 0x74, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, + 0x32, 0x0b, 0x2e, 0x6e, 0x6f, 0x74, 0x65, 0x73, 0x2e, 0x4e, 0x6f, 0x74, 0x65, 0x52, 0x04, 0x6e, + 0x6f, 0x74, 0x65, 0x22, 0x1f, 0x0a, 0x0d, 0x44, 0x65, 0x6c, 0x65, 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, 0x22, 0x31, 0x0a, 0x0e, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x52, 0x65, + 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x1f, 0x0a, 0x04, 0x6e, 0x6f, 0x74, 0x65, 0x18, 0x01, + 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0b, 0x2e, 0x6e, 0x6f, 0x74, 0x65, 0x73, 0x2e, 0x4e, 0x6f, 0x74, + 0x65, 0x52, 0x04, 0x6e, 0x6f, 0x74, 0x65, 0x22, 0x0d, 0x0a, 0x0b, 0x4c, 0x69, 0x73, 0x74, 0x52, + 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x22, 0x31, 0x0a, 0x0c, 0x4c, 0x69, 0x73, 0x74, 0x52, 0x65, + 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x21, 0x0a, 0x05, 0x6e, 0x6f, 0x74, 0x65, 0x73, 0x18, + 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x0b, 0x2e, 0x6e, 0x6f, 0x74, 0x65, 0x73, 0x2e, 0x4e, 0x6f, + 0x74, 0x65, 0x52, 0x05, 0x6e, 0x6f, 0x74, 0x65, 0x73, 0x22, 0x22, 0x0a, 0x10, 0x53, 0x75, 0x62, + 0x73, 0x63, 0x72, 0x69, 0x62, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x0e, 0x0a, + 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x02, 0x69, 0x64, 0x22, 0x4a, 0x0a, + 0x11, 0x53, 0x75, 0x62, 0x73, 0x63, 0x72, 0x69, 0x62, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, + 0x73, 0x65, 0x12, 0x14, 0x0a, 0x05, 0x65, 0x76, 0x65, 0x6e, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, + 0x09, 0x52, 0x05, 0x65, 0x76, 0x65, 0x6e, 0x74, 0x12, 0x1f, 0x0a, 0x04, 0x6e, 0x6f, 0x74, 0x65, + 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0b, 0x2e, 0x6e, 0x6f, 0x74, 0x65, 0x73, 0x2e, 0x4e, + 0x6f, 0x74, 0x65, 0x52, 0x04, 0x6e, 0x6f, 0x74, 0x65, 0x32, 0xd0, 0x02, 0x0a, 0x05, 0x4e, 0x6f, + 0x74, 0x65, 0x73, 0x12, 0x2f, 0x0a, 0x04, 0x4c, 0x69, 0x73, 0x74, 0x12, 0x12, 0x2e, 0x6e, 0x6f, + 0x74, 0x65, 0x73, 0x2e, 0x4c, 0x69, 0x73, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, + 0x13, 0x2e, 0x6e, 0x6f, 0x74, 0x65, 0x73, 0x2e, 0x4c, 0x69, 0x73, 0x74, 0x52, 0x65, 0x73, 0x70, + 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x35, 0x0a, 0x06, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x12, 0x14, + 0x2e, 0x6e, 0x6f, 0x74, 0x65, 0x73, 0x2e, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x52, 0x65, 0x71, + 0x75, 0x65, 0x73, 0x74, 0x1a, 0x15, 0x2e, 0x6e, 0x6f, 0x74, 0x65, 0x73, 0x2e, 0x43, 0x72, 0x65, + 0x61, 0x74, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x2f, 0x0a, 0x04, 0x52, + 0x65, 0x61, 0x64, 0x12, 0x12, 0x2e, 0x6e, 0x6f, 0x74, 0x65, 0x73, 0x2e, 0x52, 0x65, 0x61, 0x64, + 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x13, 0x2e, 0x6e, 0x6f, 0x74, 0x65, 0x73, 0x2e, + 0x52, 0x65, 0x61, 0x64, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x35, 0x0a, 0x06, + 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x12, 0x14, 0x2e, 0x6e, 0x6f, 0x74, 0x65, 0x73, 0x2e, 0x44, + 0x65, 0x6c, 0x65, 0x74, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x15, 0x2e, 0x6e, + 0x6f, 0x74, 0x65, 0x73, 0x2e, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, + 0x6e, 0x73, 0x65, 0x12, 0x35, 0x0a, 0x06, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x12, 0x14, 0x2e, + 0x6e, 0x6f, 0x74, 0x65, 0x73, 0x2e, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x52, 0x65, 0x71, 0x75, + 0x65, 0x73, 0x74, 0x1a, 0x15, 0x2e, 0x6e, 0x6f, 0x74, 0x65, 0x73, 0x2e, 0x55, 0x70, 0x64, 0x61, + 0x74, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x40, 0x0a, 0x09, 0x53, 0x75, + 0x62, 0x73, 0x63, 0x72, 0x69, 0x62, 0x65, 0x12, 0x17, 0x2e, 0x6e, 0x6f, 0x74, 0x65, 0x73, 0x2e, + 0x53, 0x75, 0x62, 0x73, 0x63, 0x72, 0x69, 0x62, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, + 0x1a, 0x18, 0x2e, 0x6e, 0x6f, 0x74, 0x65, 0x73, 0x2e, 0x53, 0x75, 0x62, 0x73, 0x63, 0x72, 0x69, + 0x62, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x30, 0x01, 0x42, 0x0f, 0x5a, 0x0d, + 0x2e, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x3b, 0x6e, 0x6f, 0x74, 0x65, 0x73, 0x62, 0x06, 0x70, + 0x72, 0x6f, 0x74, 0x6f, 0x33, +} + +var ( + file_proto_notes_proto_rawDescOnce sync.Once + file_proto_notes_proto_rawDescData = file_proto_notes_proto_rawDesc +) + +func file_proto_notes_proto_rawDescGZIP() []byte { + file_proto_notes_proto_rawDescOnce.Do(func() { + file_proto_notes_proto_rawDescData = protoimpl.X.CompressGZIP(file_proto_notes_proto_rawDescData) + }) + return file_proto_notes_proto_rawDescData +} + +var file_proto_notes_proto_msgTypes = make([]protoimpl.MessageInfo, 13) +var file_proto_notes_proto_goTypes = []interface{}{ + (*Note)(nil), // 0: notes.Note + (*CreateRequest)(nil), // 1: notes.CreateRequest + (*CreateResponse)(nil), // 2: notes.CreateResponse + (*ReadRequest)(nil), // 3: notes.ReadRequest + (*ReadResponse)(nil), // 4: notes.ReadResponse + (*UpdateRequest)(nil), // 5: notes.UpdateRequest + (*UpdateResponse)(nil), // 6: notes.UpdateResponse + (*DeleteRequest)(nil), // 7: notes.DeleteRequest + (*DeleteResponse)(nil), // 8: notes.DeleteResponse + (*ListRequest)(nil), // 9: notes.ListRequest + (*ListResponse)(nil), // 10: notes.ListResponse + (*SubscribeRequest)(nil), // 11: notes.SubscribeRequest + (*SubscribeResponse)(nil), // 12: notes.SubscribeResponse +} +var file_proto_notes_proto_depIdxs = []int32{ + 0, // 0: notes.CreateResponse.note:type_name -> notes.Note + 0, // 1: notes.ReadResponse.note:type_name -> notes.Note + 0, // 2: notes.UpdateRequest.note:type_name -> notes.Note + 0, // 3: notes.UpdateResponse.note:type_name -> notes.Note + 0, // 4: notes.DeleteResponse.note:type_name -> notes.Note + 0, // 5: notes.ListResponse.notes:type_name -> notes.Note + 0, // 6: notes.SubscribeResponse.note:type_name -> notes.Note + 9, // 7: notes.Notes.List:input_type -> notes.ListRequest + 1, // 8: notes.Notes.Create:input_type -> notes.CreateRequest + 3, // 9: notes.Notes.Read:input_type -> notes.ReadRequest + 7, // 10: notes.Notes.Delete:input_type -> notes.DeleteRequest + 5, // 11: notes.Notes.Update:input_type -> notes.UpdateRequest + 11, // 12: notes.Notes.Subscribe:input_type -> notes.SubscribeRequest + 10, // 13: notes.Notes.List:output_type -> notes.ListResponse + 2, // 14: notes.Notes.Create:output_type -> notes.CreateResponse + 4, // 15: notes.Notes.Read:output_type -> notes.ReadResponse + 8, // 16: notes.Notes.Delete:output_type -> notes.DeleteResponse + 6, // 17: notes.Notes.Update:output_type -> notes.UpdateResponse + 12, // 18: notes.Notes.Subscribe:output_type -> notes.SubscribeResponse + 13, // [13:19] is the sub-list for method output_type + 7, // [7:13] is the sub-list for method input_type + 7, // [7:7] is the sub-list for extension type_name + 7, // [7:7] is the sub-list for extension extendee + 0, // [0:7] is the sub-list for field type_name +} + +func init() { file_proto_notes_proto_init() } +func file_proto_notes_proto_init() { + if File_proto_notes_proto != nil { + return + } + if !protoimpl.UnsafeEnabled { + file_proto_notes_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*Note); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_proto_notes_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*CreateRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_proto_notes_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*CreateResponse); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_proto_notes_proto_msgTypes[3].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*ReadRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_proto_notes_proto_msgTypes[4].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*ReadResponse); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_proto_notes_proto_msgTypes[5].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*UpdateRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_proto_notes_proto_msgTypes[6].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*UpdateResponse); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_proto_notes_proto_msgTypes[7].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_notes_proto_msgTypes[8].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 + } + } + file_proto_notes_proto_msgTypes[9].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*ListRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_proto_notes_proto_msgTypes[10].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*ListResponse); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_proto_notes_proto_msgTypes[11].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*SubscribeRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_proto_notes_proto_msgTypes[12].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*SubscribeResponse); 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_notes_proto_rawDesc, + NumEnums: 0, + NumMessages: 13, + NumExtensions: 0, + NumServices: 1, + }, + GoTypes: file_proto_notes_proto_goTypes, + DependencyIndexes: file_proto_notes_proto_depIdxs, + MessageInfos: file_proto_notes_proto_msgTypes, + }.Build() + File_proto_notes_proto = out.File + file_proto_notes_proto_rawDesc = nil + file_proto_notes_proto_goTypes = nil + file_proto_notes_proto_depIdxs = nil +} diff --git a/notes/proto/notes.pb.micro.go b/notes/proto/notes.pb.micro.go new file mode 100644 index 0000000..3cfabdb --- /dev/null +++ b/notes/proto/notes.pb.micro.go @@ -0,0 +1,253 @@ +// Code generated by protoc-gen-micro. DO NOT EDIT. +// source: proto/notes.proto + +package notes + +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 Notes service + +func NewNotesEndpoints() []*api.Endpoint { + return []*api.Endpoint{} +} + +// Client API for Notes service + +type NotesService interface { + List(ctx context.Context, in *ListRequest, opts ...client.CallOption) (*ListResponse, error) + Create(ctx context.Context, in *CreateRequest, opts ...client.CallOption) (*CreateResponse, error) + Read(ctx context.Context, in *ReadRequest, opts ...client.CallOption) (*ReadResponse, error) + Delete(ctx context.Context, in *DeleteRequest, opts ...client.CallOption) (*DeleteResponse, error) + Update(ctx context.Context, in *UpdateRequest, opts ...client.CallOption) (*UpdateResponse, error) + Subscribe(ctx context.Context, in *SubscribeRequest, opts ...client.CallOption) (Notes_SubscribeService, error) +} + +type notesService struct { + c client.Client + name string +} + +func NewNotesService(name string, c client.Client) NotesService { + return ¬esService{ + c: c, + name: name, + } +} + +func (c *notesService) List(ctx context.Context, in *ListRequest, opts ...client.CallOption) (*ListResponse, error) { + req := c.c.NewRequest(c.name, "Notes.List", in) + out := new(ListResponse) + err := c.c.Call(ctx, req, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *notesService) Create(ctx context.Context, in *CreateRequest, opts ...client.CallOption) (*CreateResponse, error) { + req := c.c.NewRequest(c.name, "Notes.Create", in) + out := new(CreateResponse) + err := c.c.Call(ctx, req, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *notesService) Read(ctx context.Context, in *ReadRequest, opts ...client.CallOption) (*ReadResponse, error) { + req := c.c.NewRequest(c.name, "Notes.Read", in) + out := new(ReadResponse) + err := c.c.Call(ctx, req, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *notesService) Delete(ctx context.Context, in *DeleteRequest, opts ...client.CallOption) (*DeleteResponse, error) { + req := c.c.NewRequest(c.name, "Notes.Delete", in) + out := new(DeleteResponse) + err := c.c.Call(ctx, req, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *notesService) Update(ctx context.Context, in *UpdateRequest, opts ...client.CallOption) (*UpdateResponse, error) { + req := c.c.NewRequest(c.name, "Notes.Update", in) + out := new(UpdateResponse) + err := c.c.Call(ctx, req, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *notesService) Subscribe(ctx context.Context, in *SubscribeRequest, opts ...client.CallOption) (Notes_SubscribeService, error) { + req := c.c.NewRequest(c.name, "Notes.Subscribe", &SubscribeRequest{}) + stream, err := c.c.Stream(ctx, req, opts...) + if err != nil { + return nil, err + } + if err := stream.Send(in); err != nil { + return nil, err + } + return ¬esServiceSubscribe{stream}, nil +} + +type Notes_SubscribeService interface { + Context() context.Context + SendMsg(interface{}) error + RecvMsg(interface{}) error + Close() error + Recv() (*SubscribeResponse, error) +} + +type notesServiceSubscribe struct { + stream client.Stream +} + +func (x *notesServiceSubscribe) Close() error { + return x.stream.Close() +} + +func (x *notesServiceSubscribe) Context() context.Context { + return x.stream.Context() +} + +func (x *notesServiceSubscribe) SendMsg(m interface{}) error { + return x.stream.Send(m) +} + +func (x *notesServiceSubscribe) RecvMsg(m interface{}) error { + return x.stream.Recv(m) +} + +func (x *notesServiceSubscribe) Recv() (*SubscribeResponse, error) { + m := new(SubscribeResponse) + err := x.stream.Recv(m) + if err != nil { + return nil, err + } + return m, nil +} + +// Server API for Notes service + +type NotesHandler interface { + List(context.Context, *ListRequest, *ListResponse) error + Create(context.Context, *CreateRequest, *CreateResponse) error + Read(context.Context, *ReadRequest, *ReadResponse) error + Delete(context.Context, *DeleteRequest, *DeleteResponse) error + Update(context.Context, *UpdateRequest, *UpdateResponse) error + Subscribe(context.Context, *SubscribeRequest, Notes_SubscribeStream) error +} + +func RegisterNotesHandler(s server.Server, hdlr NotesHandler, opts ...server.HandlerOption) error { + type notes interface { + List(ctx context.Context, in *ListRequest, out *ListResponse) error + Create(ctx context.Context, in *CreateRequest, out *CreateResponse) error + Read(ctx context.Context, in *ReadRequest, out *ReadResponse) error + Delete(ctx context.Context, in *DeleteRequest, out *DeleteResponse) error + Update(ctx context.Context, in *UpdateRequest, out *UpdateResponse) error + Subscribe(ctx context.Context, stream server.Stream) error + } + type Notes struct { + notes + } + h := ¬esHandler{hdlr} + return s.Handle(s.NewHandler(&Notes{h}, opts...)) +} + +type notesHandler struct { + NotesHandler +} + +func (h *notesHandler) List(ctx context.Context, in *ListRequest, out *ListResponse) error { + return h.NotesHandler.List(ctx, in, out) +} + +func (h *notesHandler) Create(ctx context.Context, in *CreateRequest, out *CreateResponse) error { + return h.NotesHandler.Create(ctx, in, out) +} + +func (h *notesHandler) Read(ctx context.Context, in *ReadRequest, out *ReadResponse) error { + return h.NotesHandler.Read(ctx, in, out) +} + +func (h *notesHandler) Delete(ctx context.Context, in *DeleteRequest, out *DeleteResponse) error { + return h.NotesHandler.Delete(ctx, in, out) +} + +func (h *notesHandler) Update(ctx context.Context, in *UpdateRequest, out *UpdateResponse) error { + return h.NotesHandler.Update(ctx, in, out) +} + +func (h *notesHandler) Subscribe(ctx context.Context, stream server.Stream) error { + m := new(SubscribeRequest) + if err := stream.Recv(m); err != nil { + return err + } + return h.NotesHandler.Subscribe(ctx, m, ¬esSubscribeStream{stream}) +} + +type Notes_SubscribeStream interface { + Context() context.Context + SendMsg(interface{}) error + RecvMsg(interface{}) error + Close() error + Send(*SubscribeResponse) error +} + +type notesSubscribeStream struct { + stream server.Stream +} + +func (x *notesSubscribeStream) Close() error { + return x.stream.Close() +} + +func (x *notesSubscribeStream) Context() context.Context { + return x.stream.Context() +} + +func (x *notesSubscribeStream) SendMsg(m interface{}) error { + return x.stream.Send(m) +} + +func (x *notesSubscribeStream) RecvMsg(m interface{}) error { + return x.stream.Recv(m) +} + +func (x *notesSubscribeStream) Send(m *SubscribeResponse) error { + return x.stream.Send(m) +} diff --git a/notes/proto/notes.proto b/notes/proto/notes.proto new file mode 100644 index 0000000..5aa7229 --- /dev/null +++ b/notes/proto/notes.proto @@ -0,0 +1,91 @@ +syntax = "proto3"; + +package notes; + +option go_package = "./proto;notes"; + +service Notes { + rpc List(ListRequest) returns (ListResponse); + rpc Create(CreateRequest) returns (CreateResponse); + rpc Read(ReadRequest) returns (ReadResponse); + rpc Delete(DeleteRequest) returns (DeleteResponse); + rpc Update(UpdateRequest) returns (UpdateResponse); + rpc Subscribe(SubscribeRequest) returns (stream SubscribeResponse); +} + +message Note { + // unique id for the note, generated if not specified + string id = 1; + // time at which the note was created + string created = 2; + // time at which the note was updated + string updated = 3; + // title of the note + string title = 4; + // text within the note + string text = 5; +} + +// Create a new note +message CreateRequest { + // note title + string title = 1; + // note text + string text = 2; +} + +message CreateResponse { + // The created note + Note note = 1; +} + +// Read a note +message ReadRequest { + // the note id + string id = 1; +} + +message ReadResponse { + // The note + Note note = 1; +} + +// Update a note +message UpdateRequest { + Note note = 1; +} + +message UpdateResponse { + Note note = 1; +} + +// Delete a note +message DeleteRequest { + // specify the id of the note + string id = 1; +} + +message DeleteResponse { + Note note = 1; +} + +// List all the notes +message ListRequest {} + +message ListResponse { + // the list of notes + repeated Note notes = 1; +} + +// Specify the note to events +message SubscribeRequest { + // optionally specify a note id + string id = 1; +} + +message SubscribeResponse { + // the event which occured; created, deleted, updated + string event = 1; + // the note which the operation occured on + Note note = 2; +} diff --git a/notes/publicapi.json b/notes/publicapi.json new file mode 100644 index 0000000..275adc7 --- /dev/null +++ b/notes/publicapi.json @@ -0,0 +1,5 @@ +{ + "name": "notes", + "icon": "📝", + "category": "storage" +}