Merge pull request #1 from sundowndev/feat/grpc-gateway

Add grpc gateway and openapi
pull/3/head
Raphaël 2024-02-27 23:25:29 +04:00 committed by GitHub
commit 53503cb9f3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
43 changed files with 2191 additions and 277 deletions

3
.gitignore vendored
View File

@ -29,4 +29,5 @@ go.work
coverage
coverage.*
unit-tests.xml
.idea
.idea
.cache

View File

@ -1,8 +1,13 @@
BUF_VERSION:=v1.29.0
SWAGGER_UI_VERSION:=v5.11.8
install-tools:
go install gotest.tools/gotestsum@v1.11.0
go install github.com/bufbuild/buf/cmd/buf@$(BUF_VERSION)
go install google.golang.org/protobuf/cmd/protoc-gen-go@v1.28
go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@v1.2
go install github.com/bufbuild/buf/cmd/buf@v1.29.0
go install github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-grpc-gateway@v2.19.1
go install github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-openapiv2@v2.19.1
build: generate
buf build
@ -11,6 +16,7 @@ build: generate
generate:
buf generate
go generate ./...
SWAGGER_UI_VERSION=$(SWAGGER_UI_VERSION) ./scripts/generate-swagger-ui.sh
lint:
buf lint

View File

@ -5,11 +5,21 @@ managed:
default: github.com/sundowndev/grpc-api-example/proto
except:
- buf.build/googleapis/googleapis
- buf.build/grpc-ecosystem/grpc-gateway
- buf.build/bufbuild/protovalidate
plugins:
- plugin: buf.build/protocolbuffers/go:v1.30.0
- plugin: go
out: proto
opt: paths=source_relative
- plugin: buf.build/grpc/go:v1.3.0
opt:
- paths=source_relative
- plugin: go-grpc
out: proto
opt: paths=source_relative,require_unimplemented_servers=false
opt:
- paths=source_relative
- require_unimplemented_servers=false
- plugin: grpc-gateway
out: proto
opt:
- paths=source_relative
- plugin: openapiv2
out: gen/openapiv2

8
gen/embed.go Normal file
View File

@ -0,0 +1,8 @@
package gen
import (
"embed"
)
//go:embed openapiv2/*
var OpenAPI embed.FS

202
gen/openapiv2/LICENSE Normal file
View File

@ -0,0 +1,202 @@
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright [yyyy] [name of copyright owner]
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

Binary file not shown.

After

Width:  |  Height:  |  Size: 665 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 628 B

View File

@ -0,0 +1,90 @@
{
"swagger": "2.0",
"info": {
"title": "health/v1/health.proto",
"version": "1.0"
},
"tags": [
{
"name": "HealthService"
}
],
"schemes": [
"http",
"https"
],
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"paths": {
"/api/v1/health": {
"get": {
"summary": "Get health status",
"description": "Get health status of the server.",
"operationId": "HealthService_GetHealth",
"responses": {
"200": {
"description": "A successful response.",
"schema": {
"$ref": "#/definitions/v1GetHealthResponse"
}
},
"default": {
"description": "An unexpected error response.",
"schema": {
"$ref": "#/definitions/rpcStatus"
}
}
},
"tags": [
"HealthService"
]
}
}
},
"definitions": {
"protobufAny": {
"type": "object",
"properties": {
"@type": {
"type": "string"
}
},
"additionalProperties": {}
},
"rpcStatus": {
"type": "object",
"properties": {
"code": {
"type": "integer",
"format": "int32"
},
"message": {
"type": "string"
},
"details": {
"type": "array",
"items": {
"type": "object",
"$ref": "#/definitions/protobufAny"
}
}
}
},
"v1GetHealthResponse": {
"type": "object",
"properties": {
"ok": {
"type": "boolean"
}
}
}
},
"externalDocs": {
"description": "gRPC application example repository",
"url": "https://github.com/sundowndev/grpc-api-example"
}
}

16
gen/openapiv2/index.css Normal file
View File

@ -0,0 +1,16 @@
html {
box-sizing: border-box;
overflow: -moz-scrollbars-vertical;
overflow-y: scroll;
}
*,
*:before,
*:after {
box-sizing: inherit;
}
body {
margin: 0;
background: #fafafa;
}

19
gen/openapiv2/index.html Normal file
View File

@ -0,0 +1,19 @@
<!-- HTML for static distribution bundle build -->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Swagger UI</title>
<link rel="stylesheet" type="text/css" href="./swagger-ui.css" />
<link rel="stylesheet" type="text/css" href="index.css" />
<link rel="icon" type="image/png" href="./favicon-32x32.png" sizes="32x32" />
<link rel="icon" type="image/png" href="./favicon-16x16.png" sizes="16x16" />
</head>
<body>
<div id="swagger-ui"></div>
<script src="./swagger-ui-bundle.js" charset="UTF-8"> </script>
<script src="./swagger-ui-standalone-preset.js" charset="UTF-8"> </script>
<script src="./swagger-initializer.js" charset="UTF-8"> </script>
</body>
</html>

View File

@ -0,0 +1,194 @@
{
"swagger": "2.0",
"info": {
"title": "notes/v1/notes.proto",
"version": "1.0"
},
"tags": [
{
"name": "NotesService"
}
],
"schemes": [
"http",
"https"
],
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"paths": {
"/api/v1/notes": {
"post": {
"summary": "Add note",
"description": "Add a new note.",
"operationId": "NotesService_AddNote",
"responses": {
"200": {
"description": "A successful response.",
"schema": {
"$ref": "#/definitions/v1AddNoteResponse"
}
},
"default": {
"description": "An unexpected error response.",
"schema": {
"$ref": "#/definitions/rpcStatus"
}
}
},
"parameters": [
{
"name": "body",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/v1AddNoteRequest"
}
}
],
"tags": [
"NotesService"
]
}
},
"/api/v1/notes/{note.id}": {
"patch": {
"summary": "Edit note",
"description": "Edit an existing note.",
"operationId": "NotesService_EditNote",
"responses": {
"200": {
"description": "A successful response.",
"schema": {
"$ref": "#/definitions/v1EditNoteResponse"
}
},
"default": {
"description": "An unexpected error response.",
"schema": {
"$ref": "#/definitions/rpcStatus"
}
}
},
"parameters": [
{
"name": "note.id",
"in": "path",
"required": true,
"type": "string"
},
{
"name": "body",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/NotesServiceEditNoteBody"
}
}
],
"tags": [
"NotesService"
]
}
}
},
"definitions": {
"NotesServiceEditNoteBody": {
"type": "object",
"properties": {
"note": {
"type": "object",
"properties": {
"title": {
"type": "string"
},
"archived": {
"type": "boolean"
}
}
}
}
},
"protobufAny": {
"type": "object",
"properties": {
"@type": {
"type": "string"
}
},
"additionalProperties": {}
},
"rpcStatus": {
"type": "object",
"properties": {
"code": {
"type": "integer",
"format": "int32"
},
"message": {
"type": "string"
},
"details": {
"type": "array",
"items": {
"type": "object",
"$ref": "#/definitions/protobufAny"
}
}
}
},
"v1AddNoteRequest": {
"type": "object",
"properties": {
"title": {
"type": "string"
}
}
},
"v1AddNoteResponse": {
"type": "object",
"properties": {
"note": {
"$ref": "#/definitions/v1Note"
}
}
},
"v1EditNoteResponse": {
"type": "object",
"properties": {
"note": {
"$ref": "#/definitions/v1Note"
}
}
},
"v1ListNotesResponse": {
"type": "object",
"properties": {
"note": {
"$ref": "#/definitions/v1Note"
}
}
},
"v1Note": {
"type": "object",
"properties": {
"id": {
"type": "string"
},
"title": {
"type": "string"
},
"archived": {
"type": "boolean"
}
}
}
},
"externalDocs": {
"description": "gRPC application example repository",
"url": "https://github.com/sundowndev/grpc-api-example"
}
}

View File

@ -0,0 +1,79 @@
<!doctype html>
<html lang="en-US">
<head>
<title>Swagger UI: OAuth2 Redirect</title>
</head>
<body>
<script>
'use strict';
function run () {
var oauth2 = window.opener.swaggerUIRedirectOauth2;
var sentState = oauth2.state;
var redirectUrl = oauth2.redirectUrl;
var isValid, qp, arr;
if (/code|token|error/.test(window.location.hash)) {
qp = window.location.hash.substring(1).replace('?', '&');
} else {
qp = location.search.substring(1);
}
arr = qp.split("&");
arr.forEach(function (v,i,_arr) { _arr[i] = '"' + v.replace('=', '":"') + '"';});
qp = qp ? JSON.parse('{' + arr.join() + '}',
function (key, value) {
return key === "" ? value : decodeURIComponent(value);
}
) : {};
isValid = qp.state === sentState;
if ((
oauth2.auth.schema.get("flow") === "accessCode" ||
oauth2.auth.schema.get("flow") === "authorizationCode" ||
oauth2.auth.schema.get("flow") === "authorization_code"
) && !oauth2.auth.code) {
if (!isValid) {
oauth2.errCb({
authId: oauth2.auth.name,
source: "auth",
level: "warning",
message: "Authorization may be unsafe, passed state was changed in server. The passed state wasn't returned from auth server."
});
}
if (qp.code) {
delete oauth2.state;
oauth2.auth.code = qp.code;
oauth2.callback({auth: oauth2.auth, redirectUrl: redirectUrl});
} else {
let oauthErrorMsg;
if (qp.error) {
oauthErrorMsg = "["+qp.error+"]: " +
(qp.error_description ? qp.error_description+ ". " : "no accessCode received from the server. ") +
(qp.error_uri ? "More info: "+qp.error_uri : "");
}
oauth2.errCb({
authId: oauth2.auth.name,
source: "auth",
level: "error",
message: oauthErrorMsg || "[Authorization failed]: no accessCode received from the server."
});
}
} else {
oauth2.callback({auth: oauth2.auth, token: qp, isValid: isValid, redirectUrl: redirectUrl});
}
window.close();
}
if (document.readyState !== 'loading') {
run();
} else {
document.addEventListener('DOMContentLoaded', function () {
run();
});
}
</script>
</body>
</html>

View File

@ -0,0 +1,20 @@
window.onload = function() {
//<editor-fold desc="Changeable Configuration Block">
// the following lines will be replaced by docker/configurator, when it runs in a docker-container
window.ui = SwaggerUIBundle({
urls: [{"url":"notes/v1/notes.swagger.json","name":"notes/v1/notes.swagger.json"},{"url":"health/v1/health.swagger.json","name":"health/v1/health.swagger.json"}],
dom_id: '#swagger-ui',
deepLinking: true,
presets: [
SwaggerUIBundle.presets.apis,
SwaggerUIStandalonePreset
],
plugins: [
SwaggerUIBundle.plugins.DownloadUrl
],
layout: "StandaloneLayout"
});
//</editor-fold>
};

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

12
go.mod
View File

@ -3,26 +3,30 @@ module github.com/sundowndev/grpc-api-example
go 1.20
require (
buf.build/gen/go/bufbuild/protovalidate/protocolbuffers/go v1.32.0-20240212200630-3014d81c3a48.1
github.com/bufbuild/protovalidate-go v0.5.2
github.com/gofrs/uuid v4.4.0+incompatible
github.com/grpc-ecosystem/grpc-gateway/v2 v2.19.1
github.com/stretchr/testify v1.8.4
google.golang.org/grpc v1.62.0
google.golang.org/grpc/cmd/protoc-gen-go-grpc v1.3.0
google.golang.org/protobuf v1.32.0
)
require (
buf.build/gen/go/bufbuild/protovalidate/protocolbuffers/go v1.32.0-20240212200630-3014d81c3a48.1 // indirect
github.com/antlr4-go/antlr/v4 v4.13.0 // indirect
github.com/bufbuild/protovalidate-go v0.5.2 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/google/cel-go v0.19.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/rogpeppe/go-internal v1.12.0 // indirect
github.com/stoewer/go-strcase v1.3.0 // indirect
golang.org/x/exp v0.0.0-20230905200255-921286631fa9 // indirect
golang.org/x/net v0.20.0 // indirect
golang.org/x/sys v0.16.0 // indirect
golang.org/x/text v0.14.0 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20240123012728-ef4313101c80 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240123012728-ef4313101c80 // indirect
google.golang.org/genproto v0.0.0-20240123012728-ef4313101c80 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20240125205218-1f4bbc51befe // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240125205218-1f4bbc51befe // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)

21
go.sum
View File

@ -7,6 +7,7 @@ github.com/bufbuild/protovalidate-go v0.5.2/go.mod h1:DWCNjFl/HwtBiHyN5/3lKA+0Mg
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/envoyproxy/protoc-gen-validate v1.0.4 h1:gVPz/FMfvh57HdSJQyvBtF00j8JU4zdyUgIUNhlgg0A=
github.com/gofrs/uuid v4.4.0+incompatible h1:3qXRTX8/NbyulANqlc0lchS1gqAVxRgsuW1YrTJupqA=
github.com/gofrs/uuid v4.4.0+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRxnplIgP/c0N/04lM=
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
@ -16,8 +17,14 @@ github.com/google/cel-go v0.19.0 h1:vVgaZoHPBDd1lXCYGQOh5A06L4EtuIfmqQ/qnSXSKiU=
github.com/google/cel-go v0.19.0/go.mod h1:kWcIzTsPX0zmQ+H3TirHstLLf9ep5QTsZBN9u4dOYLg=
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/grpc-ecosystem/grpc-gateway/v2 v2.19.1 h1:/c3QmbOGMGTOumP2iT/rCwB7b0QDGLKzqOmktBjT+Is=
github.com/grpc-ecosystem/grpc-gateway/v2 v2.19.1/go.mod h1:5SN9VR2LTsRFsrEC6FHgRbTWrTHu6tqPeKxEQv15giM=
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/rogpeppe/go-internal v1.12.0 h1:exVL4IDcn6na9z1rAb56Vxr+CgyK3nn3O+epU5NdKM8=
github.com/rogpeppe/go-internal v1.12.0/go.mod h1:E+RYuTGaKKdloAfM02xzb0FW3Paa99yedzYV+kq4uf4=
github.com/stoewer/go-strcase v1.3.0 h1:g0eASXYtp+yvN9fK8sH94oCIk0fau9uV1/ZdJ0AVEzs=
github.com/stoewer/go-strcase v1.3.0/go.mod h1:fAH5hQ5pehh+j3nZfvwdk2RgEgQjAoM8wodgtPmh1xo=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
@ -38,19 +45,21 @@ golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
google.golang.org/genproto v0.0.0-20240123012728-ef4313101c80 h1:KAeGQVN3M9nD0/bQXnr/ClcEMJ968gUXJQ9pwfSynuQ=
google.golang.org/genproto/googleapis/api v0.0.0-20240123012728-ef4313101c80 h1:Lj5rbfG876hIAYFjqiJnPHfhXbv+nzTWfm04Fg/XSVU=
google.golang.org/genproto/googleapis/api v0.0.0-20240123012728-ef4313101c80/go.mod h1:4jWUdICTdgc3Ibxmr8nAJiiLHwQBY0UI0XZcEMaFKaA=
google.golang.org/genproto/googleapis/rpc v0.0.0-20240123012728-ef4313101c80 h1:AjyfHzEPEFp/NpvfN5g+KDla3EMojjhRVZc1i7cj+oM=
google.golang.org/genproto/googleapis/rpc v0.0.0-20240123012728-ef4313101c80/go.mod h1:PAREbraiVEVGVdTZsVWjSbbTtSyGbAgIIvni8a8CD5s=
google.golang.org/genproto v0.0.0-20240123012728-ef4313101c80/go.mod h1:cc8bqMqtv9gMOr0zHg2Vzff5ULhhL2IXP4sbcn32Dro=
google.golang.org/genproto/googleapis/api v0.0.0-20240125205218-1f4bbc51befe h1:0poefMBYvYbs7g5UkjS6HcxBPaTRAmznle9jnxYoAI8=
google.golang.org/genproto/googleapis/api v0.0.0-20240125205218-1f4bbc51befe/go.mod h1:4jWUdICTdgc3Ibxmr8nAJiiLHwQBY0UI0XZcEMaFKaA=
google.golang.org/genproto/googleapis/rpc v0.0.0-20240125205218-1f4bbc51befe h1:bQnxqljG/wqi4NTXu2+DJ3n7APcEA882QZ1JvhQAq9o=
google.golang.org/genproto/googleapis/rpc v0.0.0-20240125205218-1f4bbc51befe/go.mod h1:PAREbraiVEVGVdTZsVWjSbbTtSyGbAgIIvni8a8CD5s=
google.golang.org/grpc v1.62.0 h1:HQKZ/fa1bXkX1oFOvSjmZEUL8wLSaZTjCcLAlmZRtdk=
google.golang.org/grpc v1.62.0/go.mod h1:IWTG0VlJLCh1SkC58F7np9ka9mx/WNkjl4PGJaiq+QE=
google.golang.org/grpc/cmd/protoc-gen-go-grpc v1.3.0 h1:rNBFJjBCOgVr9pWD7rs/knKL4FRTKgpZmsRfV214zcA=
google.golang.org/grpc/cmd/protoc-gen-go-grpc v1.3.0/go.mod h1:Dk1tviKTvMCz5tvh7t+fh94dhmQVHuCt2OzJB3CTW9Y=
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
google.golang.org/protobuf v1.32.0 h1:pPC6BG5ex8PDFnkbrGU3EixyhKcQ2aDuBS36lqK/C7I=
google.golang.org/protobuf v1.32.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

85
main.go
View File

@ -1,36 +1,114 @@
package main
import (
"context"
"errors"
"flag"
"fmt"
"github.com/grpc-ecosystem/grpc-gateway/v2/runtime"
"github.com/sundowndev/grpc-api-example/gen"
healthv1 "github.com/sundowndev/grpc-api-example/proto/health/v1"
notesv1 "github.com/sundowndev/grpc-api-example/proto/notes/v1"
"github.com/sundowndev/grpc-api-example/server"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"
"google.golang.org/grpc/grpclog"
"io"
"io/fs"
"mime"
"net"
"net/http"
"os"
"os/signal"
"strings"
"syscall"
)
var (
httpServerEndpoint = flag.String("http-server-endpoint", "localhost:8000", "HTTP server endpoint")
grpcServerEndpoint = flag.String("grpc-server-endpoint", "localhost:9090", "gRPC server endpoint")
)
func getOpenAPIHandler() (http.Handler, error) {
err := mime.AddExtensionType(".svg", "image/svg+xml")
if err != nil {
return nil, err
}
// Use subdirectory in embedded files
subFS, err := fs.Sub(gen.OpenAPI, "openapiv2")
if err != nil {
return nil, fmt.Errorf("couldn't create sub filesystem: %v", err)
}
return http.FileServer(http.FS(subFS)), nil
}
func httpServer(ctx context.Context, addr string) error {
// Register gRPC server endpoint
// Note: Make sure the gRPC server is running properly and accessible
mux := runtime.NewServeMux()
opts := []grpc.DialOption{
grpc.WithTransportCredentials(insecure.NewCredentials()), // TODO: Replace with your own certificate!
}
// Register services
err := notesv1.RegisterNotesServiceHandlerFromEndpoint(ctx, mux, *grpcServerEndpoint, opts)
if err != nil {
return err
}
err = healthv1.RegisterHealthServiceHandlerFromEndpoint(ctx, mux, *grpcServerEndpoint, opts)
if err != nil {
return err
}
oa, err := getOpenAPIHandler()
if err != nil {
return err
}
gwServer := &http.Server{
Addr: *httpServerEndpoint,
Handler: http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if strings.HasPrefix(r.URL.Path, "/api") {
mux.ServeHTTP(w, r)
return
}
oa.ServeHTTP(w, r)
}),
}
// Start HTTP server (and proxy calls to gRPC server endpoint)
return gwServer.ListenAndServe()
}
func main() {
flag.Parse()
// Adds gRPC internal logs. This is quite verbose, so adjust as desired!
log := grpclog.NewLoggerV2(os.Stdout, io.Discard, io.Discard)
grpclog.SetLoggerV2(log)
addr := "0.0.0.0:10000" // TODO: handle this with CLI flags
srv, err := server.NewServer(insecure.NewCredentials()) // TODO: Replace with your own certificate!
if err != nil {
log.Fatal("failed to initialize server: %v", err)
}
// Serve gRPC Server
log.Info("Serving gRPC on https://", addr)
log.Info("Serving gRPC on https://", *grpcServerEndpoint)
go func() {
if err := srv.Listen(addr); err != nil && !errors.Is(err, net.ErrClosed) {
if err := srv.Listen(*grpcServerEndpoint); err != nil && !errors.Is(err, net.ErrClosed) {
log.Fatalf("listen: %s\n", err)
}
}()
// Serve HTTP gateway
ctx, cancel := context.WithCancel(context.Background())
go func() {
if err := httpServer(ctx, *httpServerEndpoint); err != nil && !errors.Is(err, http.ErrServerClosed) {
log.Fatalf("http server: %s\n", err)
}
}()
// Wait for interrupt signal to gracefully shut down the server with
// a timeout of 5 seconds.
quit := make(chan os.Signal)
@ -40,6 +118,7 @@ func main() {
signal.Notify(quit, syscall.SIGINT, syscall.SIGTERM)
<-quit
cancel()
if err := srv.Close(); err != nil {
log.Fatal(err)
}

View File

@ -11,3 +11,8 @@ deps:
repository: googleapis
commit: 7e6f6e774e29406da95bd61cdcdbc8bc
digest: shake256:fe43dd2265ea0c07d76bd925eeba612667cf4c948d2ce53d6e367e1b4b3cb5fa69a51e6acb1a6a50d32f894f054a35e6c0406f6808a483f2752e10c866ffbf73
- remote: buf.build
owner: grpc-ecosystem
repository: grpc-gateway
commit: 3f42134f4c564983838425bc43c7a65f
digest: shake256:3d11d4c0fe5e05fda0131afefbce233940e27f0c31c5d4e385686aea58ccd30f72053f61af432fa83f1fc11cda57f5f18ca3da26a29064f73c5a0d076bba8d92

View File

@ -3,6 +3,7 @@ name: buf.build/sundowndev/grpc-api-example
deps:
- buf.build/googleapis/googleapis
- buf.build/bufbuild/protovalidate
- buf.build/grpc-ecosystem/grpc-gateway
lint:
use:
- DEFAULT

View File

@ -0,0 +1,231 @@
// Code generated by protoc-gen-go. DO NOT EDIT.
// versions:
// protoc-gen-go v1.32.0
// protoc (unknown)
// source: health/v1/health.proto
package healthv1
import (
_ "github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-openapiv2/options"
_ "google.golang.org/genproto/googleapis/api/annotations"
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 GetHealthRequest struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
}
func (x *GetHealthRequest) Reset() {
*x = GetHealthRequest{}
if protoimpl.UnsafeEnabled {
mi := &file_health_v1_health_proto_msgTypes[0]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
}
func (x *GetHealthRequest) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*GetHealthRequest) ProtoMessage() {}
func (x *GetHealthRequest) ProtoReflect() protoreflect.Message {
mi := &file_health_v1_health_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 GetHealthRequest.ProtoReflect.Descriptor instead.
func (*GetHealthRequest) Descriptor() ([]byte, []int) {
return file_health_v1_health_proto_rawDescGZIP(), []int{0}
}
type GetHealthResponse struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
Ok bool `protobuf:"varint,1,opt,name=ok,proto3" json:"ok,omitempty"`
}
func (x *GetHealthResponse) Reset() {
*x = GetHealthResponse{}
if protoimpl.UnsafeEnabled {
mi := &file_health_v1_health_proto_msgTypes[1]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
}
func (x *GetHealthResponse) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*GetHealthResponse) ProtoMessage() {}
func (x *GetHealthResponse) ProtoReflect() protoreflect.Message {
mi := &file_health_v1_health_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 GetHealthResponse.ProtoReflect.Descriptor instead.
func (*GetHealthResponse) Descriptor() ([]byte, []int) {
return file_health_v1_health_proto_rawDescGZIP(), []int{1}
}
func (x *GetHealthResponse) GetOk() bool {
if x != nil {
return x.Ok
}
return false
}
var File_health_v1_health_proto protoreflect.FileDescriptor
var file_health_v1_health_proto_rawDesc = []byte{
0x0a, 0x16, 0x68, 0x65, 0x61, 0x6c, 0x74, 0x68, 0x2f, 0x76, 0x31, 0x2f, 0x68, 0x65, 0x61, 0x6c,
0x74, 0x68, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x09, 0x68, 0x65, 0x61, 0x6c, 0x74, 0x68,
0x2e, 0x76, 0x31, 0x1a, 0x1c, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2f, 0x61, 0x70, 0x69, 0x2f,
0x61, 0x6e, 0x6e, 0x6f, 0x74, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x2e, 0x70, 0x72, 0x6f, 0x74,
0x6f, 0x1a, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x63, 0x2d, 0x67, 0x65, 0x6e, 0x2d, 0x6f, 0x70,
0x65, 0x6e, 0x61, 0x70, 0x69, 0x76, 0x32, 0x2f, 0x6f, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x2f,
0x61, 0x6e, 0x6e, 0x6f, 0x74, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x2e, 0x70, 0x72, 0x6f, 0x74,
0x6f, 0x22, 0x12, 0x0a, 0x10, 0x47, 0x65, 0x74, 0x48, 0x65, 0x61, 0x6c, 0x74, 0x68, 0x52, 0x65,
0x71, 0x75, 0x65, 0x73, 0x74, 0x22, 0x23, 0x0a, 0x11, 0x47, 0x65, 0x74, 0x48, 0x65, 0x61, 0x6c,
0x74, 0x68, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x0e, 0x0a, 0x02, 0x6f, 0x6b,
0x18, 0x01, 0x20, 0x01, 0x28, 0x08, 0x52, 0x02, 0x6f, 0x6b, 0x32, 0xb7, 0x01, 0x0a, 0x0d, 0x48,
0x65, 0x61, 0x6c, 0x74, 0x68, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0xa5, 0x01, 0x0a,
0x09, 0x47, 0x65, 0x74, 0x48, 0x65, 0x61, 0x6c, 0x74, 0x68, 0x12, 0x1b, 0x2e, 0x68, 0x65, 0x61,
0x6c, 0x74, 0x68, 0x2e, 0x76, 0x31, 0x2e, 0x47, 0x65, 0x74, 0x48, 0x65, 0x61, 0x6c, 0x74, 0x68,
0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1c, 0x2e, 0x68, 0x65, 0x61, 0x6c, 0x74, 0x68,
0x2e, 0x76, 0x31, 0x2e, 0x47, 0x65, 0x74, 0x48, 0x65, 0x61, 0x6c, 0x74, 0x68, 0x52, 0x65, 0x73,
0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x5d, 0x92, 0x41, 0x44, 0x0a, 0x0d, 0x48, 0x65, 0x61, 0x6c,
0x74, 0x68, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x11, 0x47, 0x65, 0x74, 0x20, 0x68,
0x65, 0x61, 0x6c, 0x74, 0x68, 0x20, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x1a, 0x20, 0x47, 0x65,
0x74, 0x20, 0x68, 0x65, 0x61, 0x6c, 0x74, 0x68, 0x20, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x20,
0x6f, 0x66, 0x20, 0x74, 0x68, 0x65, 0x20, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x2e, 0x82, 0xd3,
0xe4, 0x93, 0x02, 0x10, 0x12, 0x0e, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x76, 0x31, 0x2f, 0x68, 0x65,
0x61, 0x6c, 0x74, 0x68, 0x42, 0x87, 0x02, 0x92, 0x41, 0x62, 0x12, 0x05, 0x32, 0x03, 0x31, 0x2e,
0x30, 0x2a, 0x02, 0x01, 0x02, 0x72, 0x55, 0x0a, 0x23, 0x67, 0x52, 0x50, 0x43, 0x20, 0x61, 0x70,
0x70, 0x6c, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x65, 0x78, 0x61, 0x6d, 0x70, 0x6c,
0x65, 0x20, 0x72, 0x65, 0x70, 0x6f, 0x73, 0x69, 0x74, 0x6f, 0x72, 0x79, 0x12, 0x2e, 0x68, 0x74,
0x74, 0x70, 0x73, 0x3a, 0x2f, 0x2f, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d,
0x2f, 0x73, 0x75, 0x6e, 0x64, 0x6f, 0x77, 0x6e, 0x64, 0x65, 0x76, 0x2f, 0x67, 0x72, 0x70, 0x63,
0x2d, 0x61, 0x70, 0x69, 0x2d, 0x65, 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x0a, 0x0d, 0x63, 0x6f,
0x6d, 0x2e, 0x68, 0x65, 0x61, 0x6c, 0x74, 0x68, 0x2e, 0x76, 0x31, 0x42, 0x0b, 0x48, 0x65, 0x61,
0x6c, 0x74, 0x68, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x50, 0x01, 0x5a, 0x3f, 0x67, 0x69, 0x74, 0x68,
0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x73, 0x75, 0x6e, 0x64, 0x6f, 0x77, 0x6e, 0x64, 0x65,
0x76, 0x2f, 0x67, 0x72, 0x70, 0x63, 0x2d, 0x61, 0x70, 0x69, 0x2d, 0x65, 0x78, 0x61, 0x6d, 0x70,
0x6c, 0x65, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x68, 0x65, 0x61, 0x6c, 0x74, 0x68, 0x2f,
0x76, 0x31, 0x3b, 0x68, 0x65, 0x61, 0x6c, 0x74, 0x68, 0x76, 0x31, 0xa2, 0x02, 0x03, 0x48, 0x58,
0x58, 0xaa, 0x02, 0x09, 0x48, 0x65, 0x61, 0x6c, 0x74, 0x68, 0x2e, 0x56, 0x31, 0xca, 0x02, 0x09,
0x48, 0x65, 0x61, 0x6c, 0x74, 0x68, 0x5c, 0x56, 0x31, 0xe2, 0x02, 0x15, 0x48, 0x65, 0x61, 0x6c,
0x74, 0x68, 0x5c, 0x56, 0x31, 0x5c, 0x47, 0x50, 0x42, 0x4d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74,
0x61, 0xea, 0x02, 0x0a, 0x48, 0x65, 0x61, 0x6c, 0x74, 0x68, 0x3a, 0x3a, 0x56, 0x31, 0x62, 0x06,
0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
}
var (
file_health_v1_health_proto_rawDescOnce sync.Once
file_health_v1_health_proto_rawDescData = file_health_v1_health_proto_rawDesc
)
func file_health_v1_health_proto_rawDescGZIP() []byte {
file_health_v1_health_proto_rawDescOnce.Do(func() {
file_health_v1_health_proto_rawDescData = protoimpl.X.CompressGZIP(file_health_v1_health_proto_rawDescData)
})
return file_health_v1_health_proto_rawDescData
}
var file_health_v1_health_proto_msgTypes = make([]protoimpl.MessageInfo, 2)
var file_health_v1_health_proto_goTypes = []interface{}{
(*GetHealthRequest)(nil), // 0: health.v1.GetHealthRequest
(*GetHealthResponse)(nil), // 1: health.v1.GetHealthResponse
}
var file_health_v1_health_proto_depIdxs = []int32{
0, // 0: health.v1.HealthService.GetHealth:input_type -> health.v1.GetHealthRequest
1, // 1: health.v1.HealthService.GetHealth:output_type -> health.v1.GetHealthResponse
1, // [1:2] is the sub-list for method output_type
0, // [0:1] is the sub-list for method input_type
0, // [0:0] is the sub-list for extension type_name
0, // [0:0] is the sub-list for extension extendee
0, // [0:0] is the sub-list for field type_name
}
func init() { file_health_v1_health_proto_init() }
func file_health_v1_health_proto_init() {
if File_health_v1_health_proto != nil {
return
}
if !protoimpl.UnsafeEnabled {
file_health_v1_health_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*GetHealthRequest); i {
case 0:
return &v.state
case 1:
return &v.sizeCache
case 2:
return &v.unknownFields
default:
return nil
}
}
file_health_v1_health_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*GetHealthResponse); 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_health_v1_health_proto_rawDesc,
NumEnums: 0,
NumMessages: 2,
NumExtensions: 0,
NumServices: 1,
},
GoTypes: file_health_v1_health_proto_goTypes,
DependencyIndexes: file_health_v1_health_proto_depIdxs,
MessageInfos: file_health_v1_health_proto_msgTypes,
}.Build()
File_health_v1_health_proto = out.File
file_health_v1_health_proto_rawDesc = nil
file_health_v1_health_proto_goTypes = nil
file_health_v1_health_proto_depIdxs = nil
}

View File

@ -0,0 +1,155 @@
// Code generated by protoc-gen-grpc-gateway. DO NOT EDIT.
// source: health/v1/health.proto
/*
Package healthv1 is a reverse proxy.
It translates gRPC into RESTful JSON APIs.
*/
package healthv1
import (
"context"
"io"
"net/http"
"github.com/grpc-ecosystem/grpc-gateway/v2/runtime"
"github.com/grpc-ecosystem/grpc-gateway/v2/utilities"
"google.golang.org/grpc"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/grpclog"
"google.golang.org/grpc/metadata"
"google.golang.org/grpc/status"
"google.golang.org/protobuf/proto"
)
// Suppress "imported and not used" errors
var _ codes.Code
var _ io.Reader
var _ status.Status
var _ = runtime.String
var _ = utilities.NewDoubleArray
var _ = metadata.Join
func request_HealthService_GetHealth_0(ctx context.Context, marshaler runtime.Marshaler, client HealthServiceClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
var protoReq GetHealthRequest
var metadata runtime.ServerMetadata
msg, err := client.GetHealth(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD))
return msg, metadata, err
}
func local_request_HealthService_GetHealth_0(ctx context.Context, marshaler runtime.Marshaler, server HealthServiceServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
var protoReq GetHealthRequest
var metadata runtime.ServerMetadata
msg, err := server.GetHealth(ctx, &protoReq)
return msg, metadata, err
}
// RegisterHealthServiceHandlerServer registers the http handlers for service HealthService to "mux".
// UnaryRPC :call HealthServiceServer directly.
// StreamingRPC :currently unsupported pending https://github.com/grpc/grpc-go/issues/906.
// Note that using this registration option will cause many gRPC library features to stop working. Consider using RegisterHealthServiceHandlerFromEndpoint instead.
func RegisterHealthServiceHandlerServer(ctx context.Context, mux *runtime.ServeMux, server HealthServiceServer) error {
mux.Handle("GET", pattern_HealthService_GetHealth_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
ctx, cancel := context.WithCancel(req.Context())
defer cancel()
var stream runtime.ServerTransportStream
ctx = grpc.NewContextWithServerTransportStream(ctx, &stream)
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
var err error
var annotatedContext context.Context
annotatedContext, err = runtime.AnnotateIncomingContext(ctx, mux, req, "/health.v1.HealthService/GetHealth", runtime.WithHTTPPathPattern("/api/v1/health"))
if err != nil {
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
return
}
resp, md, err := local_request_HealthService_GetHealth_0(annotatedContext, inboundMarshaler, server, req, pathParams)
md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer())
annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md)
if err != nil {
runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err)
return
}
forward_HealthService_GetHealth_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
})
return nil
}
// RegisterHealthServiceHandlerFromEndpoint is same as RegisterHealthServiceHandler but
// automatically dials to "endpoint" and closes the connection when "ctx" gets done.
func RegisterHealthServiceHandlerFromEndpoint(ctx context.Context, mux *runtime.ServeMux, endpoint string, opts []grpc.DialOption) (err error) {
conn, err := grpc.DialContext(ctx, endpoint, opts...)
if err != nil {
return err
}
defer func() {
if err != nil {
if cerr := conn.Close(); cerr != nil {
grpclog.Infof("Failed to close conn to %s: %v", endpoint, cerr)
}
return
}
go func() {
<-ctx.Done()
if cerr := conn.Close(); cerr != nil {
grpclog.Infof("Failed to close conn to %s: %v", endpoint, cerr)
}
}()
}()
return RegisterHealthServiceHandler(ctx, mux, conn)
}
// RegisterHealthServiceHandler registers the http handlers for service HealthService to "mux".
// The handlers forward requests to the grpc endpoint over "conn".
func RegisterHealthServiceHandler(ctx context.Context, mux *runtime.ServeMux, conn *grpc.ClientConn) error {
return RegisterHealthServiceHandlerClient(ctx, mux, NewHealthServiceClient(conn))
}
// RegisterHealthServiceHandlerClient registers the http handlers for service HealthService
// to "mux". The handlers forward requests to the grpc endpoint over the given implementation of "HealthServiceClient".
// Note: the gRPC framework executes interceptors within the gRPC handler. If the passed in "HealthServiceClient"
// doesn't go through the normal gRPC flow (creating a gRPC client etc.) then it will be up to the passed in
// "HealthServiceClient" to call the correct interceptors.
func RegisterHealthServiceHandlerClient(ctx context.Context, mux *runtime.ServeMux, client HealthServiceClient) error {
mux.Handle("GET", pattern_HealthService_GetHealth_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
ctx, cancel := context.WithCancel(req.Context())
defer cancel()
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
var err error
var annotatedContext context.Context
annotatedContext, err = runtime.AnnotateContext(ctx, mux, req, "/health.v1.HealthService/GetHealth", runtime.WithHTTPPathPattern("/api/v1/health"))
if err != nil {
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
return
}
resp, md, err := request_HealthService_GetHealth_0(annotatedContext, inboundMarshaler, client, req, pathParams)
annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md)
if err != nil {
runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err)
return
}
forward_HealthService_GetHealth_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
})
return nil
}
var (
pattern_HealthService_GetHealth_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"api", "v1", "health"}, ""))
)
var (
forward_HealthService_GetHealth_0 = runtime.ForwardResponseMessage
)

View File

@ -0,0 +1,34 @@
syntax = "proto3";
package health.v1;
import "google/api/annotations.proto";
import "protoc-gen-openapiv2/options/annotations.proto";
option (grpc.gateway.protoc_gen_openapiv2.options.openapiv2_swagger) = {
info: {version: "1.0"};
external_docs: {
url: "https://github.com/sundowndev/grpc-api-example";
description: "gRPC application example repository";
}
schemes: [HTTP, HTTPS];
};
service HealthService {
rpc GetHealth(GetHealthRequest) returns (GetHealthResponse) {
option (google.api.http) = {
get:"/api/v1/health"
};
option (grpc.gateway.protoc_gen_openapiv2.options.openapiv2_operation) = {
summary: "Get health status"
description: "Get health status of the server."
tags: "HealthService"
};
};
}
message GetHealthRequest {}
message GetHealthResponse {
bool ok = 1;
}

View File

@ -0,0 +1,107 @@
// Code generated by protoc-gen-go-grpc. DO NOT EDIT.
// versions:
// - protoc-gen-go-grpc v1.3.0
// - protoc (unknown)
// source: health/v1/health.proto
package healthv1
import (
context "context"
grpc "google.golang.org/grpc"
codes "google.golang.org/grpc/codes"
status "google.golang.org/grpc/status"
)
// This is a compile-time assertion to ensure that this generated file
// is compatible with the grpc package it is being compiled against.
// Requires gRPC-Go v1.32.0 or later.
const _ = grpc.SupportPackageIsVersion7
const (
HealthService_GetHealth_FullMethodName = "/health.v1.HealthService/GetHealth"
)
// HealthServiceClient is the client API for HealthService service.
//
// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream.
type HealthServiceClient interface {
GetHealth(ctx context.Context, in *GetHealthRequest, opts ...grpc.CallOption) (*GetHealthResponse, error)
}
type healthServiceClient struct {
cc grpc.ClientConnInterface
}
func NewHealthServiceClient(cc grpc.ClientConnInterface) HealthServiceClient {
return &healthServiceClient{cc}
}
func (c *healthServiceClient) GetHealth(ctx context.Context, in *GetHealthRequest, opts ...grpc.CallOption) (*GetHealthResponse, error) {
out := new(GetHealthResponse)
err := c.cc.Invoke(ctx, HealthService_GetHealth_FullMethodName, in, out, opts...)
if err != nil {
return nil, err
}
return out, nil
}
// HealthServiceServer is the server API for HealthService service.
// All implementations should embed UnimplementedHealthServiceServer
// for forward compatibility
type HealthServiceServer interface {
GetHealth(context.Context, *GetHealthRequest) (*GetHealthResponse, error)
}
// UnimplementedHealthServiceServer should be embedded to have forward compatible implementations.
type UnimplementedHealthServiceServer struct {
}
func (UnimplementedHealthServiceServer) GetHealth(context.Context, *GetHealthRequest) (*GetHealthResponse, error) {
return nil, status.Errorf(codes.Unimplemented, "method GetHealth not implemented")
}
// UnsafeHealthServiceServer may be embedded to opt out of forward compatibility for this service.
// Use of this interface is not recommended, as added methods to HealthServiceServer will
// result in compilation errors.
type UnsafeHealthServiceServer interface {
mustEmbedUnimplementedHealthServiceServer()
}
func RegisterHealthServiceServer(s grpc.ServiceRegistrar, srv HealthServiceServer) {
s.RegisterService(&HealthService_ServiceDesc, srv)
}
func _HealthService_GetHealth_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(GetHealthRequest)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(HealthServiceServer).GetHealth(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: HealthService_GetHealth_FullMethodName,
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(HealthServiceServer).GetHealth(ctx, req.(*GetHealthRequest))
}
return interceptor(ctx, in, info, handler)
}
// HealthService_ServiceDesc is the grpc.ServiceDesc for HealthService service.
// It's only intended for direct use with grpc.RegisterService,
// and not to be introspected or modified (even as a copy)
var HealthService_ServiceDesc = grpc.ServiceDesc{
ServiceName: "health.v1.HealthService",
HandlerType: (*HealthServiceServer)(nil),
Methods: []grpc.MethodDesc{
{
MethodName: "GetHealth",
Handler: _HealthService_GetHealth_Handler,
},
},
Streams: []grpc.StreamDesc{},
Metadata: "health/v1/health.proto",
}

View File

@ -1,6 +1,6 @@
// Code generated by protoc-gen-go. DO NOT EDIT.
// versions:
// protoc-gen-go v1.30.0
// protoc-gen-go v1.32.0
// protoc (unknown)
// source: notes/v1/notes.proto
@ -8,6 +8,8 @@ package notesv1
import (
_ "buf.build/gen/go/bufbuild/protovalidate/protocolbuffers/go/buf/validate"
_ "github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-openapiv2/options"
_ "google.golang.org/genproto/googleapis/api/annotations"
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
reflect "reflect"
@ -21,185 +23,6 @@ const (
_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20)
)
type ListNotesRequest struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
}
func (x *ListNotesRequest) Reset() {
*x = ListNotesRequest{}
if protoimpl.UnsafeEnabled {
mi := &file_notes_v1_notes_proto_msgTypes[0]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
}
func (x *ListNotesRequest) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*ListNotesRequest) ProtoMessage() {}
func (x *ListNotesRequest) ProtoReflect() protoreflect.Message {
mi := &file_notes_v1_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 ListNotesRequest.ProtoReflect.Descriptor instead.
func (*ListNotesRequest) Descriptor() ([]byte, []int) {
return file_notes_v1_notes_proto_rawDescGZIP(), []int{0}
}
type ListNotesResponse struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
Note *Note `protobuf:"bytes,1,opt,name=note,proto3" json:"note,omitempty"`
}
func (x *ListNotesResponse) Reset() {
*x = ListNotesResponse{}
if protoimpl.UnsafeEnabled {
mi := &file_notes_v1_notes_proto_msgTypes[1]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
}
func (x *ListNotesResponse) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*ListNotesResponse) ProtoMessage() {}
func (x *ListNotesResponse) ProtoReflect() protoreflect.Message {
mi := &file_notes_v1_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 ListNotesResponse.ProtoReflect.Descriptor instead.
func (*ListNotesResponse) Descriptor() ([]byte, []int) {
return file_notes_v1_notes_proto_rawDescGZIP(), []int{1}
}
func (x *ListNotesResponse) GetNote() *Note {
if x != nil {
return x.Note
}
return nil
}
type AddNoteRequest struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
Title string `protobuf:"bytes,1,opt,name=title,proto3" json:"title,omitempty"`
}
func (x *AddNoteRequest) Reset() {
*x = AddNoteRequest{}
if protoimpl.UnsafeEnabled {
mi := &file_notes_v1_notes_proto_msgTypes[2]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
}
func (x *AddNoteRequest) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*AddNoteRequest) ProtoMessage() {}
func (x *AddNoteRequest) ProtoReflect() protoreflect.Message {
mi := &file_notes_v1_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 AddNoteRequest.ProtoReflect.Descriptor instead.
func (*AddNoteRequest) Descriptor() ([]byte, []int) {
return file_notes_v1_notes_proto_rawDescGZIP(), []int{2}
}
func (x *AddNoteRequest) GetTitle() string {
if x != nil {
return x.Title
}
return ""
}
type AddNoteResponse struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
Note *Note `protobuf:"bytes,1,opt,name=note,proto3" json:"note,omitempty"`
}
func (x *AddNoteResponse) Reset() {
*x = AddNoteResponse{}
if protoimpl.UnsafeEnabled {
mi := &file_notes_v1_notes_proto_msgTypes[3]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
}
func (x *AddNoteResponse) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*AddNoteResponse) ProtoMessage() {}
func (x *AddNoteResponse) ProtoReflect() protoreflect.Message {
mi := &file_notes_v1_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 AddNoteResponse.ProtoReflect.Descriptor instead.
func (*AddNoteResponse) Descriptor() ([]byte, []int) {
return file_notes_v1_notes_proto_rawDescGZIP(), []int{3}
}
func (x *AddNoteResponse) GetNote() *Note {
if x != nil {
return x.Note
}
return nil
}
type Note struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
@ -213,7 +36,7 @@ type Note struct {
func (x *Note) Reset() {
*x = Note{}
if protoimpl.UnsafeEnabled {
mi := &file_notes_v1_notes_proto_msgTypes[4]
mi := &file_notes_v1_notes_proto_msgTypes[0]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
@ -226,7 +49,7 @@ func (x *Note) String() string {
func (*Note) ProtoMessage() {}
func (x *Note) ProtoReflect() protoreflect.Message {
mi := &file_notes_v1_notes_proto_msgTypes[4]
mi := &file_notes_v1_notes_proto_msgTypes[0]
if protoimpl.UnsafeEnabled && x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
@ -239,7 +62,7 @@ func (x *Note) ProtoReflect() protoreflect.Message {
// Deprecated: Use Note.ProtoReflect.Descriptor instead.
func (*Note) Descriptor() ([]byte, []int) {
return file_notes_v1_notes_proto_rawDescGZIP(), []int{4}
return file_notes_v1_notes_proto_rawDescGZIP(), []int{0}
}
func (x *Note) GetId() string {
@ -263,50 +86,355 @@ func (x *Note) GetArchived() bool {
return false
}
type ListNotesRequest struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
}
func (x *ListNotesRequest) Reset() {
*x = ListNotesRequest{}
if protoimpl.UnsafeEnabled {
mi := &file_notes_v1_notes_proto_msgTypes[1]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
}
func (x *ListNotesRequest) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*ListNotesRequest) ProtoMessage() {}
func (x *ListNotesRequest) ProtoReflect() protoreflect.Message {
mi := &file_notes_v1_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 ListNotesRequest.ProtoReflect.Descriptor instead.
func (*ListNotesRequest) Descriptor() ([]byte, []int) {
return file_notes_v1_notes_proto_rawDescGZIP(), []int{1}
}
type ListNotesResponse struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
Note *Note `protobuf:"bytes,1,opt,name=note,proto3" json:"note,omitempty"`
}
func (x *ListNotesResponse) Reset() {
*x = ListNotesResponse{}
if protoimpl.UnsafeEnabled {
mi := &file_notes_v1_notes_proto_msgTypes[2]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
}
func (x *ListNotesResponse) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*ListNotesResponse) ProtoMessage() {}
func (x *ListNotesResponse) ProtoReflect() protoreflect.Message {
mi := &file_notes_v1_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 ListNotesResponse.ProtoReflect.Descriptor instead.
func (*ListNotesResponse) Descriptor() ([]byte, []int) {
return file_notes_v1_notes_proto_rawDescGZIP(), []int{2}
}
func (x *ListNotesResponse) GetNote() *Note {
if x != nil {
return x.Note
}
return nil
}
type AddNoteRequest struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
Title string `protobuf:"bytes,1,opt,name=title,proto3" json:"title,omitempty"`
}
func (x *AddNoteRequest) Reset() {
*x = AddNoteRequest{}
if protoimpl.UnsafeEnabled {
mi := &file_notes_v1_notes_proto_msgTypes[3]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
}
func (x *AddNoteRequest) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*AddNoteRequest) ProtoMessage() {}
func (x *AddNoteRequest) ProtoReflect() protoreflect.Message {
mi := &file_notes_v1_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 AddNoteRequest.ProtoReflect.Descriptor instead.
func (*AddNoteRequest) Descriptor() ([]byte, []int) {
return file_notes_v1_notes_proto_rawDescGZIP(), []int{3}
}
func (x *AddNoteRequest) GetTitle() string {
if x != nil {
return x.Title
}
return ""
}
type AddNoteResponse struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
Note *Note `protobuf:"bytes,1,opt,name=note,proto3" json:"note,omitempty"`
}
func (x *AddNoteResponse) Reset() {
*x = AddNoteResponse{}
if protoimpl.UnsafeEnabled {
mi := &file_notes_v1_notes_proto_msgTypes[4]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
}
func (x *AddNoteResponse) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*AddNoteResponse) ProtoMessage() {}
func (x *AddNoteResponse) ProtoReflect() protoreflect.Message {
mi := &file_notes_v1_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 AddNoteResponse.ProtoReflect.Descriptor instead.
func (*AddNoteResponse) Descriptor() ([]byte, []int) {
return file_notes_v1_notes_proto_rawDescGZIP(), []int{4}
}
func (x *AddNoteResponse) GetNote() *Note {
if x != nil {
return x.Note
}
return nil
}
type EditNoteRequest struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
Note *Note `protobuf:"bytes,1,opt,name=note,proto3" json:"note,omitempty"`
}
func (x *EditNoteRequest) Reset() {
*x = EditNoteRequest{}
if protoimpl.UnsafeEnabled {
mi := &file_notes_v1_notes_proto_msgTypes[5]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
}
func (x *EditNoteRequest) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*EditNoteRequest) ProtoMessage() {}
func (x *EditNoteRequest) ProtoReflect() protoreflect.Message {
mi := &file_notes_v1_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 EditNoteRequest.ProtoReflect.Descriptor instead.
func (*EditNoteRequest) Descriptor() ([]byte, []int) {
return file_notes_v1_notes_proto_rawDescGZIP(), []int{5}
}
func (x *EditNoteRequest) GetNote() *Note {
if x != nil {
return x.Note
}
return nil
}
type EditNoteResponse struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
Note *Note `protobuf:"bytes,1,opt,name=note,proto3" json:"note,omitempty"`
}
func (x *EditNoteResponse) Reset() {
*x = EditNoteResponse{}
if protoimpl.UnsafeEnabled {
mi := &file_notes_v1_notes_proto_msgTypes[6]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
}
func (x *EditNoteResponse) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*EditNoteResponse) ProtoMessage() {}
func (x *EditNoteResponse) ProtoReflect() protoreflect.Message {
mi := &file_notes_v1_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 EditNoteResponse.ProtoReflect.Descriptor instead.
func (*EditNoteResponse) Descriptor() ([]byte, []int) {
return file_notes_v1_notes_proto_rawDescGZIP(), []int{6}
}
func (x *EditNoteResponse) GetNote() *Note {
if x != nil {
return x.Note
}
return nil
}
var File_notes_v1_notes_proto protoreflect.FileDescriptor
var file_notes_v1_notes_proto_rawDesc = []byte{
0x0a, 0x14, 0x6e, 0x6f, 0x74, 0x65, 0x73, 0x2f, 0x76, 0x31, 0x2f, 0x6e, 0x6f, 0x74, 0x65, 0x73,
0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x08, 0x6e, 0x6f, 0x74, 0x65, 0x73, 0x2e, 0x76, 0x31,
0x1a, 0x1b, 0x62, 0x75, 0x66, 0x2f, 0x76, 0x61, 0x6c, 0x69, 0x64, 0x61, 0x74, 0x65, 0x2f, 0x76,
0x61, 0x6c, 0x69, 0x64, 0x61, 0x74, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x12, 0x0a,
0x10, 0x4c, 0x69, 0x73, 0x74, 0x4e, 0x6f, 0x74, 0x65, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73,
0x74, 0x22, 0x37, 0x0a, 0x11, 0x4c, 0x69, 0x73, 0x74, 0x4e, 0x6f, 0x74, 0x65, 0x73, 0x52, 0x65,
0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x22, 0x0a, 0x04, 0x6e, 0x6f, 0x74, 0x65, 0x18, 0x01,
0x20, 0x01, 0x28, 0x0b, 0x32, 0x0e, 0x2e, 0x6e, 0x6f, 0x74, 0x65, 0x73, 0x2e, 0x76, 0x31, 0x2e,
0x4e, 0x6f, 0x74, 0x65, 0x52, 0x04, 0x6e, 0x6f, 0x74, 0x65, 0x22, 0x26, 0x0a, 0x0e, 0x41, 0x64,
0x64, 0x4e, 0x6f, 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, 0x22, 0x35, 0x0a, 0x0f, 0x41, 0x64, 0x64, 0x4e, 0x6f, 0x74, 0x65, 0x52, 0x65, 0x73,
0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x22, 0x0a, 0x04, 0x6e, 0x6f, 0x74, 0x65, 0x18, 0x01, 0x20,
0x01, 0x28, 0x0b, 0x32, 0x0e, 0x2e, 0x6e, 0x6f, 0x74, 0x65, 0x73, 0x2e, 0x76, 0x31, 0x2e, 0x4e,
0x6f, 0x74, 0x65, 0x52, 0x04, 0x6e, 0x6f, 0x74, 0x65, 0x22, 0x5d, 0x0a, 0x04, 0x4e, 0x6f, 0x74,
0x65, 0x12, 0x18, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x42, 0x08, 0xba,
0x48, 0x05, 0x72, 0x03, 0xb0, 0x01, 0x01, 0x52, 0x02, 0x69, 0x64, 0x12, 0x1f, 0x0a, 0x05, 0x74,
0x69, 0x74, 0x6c, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x42, 0x09, 0xba, 0x48, 0x06, 0x72,
0x04, 0x10, 0x01, 0x18, 0x32, 0x52, 0x05, 0x74, 0x69, 0x74, 0x6c, 0x65, 0x12, 0x1a, 0x0a, 0x08,
0x61, 0x72, 0x63, 0x68, 0x69, 0x76, 0x65, 0x64, 0x18, 0x03, 0x20, 0x01, 0x28, 0x08, 0x52, 0x08,
0x61, 0x72, 0x63, 0x68, 0x69, 0x76, 0x65, 0x64, 0x32, 0x9a, 0x01, 0x0a, 0x0c, 0x4e, 0x6f, 0x74,
0x65, 0x73, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x48, 0x0a, 0x09, 0x4c, 0x69, 0x73,
0x74, 0x4e, 0x6f, 0x74, 0x65, 0x73, 0x12, 0x1a, 0x2e, 0x6e, 0x6f, 0x74, 0x65, 0x73, 0x2e, 0x76,
0x31, 0x2e, 0x4c, 0x69, 0x73, 0x74, 0x4e, 0x6f, 0x74, 0x65, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65,
0x73, 0x74, 0x1a, 0x1b, 0x2e, 0x6e, 0x6f, 0x74, 0x65, 0x73, 0x2e, 0x76, 0x31, 0x2e, 0x4c, 0x69,
0x73, 0x74, 0x4e, 0x6f, 0x74, 0x65, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22,
0x00, 0x30, 0x01, 0x12, 0x40, 0x0a, 0x07, 0x41, 0x64, 0x64, 0x4e, 0x6f, 0x74, 0x65, 0x12, 0x18,
0x2e, 0x6e, 0x6f, 0x74, 0x65, 0x73, 0x2e, 0x76, 0x31, 0x2e, 0x41, 0x64, 0x64, 0x4e, 0x6f, 0x74,
0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x19, 0x2e, 0x6e, 0x6f, 0x74, 0x65, 0x73,
0x2e, 0x76, 0x31, 0x2e, 0x41, 0x64, 0x64, 0x4e, 0x6f, 0x74, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f,
0x6e, 0x73, 0x65, 0x22, 0x00, 0x42, 0x9a, 0x01, 0x0a, 0x0c, 0x63, 0x6f, 0x6d, 0x2e, 0x6e, 0x6f,
0x74, 0x65, 0x73, 0x2e, 0x76, 0x31, 0x42, 0x0a, 0x4e, 0x6f, 0x74, 0x65, 0x73, 0x50, 0x72, 0x6f,
0x74, 0x6f, 0x50, 0x01, 0x5a, 0x3d, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d,
0x2f, 0x73, 0x75, 0x6e, 0x64, 0x6f, 0x77, 0x6e, 0x64, 0x65, 0x76, 0x2f, 0x67, 0x72, 0x70, 0x63,
0x2d, 0x61, 0x70, 0x69, 0x2d, 0x65, 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x2f, 0x70, 0x72, 0x6f,
0x74, 0x6f, 0x2f, 0x6e, 0x6f, 0x74, 0x65, 0x73, 0x2f, 0x76, 0x31, 0x3b, 0x6e, 0x6f, 0x74, 0x65,
0x73, 0x76, 0x31, 0xa2, 0x02, 0x03, 0x4e, 0x58, 0x58, 0xaa, 0x02, 0x08, 0x4e, 0x6f, 0x74, 0x65,
0x73, 0x2e, 0x56, 0x31, 0xca, 0x02, 0x08, 0x4e, 0x6f, 0x74, 0x65, 0x73, 0x5c, 0x56, 0x31, 0xe2,
0x02, 0x14, 0x4e, 0x6f, 0x74, 0x65, 0x73, 0x5c, 0x56, 0x31, 0x5c, 0x47, 0x50, 0x42, 0x4d, 0x65,
0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0xea, 0x02, 0x09, 0x4e, 0x6f, 0x74, 0x65, 0x73, 0x3a, 0x3a,
0x56, 0x31, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
0x61, 0x6c, 0x69, 0x64, 0x61, 0x74, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x1c, 0x67,
0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x61, 0x6e, 0x6e, 0x6f, 0x74, 0x61,
0x74, 0x69, 0x6f, 0x6e, 0x73, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x2e, 0x70, 0x72, 0x6f,
0x74, 0x6f, 0x63, 0x2d, 0x67, 0x65, 0x6e, 0x2d, 0x6f, 0x70, 0x65, 0x6e, 0x61, 0x70, 0x69, 0x76,
0x32, 0x2f, 0x6f, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x2f, 0x61, 0x6e, 0x6e, 0x6f, 0x74, 0x61,
0x74, 0x69, 0x6f, 0x6e, 0x73, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x5d, 0x0a, 0x04, 0x4e,
0x6f, 0x74, 0x65, 0x12, 0x18, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x42,
0x08, 0xba, 0x48, 0x05, 0x72, 0x03, 0xb0, 0x01, 0x01, 0x52, 0x02, 0x69, 0x64, 0x12, 0x1f, 0x0a,
0x05, 0x74, 0x69, 0x74, 0x6c, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x42, 0x09, 0xba, 0x48,
0x06, 0x72, 0x04, 0x10, 0x01, 0x18, 0x32, 0x52, 0x05, 0x74, 0x69, 0x74, 0x6c, 0x65, 0x12, 0x1a,
0x0a, 0x08, 0x61, 0x72, 0x63, 0x68, 0x69, 0x76, 0x65, 0x64, 0x18, 0x03, 0x20, 0x01, 0x28, 0x08,
0x52, 0x08, 0x61, 0x72, 0x63, 0x68, 0x69, 0x76, 0x65, 0x64, 0x22, 0x12, 0x0a, 0x10, 0x4c, 0x69,
0x73, 0x74, 0x4e, 0x6f, 0x74, 0x65, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x22, 0x37,
0x0a, 0x11, 0x4c, 0x69, 0x73, 0x74, 0x4e, 0x6f, 0x74, 0x65, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f,
0x6e, 0x73, 0x65, 0x12, 0x22, 0x0a, 0x04, 0x6e, 0x6f, 0x74, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28,
0x0b, 0x32, 0x0e, 0x2e, 0x6e, 0x6f, 0x74, 0x65, 0x73, 0x2e, 0x76, 0x31, 0x2e, 0x4e, 0x6f, 0x74,
0x65, 0x52, 0x04, 0x6e, 0x6f, 0x74, 0x65, 0x22, 0x26, 0x0a, 0x0e, 0x41, 0x64, 0x64, 0x4e, 0x6f,
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, 0x22,
0x35, 0x0a, 0x0f, 0x41, 0x64, 0x64, 0x4e, 0x6f, 0x74, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e,
0x73, 0x65, 0x12, 0x22, 0x0a, 0x04, 0x6e, 0x6f, 0x74, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b,
0x32, 0x0e, 0x2e, 0x6e, 0x6f, 0x74, 0x65, 0x73, 0x2e, 0x76, 0x31, 0x2e, 0x4e, 0x6f, 0x74, 0x65,
0x52, 0x04, 0x6e, 0x6f, 0x74, 0x65, 0x22, 0x35, 0x0a, 0x0f, 0x45, 0x64, 0x69, 0x74, 0x4e, 0x6f,
0x74, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x22, 0x0a, 0x04, 0x6e, 0x6f, 0x74,
0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0e, 0x2e, 0x6e, 0x6f, 0x74, 0x65, 0x73, 0x2e,
0x76, 0x31, 0x2e, 0x4e, 0x6f, 0x74, 0x65, 0x52, 0x04, 0x6e, 0x6f, 0x74, 0x65, 0x22, 0x36, 0x0a,
0x10, 0x45, 0x64, 0x69, 0x74, 0x4e, 0x6f, 0x74, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73,
0x65, 0x12, 0x22, 0x0a, 0x04, 0x6e, 0x6f, 0x74, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32,
0x0e, 0x2e, 0x6e, 0x6f, 0x74, 0x65, 0x73, 0x2e, 0x76, 0x31, 0x2e, 0x4e, 0x6f, 0x74, 0x65, 0x52,
0x04, 0x6e, 0x6f, 0x74, 0x65, 0x32, 0xfb, 0x02, 0x0a, 0x0c, 0x4e, 0x6f, 0x74, 0x65, 0x73, 0x53,
0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x48, 0x0a, 0x09, 0x4c, 0x69, 0x73, 0x74, 0x4e, 0x6f,
0x74, 0x65, 0x73, 0x12, 0x1a, 0x2e, 0x6e, 0x6f, 0x74, 0x65, 0x73, 0x2e, 0x76, 0x31, 0x2e, 0x4c,
0x69, 0x73, 0x74, 0x4e, 0x6f, 0x74, 0x65, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a,
0x1b, 0x2e, 0x6e, 0x6f, 0x74, 0x65, 0x73, 0x2e, 0x76, 0x31, 0x2e, 0x4c, 0x69, 0x73, 0x74, 0x4e,
0x6f, 0x74, 0x65, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x30, 0x01,
0x12, 0x84, 0x01, 0x0a, 0x07, 0x41, 0x64, 0x64, 0x4e, 0x6f, 0x74, 0x65, 0x12, 0x18, 0x2e, 0x6e,
0x6f, 0x74, 0x65, 0x73, 0x2e, 0x76, 0x31, 0x2e, 0x41, 0x64, 0x64, 0x4e, 0x6f, 0x74, 0x65, 0x52,
0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x19, 0x2e, 0x6e, 0x6f, 0x74, 0x65, 0x73, 0x2e, 0x76,
0x31, 0x2e, 0x41, 0x64, 0x64, 0x4e, 0x6f, 0x74, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73,
0x65, 0x22, 0x44, 0x92, 0x41, 0x29, 0x0a, 0x0c, 0x4e, 0x6f, 0x74, 0x65, 0x73, 0x53, 0x65, 0x72,
0x76, 0x69, 0x63, 0x65, 0x12, 0x08, 0x41, 0x64, 0x64, 0x20, 0x6e, 0x6f, 0x74, 0x65, 0x1a, 0x0f,
0x41, 0x64, 0x64, 0x20, 0x61, 0x20, 0x6e, 0x65, 0x77, 0x20, 0x6e, 0x6f, 0x74, 0x65, 0x2e, 0x82,
0xd3, 0xe4, 0x93, 0x02, 0x12, 0x3a, 0x01, 0x2a, 0x22, 0x0d, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x76,
0x31, 0x2f, 0x6e, 0x6f, 0x74, 0x65, 0x73, 0x12, 0x99, 0x01, 0x0a, 0x08, 0x45, 0x64, 0x69, 0x74,
0x4e, 0x6f, 0x74, 0x65, 0x12, 0x19, 0x2e, 0x6e, 0x6f, 0x74, 0x65, 0x73, 0x2e, 0x76, 0x31, 0x2e,
0x45, 0x64, 0x69, 0x74, 0x4e, 0x6f, 0x74, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a,
0x1a, 0x2e, 0x6e, 0x6f, 0x74, 0x65, 0x73, 0x2e, 0x76, 0x31, 0x2e, 0x45, 0x64, 0x69, 0x74, 0x4e,
0x6f, 0x74, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x56, 0x92, 0x41, 0x31,
0x0a, 0x0c, 0x4e, 0x6f, 0x74, 0x65, 0x73, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x09,
0x45, 0x64, 0x69, 0x74, 0x20, 0x6e, 0x6f, 0x74, 0x65, 0x1a, 0x16, 0x45, 0x64, 0x69, 0x74, 0x20,
0x61, 0x6e, 0x20, 0x65, 0x78, 0x69, 0x73, 0x74, 0x69, 0x6e, 0x67, 0x20, 0x6e, 0x6f, 0x74, 0x65,
0x2e, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x1c, 0x3a, 0x01, 0x2a, 0x32, 0x17, 0x2f, 0x61, 0x70, 0x69,
0x2f, 0x76, 0x31, 0x2f, 0x6e, 0x6f, 0x74, 0x65, 0x73, 0x2f, 0x7b, 0x6e, 0x6f, 0x74, 0x65, 0x2e,
0x69, 0x64, 0x7d, 0x42, 0xff, 0x01, 0x92, 0x41, 0x62, 0x12, 0x05, 0x32, 0x03, 0x31, 0x2e, 0x30,
0x2a, 0x02, 0x01, 0x02, 0x72, 0x55, 0x0a, 0x23, 0x67, 0x52, 0x50, 0x43, 0x20, 0x61, 0x70, 0x70,
0x6c, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x65, 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65,
0x20, 0x72, 0x65, 0x70, 0x6f, 0x73, 0x69, 0x74, 0x6f, 0x72, 0x79, 0x12, 0x2e, 0x68, 0x74, 0x74,
0x70, 0x73, 0x3a, 0x2f, 0x2f, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f,
0x73, 0x75, 0x6e, 0x64, 0x6f, 0x77, 0x6e, 0x64, 0x65, 0x76, 0x2f, 0x67, 0x72, 0x70, 0x63, 0x2d,
0x61, 0x70, 0x69, 0x2d, 0x65, 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x0a, 0x0c, 0x63, 0x6f, 0x6d,
0x2e, 0x6e, 0x6f, 0x74, 0x65, 0x73, 0x2e, 0x76, 0x31, 0x42, 0x0a, 0x4e, 0x6f, 0x74, 0x65, 0x73,
0x50, 0x72, 0x6f, 0x74, 0x6f, 0x50, 0x01, 0x5a, 0x3d, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e,
0x63, 0x6f, 0x6d, 0x2f, 0x73, 0x75, 0x6e, 0x64, 0x6f, 0x77, 0x6e, 0x64, 0x65, 0x76, 0x2f, 0x67,
0x72, 0x70, 0x63, 0x2d, 0x61, 0x70, 0x69, 0x2d, 0x65, 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x2f,
0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x6e, 0x6f, 0x74, 0x65, 0x73, 0x2f, 0x76, 0x31, 0x3b, 0x6e,
0x6f, 0x74, 0x65, 0x73, 0x76, 0x31, 0xa2, 0x02, 0x03, 0x4e, 0x58, 0x58, 0xaa, 0x02, 0x08, 0x4e,
0x6f, 0x74, 0x65, 0x73, 0x2e, 0x56, 0x31, 0xca, 0x02, 0x08, 0x4e, 0x6f, 0x74, 0x65, 0x73, 0x5c,
0x56, 0x31, 0xe2, 0x02, 0x14, 0x4e, 0x6f, 0x74, 0x65, 0x73, 0x5c, 0x56, 0x31, 0x5c, 0x47, 0x50,
0x42, 0x4d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0xea, 0x02, 0x09, 0x4e, 0x6f, 0x74, 0x65,
0x73, 0x3a, 0x3a, 0x56, 0x31, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
}
var (
@ -321,26 +449,32 @@ func file_notes_v1_notes_proto_rawDescGZIP() []byte {
return file_notes_v1_notes_proto_rawDescData
}
var file_notes_v1_notes_proto_msgTypes = make([]protoimpl.MessageInfo, 5)
var file_notes_v1_notes_proto_msgTypes = make([]protoimpl.MessageInfo, 7)
var file_notes_v1_notes_proto_goTypes = []interface{}{
(*ListNotesRequest)(nil), // 0: notes.v1.ListNotesRequest
(*ListNotesResponse)(nil), // 1: notes.v1.ListNotesResponse
(*AddNoteRequest)(nil), // 2: notes.v1.AddNoteRequest
(*AddNoteResponse)(nil), // 3: notes.v1.AddNoteResponse
(*Note)(nil), // 4: notes.v1.Note
(*Note)(nil), // 0: notes.v1.Note
(*ListNotesRequest)(nil), // 1: notes.v1.ListNotesRequest
(*ListNotesResponse)(nil), // 2: notes.v1.ListNotesResponse
(*AddNoteRequest)(nil), // 3: notes.v1.AddNoteRequest
(*AddNoteResponse)(nil), // 4: notes.v1.AddNoteResponse
(*EditNoteRequest)(nil), // 5: notes.v1.EditNoteRequest
(*EditNoteResponse)(nil), // 6: notes.v1.EditNoteResponse
}
var file_notes_v1_notes_proto_depIdxs = []int32{
4, // 0: notes.v1.ListNotesResponse.note:type_name -> notes.v1.Note
4, // 1: notes.v1.AddNoteResponse.note:type_name -> notes.v1.Note
0, // 2: notes.v1.NotesService.ListNotes:input_type -> notes.v1.ListNotesRequest
2, // 3: notes.v1.NotesService.AddNote:input_type -> notes.v1.AddNoteRequest
1, // 4: notes.v1.NotesService.ListNotes:output_type -> notes.v1.ListNotesResponse
3, // 5: notes.v1.NotesService.AddNote:output_type -> notes.v1.AddNoteResponse
4, // [4:6] is the sub-list for method output_type
2, // [2:4] is the sub-list for method input_type
2, // [2:2] is the sub-list for extension type_name
2, // [2:2] is the sub-list for extension extendee
0, // [0:2] is the sub-list for field type_name
0, // 0: notes.v1.ListNotesResponse.note:type_name -> notes.v1.Note
0, // 1: notes.v1.AddNoteResponse.note:type_name -> notes.v1.Note
0, // 2: notes.v1.EditNoteRequest.note:type_name -> notes.v1.Note
0, // 3: notes.v1.EditNoteResponse.note:type_name -> notes.v1.Note
1, // 4: notes.v1.NotesService.ListNotes:input_type -> notes.v1.ListNotesRequest
3, // 5: notes.v1.NotesService.AddNote:input_type -> notes.v1.AddNoteRequest
5, // 6: notes.v1.NotesService.EditNote:input_type -> notes.v1.EditNoteRequest
2, // 7: notes.v1.NotesService.ListNotes:output_type -> notes.v1.ListNotesResponse
4, // 8: notes.v1.NotesService.AddNote:output_type -> notes.v1.AddNoteResponse
6, // 9: notes.v1.NotesService.EditNote:output_type -> notes.v1.EditNoteResponse
7, // [7:10] is the sub-list for method output_type
4, // [4:7] is the sub-list for method input_type
4, // [4:4] is the sub-list for extension type_name
4, // [4:4] is the sub-list for extension extendee
0, // [0:4] is the sub-list for field type_name
}
func init() { file_notes_v1_notes_proto_init() }
@ -350,7 +484,7 @@ func file_notes_v1_notes_proto_init() {
}
if !protoimpl.UnsafeEnabled {
file_notes_v1_notes_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*ListNotesRequest); i {
switch v := v.(*Note); i {
case 0:
return &v.state
case 1:
@ -362,7 +496,7 @@ func file_notes_v1_notes_proto_init() {
}
}
file_notes_v1_notes_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*ListNotesResponse); i {
switch v := v.(*ListNotesRequest); i {
case 0:
return &v.state
case 1:
@ -374,7 +508,7 @@ func file_notes_v1_notes_proto_init() {
}
}
file_notes_v1_notes_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*AddNoteRequest); i {
switch v := v.(*ListNotesResponse); i {
case 0:
return &v.state
case 1:
@ -386,7 +520,7 @@ func file_notes_v1_notes_proto_init() {
}
}
file_notes_v1_notes_proto_msgTypes[3].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*AddNoteResponse); i {
switch v := v.(*AddNoteRequest); i {
case 0:
return &v.state
case 1:
@ -398,7 +532,31 @@ func file_notes_v1_notes_proto_init() {
}
}
file_notes_v1_notes_proto_msgTypes[4].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*Note); i {
switch v := v.(*AddNoteResponse); i {
case 0:
return &v.state
case 1:
return &v.sizeCache
case 2:
return &v.unknownFields
default:
return nil
}
}
file_notes_v1_notes_proto_msgTypes[5].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*EditNoteRequest); i {
case 0:
return &v.state
case 1:
return &v.sizeCache
case 2:
return &v.unknownFields
default:
return nil
}
}
file_notes_v1_notes_proto_msgTypes[6].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*EditNoteResponse); i {
case 0:
return &v.state
case 1:
@ -416,7 +574,7 @@ func file_notes_v1_notes_proto_init() {
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: file_notes_v1_notes_proto_rawDesc,
NumEnums: 0,
NumMessages: 5,
NumMessages: 7,
NumExtensions: 0,
NumServices: 1,
},

View File

@ -0,0 +1,274 @@
// Code generated by protoc-gen-grpc-gateway. DO NOT EDIT.
// source: notes/v1/notes.proto
/*
Package notesv1 is a reverse proxy.
It translates gRPC into RESTful JSON APIs.
*/
package notesv1
import (
"context"
"io"
"net/http"
"github.com/grpc-ecosystem/grpc-gateway/v2/runtime"
"github.com/grpc-ecosystem/grpc-gateway/v2/utilities"
"google.golang.org/grpc"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/grpclog"
"google.golang.org/grpc/metadata"
"google.golang.org/grpc/status"
"google.golang.org/protobuf/proto"
)
// Suppress "imported and not used" errors
var _ codes.Code
var _ io.Reader
var _ status.Status
var _ = runtime.String
var _ = utilities.NewDoubleArray
var _ = metadata.Join
func request_NotesService_AddNote_0(ctx context.Context, marshaler runtime.Marshaler, client NotesServiceClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
var protoReq AddNoteRequest
var metadata runtime.ServerMetadata
if err := marshaler.NewDecoder(req.Body).Decode(&protoReq); err != nil && err != io.EOF {
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
}
msg, err := client.AddNote(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD))
return msg, metadata, err
}
func local_request_NotesService_AddNote_0(ctx context.Context, marshaler runtime.Marshaler, server NotesServiceServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
var protoReq AddNoteRequest
var metadata runtime.ServerMetadata
if err := marshaler.NewDecoder(req.Body).Decode(&protoReq); err != nil && err != io.EOF {
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
}
msg, err := server.AddNote(ctx, &protoReq)
return msg, metadata, err
}
func request_NotesService_EditNote_0(ctx context.Context, marshaler runtime.Marshaler, client NotesServiceClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
var protoReq EditNoteRequest
var metadata runtime.ServerMetadata
if err := marshaler.NewDecoder(req.Body).Decode(&protoReq); err != nil && err != io.EOF {
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
}
var (
val string
ok bool
err error
_ = err
)
val, ok = pathParams["note.id"]
if !ok {
return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "note.id")
}
err = runtime.PopulateFieldFromPath(&protoReq, "note.id", val)
if err != nil {
return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "note.id", err)
}
msg, err := client.EditNote(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD))
return msg, metadata, err
}
func local_request_NotesService_EditNote_0(ctx context.Context, marshaler runtime.Marshaler, server NotesServiceServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
var protoReq EditNoteRequest
var metadata runtime.ServerMetadata
if err := marshaler.NewDecoder(req.Body).Decode(&protoReq); err != nil && err != io.EOF {
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
}
var (
val string
ok bool
err error
_ = err
)
val, ok = pathParams["note.id"]
if !ok {
return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "note.id")
}
err = runtime.PopulateFieldFromPath(&protoReq, "note.id", val)
if err != nil {
return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "note.id", err)
}
msg, err := server.EditNote(ctx, &protoReq)
return msg, metadata, err
}
// RegisterNotesServiceHandlerServer registers the http handlers for service NotesService to "mux".
// UnaryRPC :call NotesServiceServer directly.
// StreamingRPC :currently unsupported pending https://github.com/grpc/grpc-go/issues/906.
// Note that using this registration option will cause many gRPC library features to stop working. Consider using RegisterNotesServiceHandlerFromEndpoint instead.
func RegisterNotesServiceHandlerServer(ctx context.Context, mux *runtime.ServeMux, server NotesServiceServer) error {
mux.Handle("POST", pattern_NotesService_AddNote_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
ctx, cancel := context.WithCancel(req.Context())
defer cancel()
var stream runtime.ServerTransportStream
ctx = grpc.NewContextWithServerTransportStream(ctx, &stream)
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
var err error
var annotatedContext context.Context
annotatedContext, err = runtime.AnnotateIncomingContext(ctx, mux, req, "/notes.v1.NotesService/AddNote", runtime.WithHTTPPathPattern("/api/v1/notes"))
if err != nil {
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
return
}
resp, md, err := local_request_NotesService_AddNote_0(annotatedContext, inboundMarshaler, server, req, pathParams)
md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer())
annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md)
if err != nil {
runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err)
return
}
forward_NotesService_AddNote_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
})
mux.Handle("PATCH", pattern_NotesService_EditNote_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
ctx, cancel := context.WithCancel(req.Context())
defer cancel()
var stream runtime.ServerTransportStream
ctx = grpc.NewContextWithServerTransportStream(ctx, &stream)
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
var err error
var annotatedContext context.Context
annotatedContext, err = runtime.AnnotateIncomingContext(ctx, mux, req, "/notes.v1.NotesService/EditNote", runtime.WithHTTPPathPattern("/api/v1/notes/{note.id}"))
if err != nil {
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
return
}
resp, md, err := local_request_NotesService_EditNote_0(annotatedContext, inboundMarshaler, server, req, pathParams)
md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer())
annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md)
if err != nil {
runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err)
return
}
forward_NotesService_EditNote_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
})
return nil
}
// RegisterNotesServiceHandlerFromEndpoint is same as RegisterNotesServiceHandler but
// automatically dials to "endpoint" and closes the connection when "ctx" gets done.
func RegisterNotesServiceHandlerFromEndpoint(ctx context.Context, mux *runtime.ServeMux, endpoint string, opts []grpc.DialOption) (err error) {
conn, err := grpc.DialContext(ctx, endpoint, opts...)
if err != nil {
return err
}
defer func() {
if err != nil {
if cerr := conn.Close(); cerr != nil {
grpclog.Infof("Failed to close conn to %s: %v", endpoint, cerr)
}
return
}
go func() {
<-ctx.Done()
if cerr := conn.Close(); cerr != nil {
grpclog.Infof("Failed to close conn to %s: %v", endpoint, cerr)
}
}()
}()
return RegisterNotesServiceHandler(ctx, mux, conn)
}
// RegisterNotesServiceHandler registers the http handlers for service NotesService to "mux".
// The handlers forward requests to the grpc endpoint over "conn".
func RegisterNotesServiceHandler(ctx context.Context, mux *runtime.ServeMux, conn *grpc.ClientConn) error {
return RegisterNotesServiceHandlerClient(ctx, mux, NewNotesServiceClient(conn))
}
// RegisterNotesServiceHandlerClient registers the http handlers for service NotesService
// to "mux". The handlers forward requests to the grpc endpoint over the given implementation of "NotesServiceClient".
// Note: the gRPC framework executes interceptors within the gRPC handler. If the passed in "NotesServiceClient"
// doesn't go through the normal gRPC flow (creating a gRPC client etc.) then it will be up to the passed in
// "NotesServiceClient" to call the correct interceptors.
func RegisterNotesServiceHandlerClient(ctx context.Context, mux *runtime.ServeMux, client NotesServiceClient) error {
mux.Handle("POST", pattern_NotesService_AddNote_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
ctx, cancel := context.WithCancel(req.Context())
defer cancel()
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
var err error
var annotatedContext context.Context
annotatedContext, err = runtime.AnnotateContext(ctx, mux, req, "/notes.v1.NotesService/AddNote", runtime.WithHTTPPathPattern("/api/v1/notes"))
if err != nil {
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
return
}
resp, md, err := request_NotesService_AddNote_0(annotatedContext, inboundMarshaler, client, req, pathParams)
annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md)
if err != nil {
runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err)
return
}
forward_NotesService_AddNote_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
})
mux.Handle("PATCH", pattern_NotesService_EditNote_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
ctx, cancel := context.WithCancel(req.Context())
defer cancel()
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
var err error
var annotatedContext context.Context
annotatedContext, err = runtime.AnnotateContext(ctx, mux, req, "/notes.v1.NotesService/EditNote", runtime.WithHTTPPathPattern("/api/v1/notes/{note.id}"))
if err != nil {
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
return
}
resp, md, err := request_NotesService_EditNote_0(annotatedContext, inboundMarshaler, client, req, pathParams)
annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md)
if err != nil {
runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err)
return
}
forward_NotesService_EditNote_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
})
return nil
}
var (
pattern_NotesService_AddNote_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"api", "v1", "notes"}, ""))
pattern_NotesService_EditNote_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 1, 0, 4, 1, 5, 3}, []string{"api", "v1", "notes", "note.id"}, ""))
)
var (
forward_NotesService_AddNote_0 = runtime.ForwardResponseMessage
forward_NotesService_EditNote_0 = runtime.ForwardResponseMessage
)

View File

@ -3,11 +3,49 @@ syntax = "proto3";
package notes.v1;
import "buf/validate/validate.proto";
import "google/api/annotations.proto";
import "protoc-gen-openapiv2/options/annotations.proto";
option (grpc.gateway.protoc_gen_openapiv2.options.openapiv2_swagger) = {
info: {version: "1.0"};
external_docs: {
url: "https://github.com/sundowndev/grpc-api-example";
description: "gRPC application example repository";
}
schemes: [HTTP, HTTPS];
};
service NotesService {
rpc ListNotes(ListNotesRequest) returns (stream ListNotesResponse) {};
rpc AddNote(AddNoteRequest) returns (AddNoteResponse) {};
// rpc ArchiveNote(ArchiveNoteRequest) returns (ArchiveNoteResponse) {};
rpc AddNote(AddNoteRequest) returns (AddNoteResponse) {
option (google.api.http) = {
post:"/api/v1/notes"
body: "*"
};
option (grpc.gateway.protoc_gen_openapiv2.options.openapiv2_operation) = {
summary: "Add note"
description: "Add a new note."
tags: "NotesService"
};
};
rpc EditNote(EditNoteRequest) returns (EditNoteResponse) {
option (google.api.http) = {
patch:"/api/v1/notes/{note.id}"
body: "*"
};
option (grpc.gateway.protoc_gen_openapiv2.options.openapiv2_operation) = {
summary: "Edit note"
description: "Edit an existing note."
tags: "NotesService"
};
};
// rpc GetNote(GetNoteRequest) returns (GetNoteResponse) {};
}
message Note {
string id = 1 [(buf.validate.field).string.uuid = true];
string title = 2 [(buf.validate.field).string.min_len = 1, (buf.validate.field).string.max_len = 50];
bool archived = 3;
}
message ListNotesRequest {}
@ -24,8 +62,10 @@ message AddNoteResponse {
Note note = 1;
}
message Note {
string id = 1 [(buf.validate.field).string.uuid = true];
string title = 2 [(buf.validate.field).string.min_len = 1, (buf.validate.field).string.max_len = 50];
bool archived = 3;
message EditNoteRequest {
Note note = 1;
}
message EditNoteResponse {
Note note = 1;
}

View File

@ -21,6 +21,7 @@ const _ = grpc.SupportPackageIsVersion7
const (
NotesService_ListNotes_FullMethodName = "/notes.v1.NotesService/ListNotes"
NotesService_AddNote_FullMethodName = "/notes.v1.NotesService/AddNote"
NotesService_EditNote_FullMethodName = "/notes.v1.NotesService/EditNote"
)
// NotesServiceClient is the client API for NotesService service.
@ -29,6 +30,7 @@ const (
type NotesServiceClient interface {
ListNotes(ctx context.Context, in *ListNotesRequest, opts ...grpc.CallOption) (NotesService_ListNotesClient, error)
AddNote(ctx context.Context, in *AddNoteRequest, opts ...grpc.CallOption) (*AddNoteResponse, error)
EditNote(ctx context.Context, in *EditNoteRequest, opts ...grpc.CallOption) (*EditNoteResponse, error)
}
type notesServiceClient struct {
@ -80,12 +82,22 @@ func (c *notesServiceClient) AddNote(ctx context.Context, in *AddNoteRequest, op
return out, nil
}
func (c *notesServiceClient) EditNote(ctx context.Context, in *EditNoteRequest, opts ...grpc.CallOption) (*EditNoteResponse, error) {
out := new(EditNoteResponse)
err := c.cc.Invoke(ctx, NotesService_EditNote_FullMethodName, in, out, opts...)
if err != nil {
return nil, err
}
return out, nil
}
// NotesServiceServer is the server API for NotesService service.
// All implementations should embed UnimplementedNotesServiceServer
// for forward compatibility
type NotesServiceServer interface {
ListNotes(*ListNotesRequest, NotesService_ListNotesServer) error
AddNote(context.Context, *AddNoteRequest) (*AddNoteResponse, error)
EditNote(context.Context, *EditNoteRequest) (*EditNoteResponse, error)
}
// UnimplementedNotesServiceServer should be embedded to have forward compatible implementations.
@ -98,6 +110,9 @@ func (UnimplementedNotesServiceServer) ListNotes(*ListNotesRequest, NotesService
func (UnimplementedNotesServiceServer) AddNote(context.Context, *AddNoteRequest) (*AddNoteResponse, error) {
return nil, status.Errorf(codes.Unimplemented, "method AddNote not implemented")
}
func (UnimplementedNotesServiceServer) EditNote(context.Context, *EditNoteRequest) (*EditNoteResponse, error) {
return nil, status.Errorf(codes.Unimplemented, "method EditNote not implemented")
}
// UnsafeNotesServiceServer may be embedded to opt out of forward compatibility for this service.
// Use of this interface is not recommended, as added methods to NotesServiceServer will
@ -149,6 +164,24 @@ func _NotesService_AddNote_Handler(srv interface{}, ctx context.Context, dec fun
return interceptor(ctx, in, info, handler)
}
func _NotesService_EditNote_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(EditNoteRequest)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(NotesServiceServer).EditNote(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: NotesService_EditNote_FullMethodName,
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(NotesServiceServer).EditNote(ctx, req.(*EditNoteRequest))
}
return interceptor(ctx, in, info, handler)
}
// NotesService_ServiceDesc is the grpc.ServiceDesc for NotesService service.
// It's only intended for direct use with grpc.RegisterService,
// and not to be introspected or modified (even as a copy)
@ -160,6 +193,10 @@ var NotesService_ServiceDesc = grpc.ServiceDesc{
MethodName: "AddNote",
Handler: _NotesService_AddNote_Handler,
},
{
MethodName: "EditNote",
Handler: _NotesService_EditNote_Handler,
},
},
Streams: []grpc.StreamDesc{
{

45
scripts/generate-swagger-ui.sh Executable file
View File

@ -0,0 +1,45 @@
#!/bin/sh
set -e
[ -z "$SWAGGER_UI_VERSION" ] && echo "missing \$SWAGGER_UI_VERSION" && exit 1
SWAGGER_UI_GIT="https://github.com/swagger-api/swagger-ui.git"
CACHE_DIR="./.cache/swagger-ui/$SWAGGER_UI_VERSION"
GEN_DIR="./gen/openapiv2"
escape_str() {
echo "$1" | sed -e 's/[]\/$*.^[]/\\&/g'
}
# do caching if there's no cache yet
if [ ! -d "$CACHE_DIR" ]; then
mkdir -p "$CACHE_DIR"
tmp="$(mktemp -d)"
git clone --depth 1 --branch "$SWAGGER_UI_VERSION" "$SWAGGER_UI_GIT" "$tmp"
cp -r "$tmp/dist/"* "$CACHE_DIR"
cp -r "$tmp/LICENSE" "$CACHE_DIR"
rm -rf "$tmp"
fi
# populate swagger.json
tmp=" urls: ["
for i in $(find "$GEN_DIR" -name "*.swagger.json"); do
escaped_gen_dir="$(escape_str "$GEN_DIR/")"
path="$(echo $i | sed -e "s/$escaped_gen_dir//g")"
tmp="$tmp{\"url\":\"$path\",\"name\":\"$path\"},"
done
# delete last characters from $tmp
tmp=$(echo "$tmp" | sed 's/.$//')
tmp="$tmp],"
# recreate swagger-ui, delete all except swagger.json
find "$GEN_DIR" -type f -not -name "*.swagger.json" -delete
mkdir -p "$GEN_DIR"
cp -r "$CACHE_DIR/"* "$GEN_DIR"
# replace the default URL
line="$(cat "$GEN_DIR/swagger-initializer.js" | grep -n "url" | cut -f1 -d:)"
escaped_tmp="$(escape_str "$tmp")"
sed -i'' -e "$line s/^.*$/$escaped_tmp/" "$GEN_DIR/swagger-initializer.js"
rm -f "$GEN_DIR/swagger-initializer.js-e"

17
server/health.go Normal file
View File

@ -0,0 +1,17 @@
package server
import (
"context"
healthv1 "github.com/sundowndev/grpc-api-example/proto/health/v1"
)
type HealthService struct {
}
func NewHealthService() *HealthService {
return &HealthService{}
}
func (s *HealthService) GetHealth(_ context.Context, _ *healthv1.GetHealthRequest) (*healthv1.GetHealthResponse, error) {
return &healthv1.GetHealthResponse{Ok: true}, nil
}

View File

@ -54,7 +54,29 @@ func (s *NotesService) AddNote(_ context.Context, req *notesv1.AddNoteRequest) (
s.notes = append(s.notes, note)
return &notesv1.AddNoteResponse{
Note: note,
}, nil
return &notesv1.AddNoteResponse{Note: note}, nil
}
func (s *NotesService) EditNote(_ context.Context, req *notesv1.EditNoteRequest) (*notesv1.EditNoteResponse, error) {
s.mu.Lock()
defer s.mu.Unlock()
editedNote := &notesv1.Note{
Id: req.Note.Id,
Title: req.Note.Title,
Archived: req.Note.Archived,
}
if err := s.validator.Validate(editedNote); err != nil {
return nil, fmt.Errorf("validation failed: %v", err)
}
for i := range s.notes {
if s.notes[i].Id == req.Note.Id {
s.notes[i] = editedNote
break
}
}
return &notesv1.EditNoteResponse{Note: editedNote}, nil
}

View File

@ -52,22 +52,22 @@ func TestNotesService_ListNotes(t *testing.T) {
{
name: "test with few notes",
notes: []*notesv1.Note{
{Title: "test note 1", Archived: false},
{Title: "note 2", Archived: true},
{Title: "note 3", Archived: false},
{Title: "test note 1"},
{Title: "note 2"},
{Title: "note 3"},
},
},
{
name: "test with min_len validation error",
notes: []*notesv1.Note{
{Title: "", Archived: false},
{Title: ""},
},
wantErr: "validation failed: validation error:\n - title: value length must be at least 1 characters [string.min_len]",
},
{
name: "test with max_len validation error",
notes: []*notesv1.Note{
{Title: "this is a super long note title that can trigger a validation error", Archived: false},
{Title: "this is a super long note title that can trigger a validation error"},
},
wantErr: "validation failed: validation error:\n - title: value length must be at most 50 characters [string.max_len]",
},
@ -140,3 +140,29 @@ func TestNotesService_AddNote(t *testing.T) {
assert.Equal(t, "test note", res.Note.Title)
assert.Equal(t, false, res.Note.Archived)
}
func TestNotesService_EditNote(t *testing.T) {
srv, conn, err := newTestServer()
if err != nil {
t.Fatal(err)
}
client := notesv1.NewNotesServiceClient(conn)
defer srv.Close()
defer conn.Close()
res, err := client.AddNote(context.Background(), &notesv1.AddNoteRequest{Title: "test note"})
if err != nil {
t.Fatal(err)
}
res.Note.Title = "january groceries"
res.Note.Archived = true
res2, err := client.EditNote(context.Background(), &notesv1.EditNoteRequest{Note: res.Note})
if err != nil {
t.Fatal(err)
}
assert.Equal(t, "january groceries", res2.Note.Title)
assert.True(t, res2.Note.Archived)
}

View File

@ -4,6 +4,7 @@ import (
"errors"
"fmt"
"github.com/bufbuild/protovalidate-go"
healthv1 "github.com/sundowndev/grpc-api-example/proto/health/v1"
notesv1 "github.com/sundowndev/grpc-api-example/proto/notes/v1"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials"
@ -54,5 +55,6 @@ func (s *Server) Close() error {
}
func (s *Server) registerServices(v *protovalidate.Validator) {
healthv1.RegisterHealthServiceServer(s.grpcSrv, NewHealthService())
notesv1.RegisterNotesServiceServer(s.grpcSrv, NewNotesService(v))
}