HW13 Completed
parent
bf51b3e364
commit
b72c769dc8
|
@ -3,7 +3,6 @@ package main
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"flag"
|
"flag"
|
||||||
"github.com/dmitryt/otus-golang-hw/hw12_13_14_15_calendar/service/server"
|
|
||||||
"github.com/grpc-ecosystem/grpc-gateway/runtime"
|
"github.com/grpc-ecosystem/grpc-gateway/runtime"
|
||||||
"google.golang.org/grpc"
|
"google.golang.org/grpc"
|
||||||
oslog "log"
|
oslog "log"
|
||||||
|
@ -18,7 +17,6 @@ import (
|
||||||
"github.com/tiburon-777/HW_OTUS/hw12_13_14_15_calendar/internal/config"
|
"github.com/tiburon-777/HW_OTUS/hw12_13_14_15_calendar/internal/config"
|
||||||
"github.com/tiburon-777/HW_OTUS/hw12_13_14_15_calendar/internal/grpcserver"
|
"github.com/tiburon-777/HW_OTUS/hw12_13_14_15_calendar/internal/grpcserver"
|
||||||
"github.com/tiburon-777/HW_OTUS/hw12_13_14_15_calendar/internal/logger"
|
"github.com/tiburon-777/HW_OTUS/hw12_13_14_15_calendar/internal/logger"
|
||||||
internalhttp "github.com/tiburon-777/HW_OTUS/hw12_13_14_15_calendar/internal/server/http"
|
|
||||||
store "github.com/tiburon-777/HW_OTUS/hw12_13_14_15_calendar/internal/storage"
|
store "github.com/tiburon-777/HW_OTUS/hw12_13_14_15_calendar/internal/storage"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -50,14 +48,6 @@ func main() {
|
||||||
|
|
||||||
calendar := app.New(log, st)
|
calendar := app.New(log, st)
|
||||||
|
|
||||||
serverHTTP := internalhttp.NewServer(calendar, conf.Server.Address, conf.Server.Port)
|
|
||||||
go func() {
|
|
||||||
if err := serverHTTP.Start(); err != nil {
|
|
||||||
log.Errorf("failed to start http server: " + err.Error())
|
|
||||||
os.Exit(1)
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
|
|
||||||
serverGRPC := grpcserver.New(calendar)
|
serverGRPC := grpcserver.New(calendar)
|
||||||
go func() {
|
go func() {
|
||||||
if err := serverGRPC.Start(conf); err != nil {
|
if err := serverGRPC.Start(conf); err != nil {
|
||||||
|
@ -75,7 +65,7 @@ func main() {
|
||||||
|
|
||||||
grpcGwRouter := runtime.NewServeMux()
|
grpcGwRouter := runtime.NewServeMux()
|
||||||
|
|
||||||
if err = server.RegisterCalendarHandler(context.Background(), grpcGwRouter, grpcDiler); err != nil {
|
if err = grpcserver.RegisterGrpcHandler(context.Background(), grpcGwRouter, grpcDiler); err != nil {
|
||||||
log.Errorf("can't register handlers for grpc-gateway: " + err.Error())
|
log.Errorf("can't register handlers for grpc-gateway: " + err.Error())
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
@ -91,11 +81,8 @@ func main() {
|
||||||
}()
|
}()
|
||||||
|
|
||||||
signals := make(chan os.Signal, 1)
|
signals := make(chan os.Signal, 1)
|
||||||
signal.Notify(signals,syscall.SIGINT, syscall.SIGHUP)
|
signal.Notify(signals,syscall.SIGINT)
|
||||||
<-signals
|
<-signals
|
||||||
signal.Stop(signals)
|
signal.Stop(signals)
|
||||||
serverGRPC.Stop()
|
serverGRPC.Stop()
|
||||||
if err := serverHTTP.Stop(); err != nil {
|
|
||||||
log.Errorf("failed to stop http server: " + err.Error())
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,14 +1,10 @@
|
||||||
[Server]
|
|
||||||
Address = "localhost"
|
|
||||||
Port = "8080"
|
|
||||||
|
|
||||||
[Grpc]
|
[Grpc]
|
||||||
Address = "localhost"
|
Address = "localhost"
|
||||||
Port = "50051"
|
Port = "50051"
|
||||||
|
|
||||||
[Http]
|
[HTTP]
|
||||||
Address = "localhost"
|
Address = "localhost"
|
||||||
Port = "50051"
|
Port = "50052"
|
||||||
|
|
||||||
[Logger]
|
[Logger]
|
||||||
File = "./calendar.log"
|
File = "./calendar.log"
|
||||||
|
|
|
@ -131,6 +131,7 @@ github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJy
|
||||||
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
|
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
|
||||||
github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0=
|
github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0=
|
||||||
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||||
|
github.com/tiburon-777/HW_OTUS v0.0.0-20200927064133-fc19ac2e8966 h1:LjBeW5xHnZQP7ZlViMBSaKP+HJhLSkOdSj7K7lXdbzg=
|
||||||
github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
|
github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
|
||||||
github.com/zenazn/goji v0.9.0/go.mod h1:7S9M489iMyHBNxwZnk9/EHS098H4/F6TATF2mIxtB1Q=
|
github.com/zenazn/goji v0.9.0/go.mod h1:7S9M489iMyHBNxwZnk9/EHS098H4/F6TATF2mIxtB1Q=
|
||||||
go.uber.org/atomic v1.3.2/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE=
|
go.uber.org/atomic v1.3.2/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE=
|
||||||
|
|
|
@ -0,0 +1,31 @@
|
||||||
|
// Copyright (c) 2015, Google Inc.
|
||||||
|
//
|
||||||
|
// 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.
|
||||||
|
|
||||||
|
syntax = "proto3";
|
||||||
|
|
||||||
|
package google.api;
|
||||||
|
|
||||||
|
import "google/api/http.proto";
|
||||||
|
import "google/protobuf/descriptor.proto";
|
||||||
|
|
||||||
|
option go_package = "google.golang.org/genproto/googleapis/api/annotations;annotations";
|
||||||
|
option java_multiple_files = true;
|
||||||
|
option java_outer_classname = "AnnotationsProto";
|
||||||
|
option java_package = "com.google.api";
|
||||||
|
option objc_class_prefix = "GAPI";
|
||||||
|
|
||||||
|
extend google.protobuf.MethodOptions {
|
||||||
|
// See `HttpRule`.
|
||||||
|
HttpRule http = 72295728;
|
||||||
|
}
|
|
@ -0,0 +1,318 @@
|
||||||
|
// Copyright 2018 Google LLC
|
||||||
|
//
|
||||||
|
// 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.
|
||||||
|
|
||||||
|
syntax = "proto3";
|
||||||
|
|
||||||
|
package google.api;
|
||||||
|
|
||||||
|
option cc_enable_arenas = true;
|
||||||
|
option go_package = "google.golang.org/genproto/googleapis/api/annotations;annotations";
|
||||||
|
option java_multiple_files = true;
|
||||||
|
option java_outer_classname = "HttpProto";
|
||||||
|
option java_package = "com.google.api";
|
||||||
|
option objc_class_prefix = "GAPI";
|
||||||
|
|
||||||
|
|
||||||
|
// Defines the HTTP configuration for an API service. It contains a list of
|
||||||
|
// [HttpRule][google.api.HttpRule], each specifying the mapping of an RPC method
|
||||||
|
// to one or more HTTP REST API methods.
|
||||||
|
message Http {
|
||||||
|
// A list of HTTP configuration rules that apply to individual API methods.
|
||||||
|
//
|
||||||
|
// **NOTE:** All service configuration rules follow "last one wins" order.
|
||||||
|
repeated HttpRule rules = 1;
|
||||||
|
|
||||||
|
// When set to true, URL path parmeters will be fully URI-decoded except in
|
||||||
|
// cases of single segment matches in reserved expansion, where "%2F" will be
|
||||||
|
// left encoded.
|
||||||
|
//
|
||||||
|
// The default behavior is to not decode RFC 6570 reserved characters in multi
|
||||||
|
// segment matches.
|
||||||
|
bool fully_decode_reserved_expansion = 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
// `HttpRule` defines the mapping of an RPC method to one or more HTTP
|
||||||
|
// REST API methods. The mapping specifies how different portions of the RPC
|
||||||
|
// request message are mapped to URL path, URL query parameters, and
|
||||||
|
// HTTP request body. The mapping is typically specified as an
|
||||||
|
// `google.api.http` annotation on the RPC method,
|
||||||
|
// see "google/api/annotations.proto" for details.
|
||||||
|
//
|
||||||
|
// The mapping consists of a field specifying the path template and
|
||||||
|
// method kind. The path template can refer to fields in the request
|
||||||
|
// message, as in the example below which describes a REST GET
|
||||||
|
// operation on a resource collection of messages:
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// service Messaging {
|
||||||
|
// rpc GetMessage(GetMessageRequest) returns (Message) {
|
||||||
|
// option (google.api.http).get = "/v1/messages/{message_id}/{sub.subfield}";
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// message GetMessageRequest {
|
||||||
|
// message SubMessage {
|
||||||
|
// string subfield = 1;
|
||||||
|
// }
|
||||||
|
// string message_id = 1; // mapped to the URL
|
||||||
|
// SubMessage sub = 2; // `sub.subfield` is url-mapped
|
||||||
|
// }
|
||||||
|
// message Message {
|
||||||
|
// string text = 1; // content of the resource
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// The same http annotation can alternatively be expressed inside the
|
||||||
|
// `GRPC API Configuration` YAML file.
|
||||||
|
//
|
||||||
|
// http:
|
||||||
|
// rules:
|
||||||
|
// - selector: <proto_package_name>.Messaging.GetMessage
|
||||||
|
// get: /v1/messages/{message_id}/{sub.subfield}
|
||||||
|
//
|
||||||
|
// This definition enables an automatic, bidrectional mapping of HTTP
|
||||||
|
// JSON to RPC. Example:
|
||||||
|
//
|
||||||
|
// HTTP | RPC
|
||||||
|
// -----|-----
|
||||||
|
// `GET /v1/messages/123456/foo` | `GetMessage(message_id: "123456" sub: SubMessage(subfield: "foo"))`
|
||||||
|
//
|
||||||
|
// In general, not only fields but also field paths can be referenced
|
||||||
|
// from a path pattern. Fields mapped to the path pattern cannot be
|
||||||
|
// repeated and must have a primitive (non-message) type.
|
||||||
|
//
|
||||||
|
// Any fields in the request message which are not bound by the path
|
||||||
|
// pattern automatically become (optional) HTTP query
|
||||||
|
// parameters. Assume the following definition of the request message:
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// service Messaging {
|
||||||
|
// rpc GetMessage(GetMessageRequest) returns (Message) {
|
||||||
|
// option (google.api.http).get = "/v1/messages/{message_id}";
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// message GetMessageRequest {
|
||||||
|
// message SubMessage {
|
||||||
|
// string subfield = 1;
|
||||||
|
// }
|
||||||
|
// string message_id = 1; // mapped to the URL
|
||||||
|
// int64 revision = 2; // becomes a parameter
|
||||||
|
// SubMessage sub = 3; // `sub.subfield` becomes a parameter
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// This enables a HTTP JSON to RPC mapping as below:
|
||||||
|
//
|
||||||
|
// HTTP | RPC
|
||||||
|
// -----|-----
|
||||||
|
// `GET /v1/messages/123456?revision=2&sub.subfield=foo` | `GetMessage(message_id: "123456" revision: 2 sub: SubMessage(subfield: "foo"))`
|
||||||
|
//
|
||||||
|
// Note that fields which are mapped to HTTP parameters must have a
|
||||||
|
// primitive type or a repeated primitive type. Message types are not
|
||||||
|
// allowed. In the case of a repeated type, the parameter can be
|
||||||
|
// repeated in the URL, as in `...?param=A¶m=B`.
|
||||||
|
//
|
||||||
|
// For HTTP method kinds which allow a request body, the `body` field
|
||||||
|
// specifies the mapping. Consider a REST update method on the
|
||||||
|
// message resource collection:
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// service Messaging {
|
||||||
|
// rpc UpdateMessage(UpdateMessageRequest) returns (Message) {
|
||||||
|
// option (google.api.http) = {
|
||||||
|
// put: "/v1/messages/{message_id}"
|
||||||
|
// body: "message"
|
||||||
|
// };
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// message UpdateMessageRequest {
|
||||||
|
// string message_id = 1; // mapped to the URL
|
||||||
|
// Message message = 2; // mapped to the body
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// The following HTTP JSON to RPC mapping is enabled, where the
|
||||||
|
// representation of the JSON in the request body is determined by
|
||||||
|
// protos JSON encoding:
|
||||||
|
//
|
||||||
|
// HTTP | RPC
|
||||||
|
// -----|-----
|
||||||
|
// `PUT /v1/messages/123456 { "text": "Hi!" }` | `UpdateMessage(message_id: "123456" message { text: "Hi!" })`
|
||||||
|
//
|
||||||
|
// The special name `*` can be used in the body mapping to define that
|
||||||
|
// every field not bound by the path template should be mapped to the
|
||||||
|
// request body. This enables the following alternative definition of
|
||||||
|
// the update method:
|
||||||
|
//
|
||||||
|
// service Messaging {
|
||||||
|
// rpc UpdateMessage(Message) returns (Message) {
|
||||||
|
// option (google.api.http) = {
|
||||||
|
// put: "/v1/messages/{message_id}"
|
||||||
|
// body: "*"
|
||||||
|
// };
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// message Message {
|
||||||
|
// string message_id = 1;
|
||||||
|
// string text = 2;
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// The following HTTP JSON to RPC mapping is enabled:
|
||||||
|
//
|
||||||
|
// HTTP | RPC
|
||||||
|
// -----|-----
|
||||||
|
// `PUT /v1/messages/123456 { "text": "Hi!" }` | `UpdateMessage(message_id: "123456" text: "Hi!")`
|
||||||
|
//
|
||||||
|
// Note that when using `*` in the body mapping, it is not possible to
|
||||||
|
// have HTTP parameters, as all fields not bound by the path end in
|
||||||
|
// the body. This makes this option more rarely used in practice of
|
||||||
|
// defining REST APIs. The common usage of `*` is in custom methods
|
||||||
|
// which don't use the URL at all for transferring data.
|
||||||
|
//
|
||||||
|
// It is possible to define multiple HTTP methods for one RPC by using
|
||||||
|
// the `additional_bindings` option. Example:
|
||||||
|
//
|
||||||
|
// service Messaging {
|
||||||
|
// rpc GetMessage(GetMessageRequest) returns (Message) {
|
||||||
|
// option (google.api.http) = {
|
||||||
|
// get: "/v1/messages/{message_id}"
|
||||||
|
// additional_bindings {
|
||||||
|
// get: "/v1/users/{user_id}/messages/{message_id}"
|
||||||
|
// }
|
||||||
|
// };
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// message GetMessageRequest {
|
||||||
|
// string message_id = 1;
|
||||||
|
// string user_id = 2;
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// This enables the following two alternative HTTP JSON to RPC
|
||||||
|
// mappings:
|
||||||
|
//
|
||||||
|
// HTTP | RPC
|
||||||
|
// -----|-----
|
||||||
|
// `GET /v1/messages/123456` | `GetMessage(message_id: "123456")`
|
||||||
|
// `GET /v1/users/me/messages/123456` | `GetMessage(user_id: "me" message_id: "123456")`
|
||||||
|
//
|
||||||
|
// # Rules for HTTP mapping
|
||||||
|
//
|
||||||
|
// The rules for mapping HTTP path, query parameters, and body fields
|
||||||
|
// to the request message are as follows:
|
||||||
|
//
|
||||||
|
// 1. The `body` field specifies either `*` or a field path, or is
|
||||||
|
// omitted. If omitted, it indicates there is no HTTP request body.
|
||||||
|
// 2. Leaf fields (recursive expansion of nested messages in the
|
||||||
|
// request) can be classified into three types:
|
||||||
|
// (a) Matched in the URL template.
|
||||||
|
// (b) Covered by body (if body is `*`, everything except (a) fields;
|
||||||
|
// else everything under the body field)
|
||||||
|
// (c) All other fields.
|
||||||
|
// 3. URL query parameters found in the HTTP request are mapped to (c) fields.
|
||||||
|
// 4. Any body sent with an HTTP request can contain only (b) fields.
|
||||||
|
//
|
||||||
|
// The syntax of the path template is as follows:
|
||||||
|
//
|
||||||
|
// Template = "/" Segments [ Verb ] ;
|
||||||
|
// Segments = Segment { "/" Segment } ;
|
||||||
|
// Segment = "*" | "**" | LITERAL | Variable ;
|
||||||
|
// Variable = "{" FieldPath [ "=" Segments ] "}" ;
|
||||||
|
// FieldPath = IDENT { "." IDENT } ;
|
||||||
|
// Verb = ":" LITERAL ;
|
||||||
|
//
|
||||||
|
// The syntax `*` matches a single path segment. The syntax `**` matches zero
|
||||||
|
// or more path segments, which must be the last part of the path except the
|
||||||
|
// `Verb`. The syntax `LITERAL` matches literal text in the path.
|
||||||
|
//
|
||||||
|
// The syntax `Variable` matches part of the URL path as specified by its
|
||||||
|
// template. A variable template must not contain other variables. If a variable
|
||||||
|
// matches a single path segment, its template may be omitted, e.g. `{var}`
|
||||||
|
// is equivalent to `{var=*}`.
|
||||||
|
//
|
||||||
|
// If a variable contains exactly one path segment, such as `"{var}"` or
|
||||||
|
// `"{var=*}"`, when such a variable is expanded into a URL path, all characters
|
||||||
|
// except `[-_.~0-9a-zA-Z]` are percent-encoded. Such variables show up in the
|
||||||
|
// Discovery Document as `{var}`.
|
||||||
|
//
|
||||||
|
// If a variable contains one or more path segments, such as `"{var=foo/*}"`
|
||||||
|
// or `"{var=**}"`, when such a variable is expanded into a URL path, all
|
||||||
|
// characters except `[-_.~/0-9a-zA-Z]` are percent-encoded. Such variables
|
||||||
|
// show up in the Discovery Document as `{+var}`.
|
||||||
|
//
|
||||||
|
// NOTE: While the single segment variable matches the semantics of
|
||||||
|
// [RFC 6570](https://tools.ietf.org/html/rfc6570) Section 3.2.2
|
||||||
|
// Simple String Expansion, the multi segment variable **does not** match
|
||||||
|
// RFC 6570 Reserved Expansion. The reason is that the Reserved Expansion
|
||||||
|
// does not expand special characters like `?` and `#`, which would lead
|
||||||
|
// to invalid URLs.
|
||||||
|
//
|
||||||
|
// NOTE: the field paths in variables and in the `body` must not refer to
|
||||||
|
// repeated fields or map fields.
|
||||||
|
message HttpRule {
|
||||||
|
// Selects methods to which this rule applies.
|
||||||
|
//
|
||||||
|
// Refer to [selector][google.api.DocumentationRule.selector] for syntax details.
|
||||||
|
string selector = 1;
|
||||||
|
|
||||||
|
// Determines the URL pattern is matched by this rules. This pattern can be
|
||||||
|
// used with any of the {get|put|post|delete|patch} methods. A custom method
|
||||||
|
// can be defined using the 'custom' field.
|
||||||
|
oneof pattern {
|
||||||
|
// Used for listing and getting information about resources.
|
||||||
|
string get = 2;
|
||||||
|
|
||||||
|
// Used for updating a resource.
|
||||||
|
string put = 3;
|
||||||
|
|
||||||
|
// Used for creating a resource.
|
||||||
|
string post = 4;
|
||||||
|
|
||||||
|
// Used for deleting a resource.
|
||||||
|
string delete = 5;
|
||||||
|
|
||||||
|
// Used for updating a resource.
|
||||||
|
string patch = 6;
|
||||||
|
|
||||||
|
// The custom pattern is used for specifying an HTTP method that is not
|
||||||
|
// included in the `pattern` field, such as HEAD, or "*" to leave the
|
||||||
|
// HTTP method unspecified for this rule. The wild-card rule is useful
|
||||||
|
// for services that provide content to Web (HTML) clients.
|
||||||
|
CustomHttpPattern custom = 8;
|
||||||
|
}
|
||||||
|
|
||||||
|
// The name of the request field whose value is mapped to the HTTP body, or
|
||||||
|
// `*` for mapping all fields not captured by the path pattern to the HTTP
|
||||||
|
// body. NOTE: the referred field must not be a repeated field and must be
|
||||||
|
// present at the top-level of request message type.
|
||||||
|
string body = 7;
|
||||||
|
|
||||||
|
// Optional. The name of the response field whose value is mapped to the HTTP
|
||||||
|
// body of response. Other response fields are ignored. When
|
||||||
|
// not set, the response message will be used as HTTP body of response.
|
||||||
|
string response_body = 12;
|
||||||
|
|
||||||
|
// Additional HTTP bindings for the selector. Nested bindings must
|
||||||
|
// not contain an `additional_bindings` field themselves (that is,
|
||||||
|
// the nesting may only be one level deep).
|
||||||
|
repeated HttpRule additional_bindings = 11;
|
||||||
|
}
|
||||||
|
|
||||||
|
// A custom pattern is used for defining custom HTTP verb.
|
||||||
|
message CustomHttpPattern {
|
||||||
|
// The name of this custom HTTP verb.
|
||||||
|
string kind = 1;
|
||||||
|
|
||||||
|
// The path matched by this custom verb.
|
||||||
|
string path = 2;
|
||||||
|
}
|
|
@ -0,0 +1,78 @@
|
||||||
|
// Copyright 2018 Google LLC.
|
||||||
|
//
|
||||||
|
// 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.
|
||||||
|
//
|
||||||
|
|
||||||
|
syntax = "proto3";
|
||||||
|
|
||||||
|
package google.api;
|
||||||
|
|
||||||
|
import "google/protobuf/any.proto";
|
||||||
|
|
||||||
|
option cc_enable_arenas = true;
|
||||||
|
option go_package = "google.golang.org/genproto/googleapis/api/httpbody;httpbody";
|
||||||
|
option java_multiple_files = true;
|
||||||
|
option java_outer_classname = "HttpBodyProto";
|
||||||
|
option java_package = "com.google.api";
|
||||||
|
option objc_class_prefix = "GAPI";
|
||||||
|
|
||||||
|
// Message that represents an arbitrary HTTP body. It should only be used for
|
||||||
|
// payload formats that can't be represented as JSON, such as raw binary or
|
||||||
|
// an HTML page.
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// This message can be used both in streaming and non-streaming API methods in
|
||||||
|
// the request as well as the response.
|
||||||
|
//
|
||||||
|
// It can be used as a top-level request field, which is convenient if one
|
||||||
|
// wants to extract parameters from either the URL or HTTP template into the
|
||||||
|
// request fields and also want access to the raw HTTP body.
|
||||||
|
//
|
||||||
|
// Example:
|
||||||
|
//
|
||||||
|
// message GetResourceRequest {
|
||||||
|
// // A unique request id.
|
||||||
|
// string request_id = 1;
|
||||||
|
//
|
||||||
|
// // The raw HTTP body is bound to this field.
|
||||||
|
// google.api.HttpBody http_body = 2;
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// service ResourceService {
|
||||||
|
// rpc GetResource(GetResourceRequest) returns (google.api.HttpBody);
|
||||||
|
// rpc UpdateResource(google.api.HttpBody) returns
|
||||||
|
// (google.protobuf.Empty);
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// Example with streaming methods:
|
||||||
|
//
|
||||||
|
// service CaldavService {
|
||||||
|
// rpc GetCalendar(stream google.api.HttpBody)
|
||||||
|
// returns (stream google.api.HttpBody);
|
||||||
|
// rpc UpdateCalendar(stream google.api.HttpBody)
|
||||||
|
// returns (stream google.api.HttpBody);
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// Use of this type only changes how the request and response bodies are
|
||||||
|
// handled, all other features will continue to work unchanged.
|
||||||
|
message HttpBody {
|
||||||
|
// The HTTP Content-Type header value specifying the content type of the body.
|
||||||
|
string content_type = 1;
|
||||||
|
|
||||||
|
// The HTTP request/response body as raw binary.
|
||||||
|
bytes data = 2;
|
||||||
|
|
||||||
|
// Application specific response metadata. Must be set in the first response
|
||||||
|
// for streaming APIs.
|
||||||
|
repeated google.protobuf.Any extensions = 3;
|
||||||
|
}
|
|
@ -7,15 +7,42 @@ option go_package = "grpcserver";
|
||||||
import "google/protobuf/timestamp.proto";
|
import "google/protobuf/timestamp.proto";
|
||||||
import "google/protobuf/duration.proto";
|
import "google/protobuf/duration.proto";
|
||||||
import "google/protobuf/empty.proto";
|
import "google/protobuf/empty.proto";
|
||||||
|
import "google/api/annotations.proto";
|
||||||
|
|
||||||
|
|
||||||
service grpc {
|
service grpc {
|
||||||
rpc Create(CreateReq) returns (CreateRsp) {}
|
rpc Create(CreateReq) returns (CreateRsp) {
|
||||||
rpc Update(UpdateReq) returns (google.protobuf.Empty) {}
|
option (google.api.http) = {
|
||||||
rpc Delete(DeleteReq) returns (google.protobuf.Empty) {}
|
post: "/events",
|
||||||
rpc List(google.protobuf.Empty) returns (ListResp) {}
|
body: "*",
|
||||||
rpc GetByID(GetByIDReq) returns (GetByIDResp) {}
|
};
|
||||||
rpc GetByDate(GetByDateReq) returns (GetByDateResp) {}
|
}
|
||||||
|
rpc Update(UpdateReq) returns (google.protobuf.Empty) {
|
||||||
|
option (google.api.http) = {
|
||||||
|
put: "/events/{ID}",
|
||||||
|
body: "*",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
rpc Delete(DeleteReq) returns (google.protobuf.Empty) {
|
||||||
|
option (google.api.http) = {
|
||||||
|
delete: "/events/{ID}"
|
||||||
|
};
|
||||||
|
}
|
||||||
|
rpc List(google.protobuf.Empty) returns (ListResp) {
|
||||||
|
option (google.api.http) = {
|
||||||
|
get: "/events"
|
||||||
|
};
|
||||||
|
}
|
||||||
|
rpc GetByID(GetByIDReq) returns (GetByIDResp) {
|
||||||
|
option (google.api.http) = {
|
||||||
|
get: "/events/{ID}"
|
||||||
|
};
|
||||||
|
}
|
||||||
|
rpc GetByDate(GetByDateReq) returns (GetByDateResp) {
|
||||||
|
option (google.api.http) = {
|
||||||
|
post: "/events/{Range}/{Date}"
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
enum QueryRange {
|
enum QueryRange {
|
||||||
|
|
|
@ -8,7 +8,6 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
Server Server
|
|
||||||
GRPC Server
|
GRPC Server
|
||||||
HTTP Server
|
HTTP Server
|
||||||
Logger Logger
|
Logger Logger
|
||||||
|
|
|
@ -10,6 +10,7 @@ import (
|
||||||
duration "github.com/golang/protobuf/ptypes/duration"
|
duration "github.com/golang/protobuf/ptypes/duration"
|
||||||
empty "github.com/golang/protobuf/ptypes/empty"
|
empty "github.com/golang/protobuf/ptypes/empty"
|
||||||
timestamp "github.com/golang/protobuf/ptypes/timestamp"
|
timestamp "github.com/golang/protobuf/ptypes/timestamp"
|
||||||
|
_ "google.golang.org/genproto/googleapis/api/annotations"
|
||||||
grpc "google.golang.org/grpc"
|
grpc "google.golang.org/grpc"
|
||||||
codes "google.golang.org/grpc/codes"
|
codes "google.golang.org/grpc/codes"
|
||||||
status "google.golang.org/grpc/status"
|
status "google.golang.org/grpc/status"
|
||||||
|
@ -566,40 +567,45 @@ func init() {
|
||||||
func init() { proto.RegisterFile("grpcserver.proto", fileDescriptor_afa6debe97205904) }
|
func init() { proto.RegisterFile("grpcserver.proto", fileDescriptor_afa6debe97205904) }
|
||||||
|
|
||||||
var fileDescriptor_afa6debe97205904 = []byte{
|
var fileDescriptor_afa6debe97205904 = []byte{
|
||||||
// 525 bytes of a gzipped FileDescriptorProto
|
// 608 bytes of a gzipped FileDescriptorProto
|
||||||
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe4, 0x54, 0xdf, 0x6b, 0xd3, 0x50,
|
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe4, 0x95, 0x4f, 0x6f, 0xd3, 0x4c,
|
||||||
0x14, 0x5e, 0xda, 0x24, 0x5d, 0x4e, 0xe7, 0xa8, 0x87, 0x59, 0xb3, 0x4c, 0xb4, 0xe4, 0xc5, 0x3a,
|
0x10, 0xc6, 0x5f, 0x27, 0x8e, 0x53, 0x4f, 0xf3, 0x96, 0x74, 0x14, 0x52, 0xd7, 0xad, 0x4a, 0xb4,
|
||||||
0x24, 0x83, 0x0e, 0x65, 0x13, 0x5f, 0xac, 0xb7, 0x68, 0x71, 0x56, 0x0c, 0x1d, 0xa2, 0x6f, 0xd9,
|
0x17, 0x42, 0x84, 0x6c, 0x29, 0x15, 0x12, 0xf4, 0x46, 0x71, 0x04, 0x81, 0x36, 0x14, 0x2b, 0x15,
|
||||||
0x76, 0x56, 0x02, 0x6d, 0x13, 0x93, 0xdb, 0x41, 0xfe, 0x68, 0xc1, 0x57, 0xdf, 0x24, 0xf7, 0x26,
|
0x82, 0x13, 0x6e, 0xbb, 0x8d, 0x2c, 0x25, 0xb6, 0xb1, 0x37, 0x95, 0xa2, 0x2a, 0x17, 0xbe, 0x02,
|
||||||
0x69, 0xda, 0x66, 0xea, 0x9e, 0x7d, 0x4b, 0xee, 0xf7, 0xe3, 0x9c, 0x7b, 0xce, 0xc7, 0x85, 0xd6,
|
0x1f, 0x8d, 0xaf, 0xc0, 0x15, 0xee, 0xdc, 0x90, 0xd7, 0x6b, 0xc7, 0xf9, 0x27, 0xe8, 0x99, 0x5b,
|
||||||
0x24, 0x0a, 0x2f, 0x63, 0x8a, 0x6e, 0x28, 0x72, 0xc2, 0x28, 0xe0, 0x01, 0xc2, 0xf2, 0xc4, 0x7a,
|
0x76, 0x9f, 0x99, 0xdf, 0xcc, 0xec, 0x3c, 0x8a, 0xa1, 0x3a, 0x08, 0x83, 0xcb, 0x88, 0x86, 0x37,
|
||||||
0x32, 0x09, 0x82, 0xc9, 0x94, 0x8e, 0x04, 0x72, 0xb1, 0xb8, 0x3e, 0xe2, 0xfe, 0x8c, 0x62, 0xee,
|
0x34, 0x34, 0x82, 0xd0, 0x67, 0x3e, 0xc2, 0xec, 0x46, 0x7f, 0x30, 0xf0, 0xfd, 0xc1, 0x90, 0x9a,
|
||||||
0xcd, 0x42, 0x49, 0xb6, 0x1e, 0xaf, 0x13, 0xae, 0x16, 0x91, 0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16, 0x00, 0x5c, 0x59, 0xc1, 0x32, 0x33,
|
0xe5, 0xd5, 0x8f, 0xa4, 0x16, 0x9e, 0x81, 0x92, 0x98, 0x63, 0x9e, 0x95, 0x19, 0x46, 0xaf, 0x2f,
|
||||||
0xd6, 0xc3, 0xca, 0x73, 0xa1, 0xee, 0x83, 0x51, 0xac, 0x05, 0xcd, 0x0d, 0x5e, 0x96, 0x0d, 0x6b,
|
0xbd, 0x56, 0x27, 0xfe, 0x0b, 0x22, 0x3b, 0x1c, 0xb6, 0xad, 0x57, 0x04, 0xcc, 0xbc, 0xed, 0x5a,
|
||||||
0xff, 0x16, 0x24, 0xf5, 0xe8, 0xef, 0x7c, 0x2b, 0xbd, 0xd7, 0x17, 0xba, 0xe8, 0xfb, 0xf8, 0x77,
|
0xd3, 0x98, 0x78, 0x0a, 0x4a, 0x62, 0x94, 0x79, 0x62, 0x66, 0x9e, 0xb5, 0xc4, 0x1a, 0x27, 0x6e,
|
||||||
0x00, 0x00, 0x00, 0xff, 0xff, 0x60, 0x63, 0x06, 0xc6, 0xd6, 0x05, 0x00, 0x00,
|
0xb5, 0xe6, 0x88, 0xd8, 0x01, 0x39, 0xb6, 0x16, 0xae, 0xc9, 0xd2, 0x6b, 0xf9, 0x22, 0xa9, 0x09,
|
||||||
|
0xc9, 0x3d, 0xce, 0x52, 0x31, 0x1d, 0x15, 0xcf, 0xa0, 0x2c, 0xcc, 0x84, 0x73, 0xeb, 0x9c, 0xf9,
|
||||||
|
0x4f, 0xdf, 0x59, 0x79, 0x1f, 0x05, 0x69, 0x63, 0x38, 0xdf, 0xd8, 0x27, 0x50, 0xb3, 0xb5, 0xa3,
|
||||||
|
0xb6, 0x94, 0x2b, 0xbc, 0xa7, 0xef, 0xae, 0x51, 0xa2, 0x80, 0x1c, 0x70, 0xae, 0x46, 0xea, 0x19,
|
||||||
|
0x97, 0xdb, 0x60, 0x6a, 0xde, 0xc6, 0x21, 0xd3, 0xe3, 0xca, 0xc7, 0xdc, 0xb7, 0xe4, 0x42, 0xe1,
|
||||||
|
0x83, 0x1f, 0xfe, 0x0e, 0x00, 0x00, 0xff, 0xff, 0xc6, 0xe4, 0xd7, 0xf2, 0x72, 0x06, 0x00, 0x00,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reference imports to suppress errors if they are not otherwise used.
|
// Reference imports to suppress errors if they are not otherwise used.
|
||||||
|
|
|
@ -0,0 +1,375 @@
|
||||||
|
// Code generated by protoc-gen-grpc-gateway. DO NOT EDIT.
|
||||||
|
// source: grpcserver.proto
|
||||||
|
|
||||||
|
/*
|
||||||
|
Package grpcserver is a reverse proxy.
|
||||||
|
|
||||||
|
It translates gRPC into RESTful JSON APIs.
|
||||||
|
*/
|
||||||
|
package grpcserver
|
||||||
|
|
||||||
|
import (
|
||||||
|
"io"
|
||||||
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/golang/protobuf/proto"
|
||||||
|
"github.com/golang/protobuf/ptypes/empty"
|
||||||
|
"github.com/grpc-ecosystem/grpc-gateway/runtime"
|
||||||
|
"github.com/grpc-ecosystem/grpc-gateway/utilities"
|
||||||
|
"golang.org/x/net/context"
|
||||||
|
"google.golang.org/grpc"
|
||||||
|
"google.golang.org/grpc/codes"
|
||||||
|
"google.golang.org/grpc/grpclog"
|
||||||
|
"google.golang.org/grpc/status"
|
||||||
|
)
|
||||||
|
|
||||||
|
var _ codes.Code
|
||||||
|
var _ io.Reader
|
||||||
|
var _ status.Status
|
||||||
|
var _ = runtime.String
|
||||||
|
var _ = utilities.NewDoubleArray
|
||||||
|
|
||||||
|
func request_Grpc_Create_0(ctx context.Context, marshaler runtime.Marshaler, client GrpcClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
|
||||||
|
var protoReq CreateReq
|
||||||
|
var metadata runtime.ServerMetadata
|
||||||
|
|
||||||
|
newReader, berr := utilities.IOReaderFactory(req.Body)
|
||||||
|
if berr != nil {
|
||||||
|
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", berr)
|
||||||
|
}
|
||||||
|
if err := marshaler.NewDecoder(newReader()).Decode(&protoReq); err != nil && err != io.EOF {
|
||||||
|
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
msg, err := client.Create(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD))
|
||||||
|
return msg, metadata, err
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func request_Grpc_Update_0(ctx context.Context, marshaler runtime.Marshaler, client GrpcClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
|
||||||
|
var protoReq UpdateReq
|
||||||
|
var metadata runtime.ServerMetadata
|
||||||
|
|
||||||
|
newReader, berr := utilities.IOReaderFactory(req.Body)
|
||||||
|
if berr != nil {
|
||||||
|
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", berr)
|
||||||
|
}
|
||||||
|
if err := marshaler.NewDecoder(newReader()).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["ID"]
|
||||||
|
if !ok {
|
||||||
|
return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "ID")
|
||||||
|
}
|
||||||
|
|
||||||
|
protoReq.ID, err = runtime.Int64(val)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "ID", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
msg, err := client.Update(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD))
|
||||||
|
return msg, metadata, err
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func request_Grpc_Delete_0(ctx context.Context, marshaler runtime.Marshaler, client GrpcClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
|
||||||
|
var protoReq DeleteReq
|
||||||
|
var metadata runtime.ServerMetadata
|
||||||
|
|
||||||
|
var (
|
||||||
|
val string
|
||||||
|
ok bool
|
||||||
|
err error
|
||||||
|
_ = err
|
||||||
|
)
|
||||||
|
|
||||||
|
val, ok = pathParams["ID"]
|
||||||
|
if !ok {
|
||||||
|
return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "ID")
|
||||||
|
}
|
||||||
|
|
||||||
|
protoReq.ID, err = runtime.Int64(val)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "ID", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
msg, err := client.Delete(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD))
|
||||||
|
return msg, metadata, err
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func request_Grpc_List_0(ctx context.Context, marshaler runtime.Marshaler, client GrpcClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
|
||||||
|
var protoReq empty.Empty
|
||||||
|
var metadata runtime.ServerMetadata
|
||||||
|
|
||||||
|
msg, err := client.List(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD))
|
||||||
|
return msg, metadata, err
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func request_Grpc_GetByID_0(ctx context.Context, marshaler runtime.Marshaler, client GrpcClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
|
||||||
|
var protoReq GetByIDReq
|
||||||
|
var metadata runtime.ServerMetadata
|
||||||
|
|
||||||
|
var (
|
||||||
|
val string
|
||||||
|
ok bool
|
||||||
|
err error
|
||||||
|
_ = err
|
||||||
|
)
|
||||||
|
|
||||||
|
val, ok = pathParams["ID"]
|
||||||
|
if !ok {
|
||||||
|
return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "ID")
|
||||||
|
}
|
||||||
|
|
||||||
|
protoReq.ID, err = runtime.Int64(val)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "ID", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
msg, err := client.GetByID(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD))
|
||||||
|
return msg, metadata, err
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func request_Grpc_GetByDate_0(ctx context.Context, marshaler runtime.Marshaler, client GrpcClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
|
||||||
|
var protoReq GetByDateReq
|
||||||
|
var metadata runtime.ServerMetadata
|
||||||
|
|
||||||
|
var (
|
||||||
|
val string
|
||||||
|
e int32
|
||||||
|
ok bool
|
||||||
|
err error
|
||||||
|
_ = err
|
||||||
|
)
|
||||||
|
|
||||||
|
val, ok = pathParams["Range"]
|
||||||
|
if !ok {
|
||||||
|
return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "Range")
|
||||||
|
}
|
||||||
|
|
||||||
|
e, err = runtime.Enum(val, QueryRange_value)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "Range", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
protoReq.Range = QueryRange(e)
|
||||||
|
|
||||||
|
val, ok = pathParams["Date"]
|
||||||
|
if !ok {
|
||||||
|
return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "Date")
|
||||||
|
}
|
||||||
|
|
||||||
|
protoReq.Date, err = runtime.Timestamp(val)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "Date", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
msg, err := client.GetByDate(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD))
|
||||||
|
return msg, metadata, err
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// RegisterGrpcHandlerFromEndpoint is same as RegisterGrpcHandler but
|
||||||
|
// automatically dials to "endpoint" and closes the connection when "ctx" gets done.
|
||||||
|
func RegisterGrpcHandlerFromEndpoint(ctx context.Context, mux *runtime.ServeMux, endpoint string, opts []grpc.DialOption) (err error) {
|
||||||
|
conn, err := grpc.Dial(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 RegisterGrpcHandler(ctx, mux, conn)
|
||||||
|
}
|
||||||
|
|
||||||
|
// RegisterGrpcHandler registers the http handlers for service Grpc to "mux".
|
||||||
|
// The handlers forward requests to the grpc endpoint over "conn".
|
||||||
|
func RegisterGrpcHandler(ctx context.Context, mux *runtime.ServeMux, conn *grpc.ClientConn) error {
|
||||||
|
return RegisterGrpcHandlerClient(ctx, mux, NewGrpcClient(conn))
|
||||||
|
}
|
||||||
|
|
||||||
|
// RegisterGrpcHandlerClient registers the http handlers for service Grpc
|
||||||
|
// to "mux". The handlers forward requests to the grpc endpoint over the given implementation of "GrpcClient".
|
||||||
|
// Note: the gRPC framework executes interceptors within the gRPC handler. If the passed in "GrpcClient"
|
||||||
|
// doesn't go through the normal gRPC flow (creating a gRPC client etc.) then it will be up to the passed in
|
||||||
|
// "GrpcClient" to call the correct interceptors.
|
||||||
|
func RegisterGrpcHandlerClient(ctx context.Context, mux *runtime.ServeMux, client GrpcClient) error {
|
||||||
|
|
||||||
|
mux.Handle("POST", pattern_Grpc_Create_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)
|
||||||
|
rctx, err := runtime.AnnotateContext(ctx, mux, req)
|
||||||
|
if err != nil {
|
||||||
|
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
resp, md, err := request_Grpc_Create_0(rctx, inboundMarshaler, client, req, pathParams)
|
||||||
|
ctx = runtime.NewServerMetadataContext(ctx, md)
|
||||||
|
if err != nil {
|
||||||
|
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
forward_Grpc_Create_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
|
||||||
|
|
||||||
|
})
|
||||||
|
|
||||||
|
mux.Handle("PUT", pattern_Grpc_Update_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)
|
||||||
|
rctx, err := runtime.AnnotateContext(ctx, mux, req)
|
||||||
|
if err != nil {
|
||||||
|
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
resp, md, err := request_Grpc_Update_0(rctx, inboundMarshaler, client, req, pathParams)
|
||||||
|
ctx = runtime.NewServerMetadataContext(ctx, md)
|
||||||
|
if err != nil {
|
||||||
|
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
forward_Grpc_Update_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
|
||||||
|
|
||||||
|
})
|
||||||
|
|
||||||
|
mux.Handle("DELETE", pattern_Grpc_Delete_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)
|
||||||
|
rctx, err := runtime.AnnotateContext(ctx, mux, req)
|
||||||
|
if err != nil {
|
||||||
|
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
resp, md, err := request_Grpc_Delete_0(rctx, inboundMarshaler, client, req, pathParams)
|
||||||
|
ctx = runtime.NewServerMetadataContext(ctx, md)
|
||||||
|
if err != nil {
|
||||||
|
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
forward_Grpc_Delete_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
|
||||||
|
|
||||||
|
})
|
||||||
|
|
||||||
|
mux.Handle("GET", pattern_Grpc_List_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)
|
||||||
|
rctx, err := runtime.AnnotateContext(ctx, mux, req)
|
||||||
|
if err != nil {
|
||||||
|
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
resp, md, err := request_Grpc_List_0(rctx, inboundMarshaler, client, req, pathParams)
|
||||||
|
ctx = runtime.NewServerMetadataContext(ctx, md)
|
||||||
|
if err != nil {
|
||||||
|
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
forward_Grpc_List_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
|
||||||
|
|
||||||
|
})
|
||||||
|
|
||||||
|
mux.Handle("GET", pattern_Grpc_GetByID_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)
|
||||||
|
rctx, err := runtime.AnnotateContext(ctx, mux, req)
|
||||||
|
if err != nil {
|
||||||
|
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
resp, md, err := request_Grpc_GetByID_0(rctx, inboundMarshaler, client, req, pathParams)
|
||||||
|
ctx = runtime.NewServerMetadataContext(ctx, md)
|
||||||
|
if err != nil {
|
||||||
|
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
forward_Grpc_GetByID_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
|
||||||
|
|
||||||
|
})
|
||||||
|
|
||||||
|
mux.Handle("POST", pattern_Grpc_GetByDate_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)
|
||||||
|
rctx, err := runtime.AnnotateContext(ctx, mux, req)
|
||||||
|
if err != nil {
|
||||||
|
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
resp, md, err := request_Grpc_GetByDate_0(rctx, inboundMarshaler, client, req, pathParams)
|
||||||
|
ctx = runtime.NewServerMetadataContext(ctx, md)
|
||||||
|
if err != nil {
|
||||||
|
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
forward_Grpc_GetByDate_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
|
||||||
|
|
||||||
|
})
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
var (
|
||||||
|
pattern_Grpc_Create_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0}, []string{"events"}, ""))
|
||||||
|
|
||||||
|
pattern_Grpc_Update_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 1, 0, 4, 1, 5, 1}, []string{"events", "ID"}, ""))
|
||||||
|
|
||||||
|
pattern_Grpc_Delete_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 1, 0, 4, 1, 5, 1}, []string{"events", "ID"}, ""))
|
||||||
|
|
||||||
|
pattern_Grpc_List_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0}, []string{"events"}, ""))
|
||||||
|
|
||||||
|
pattern_Grpc_GetByID_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 1, 0, 4, 1, 5, 1}, []string{"events", "ID"}, ""))
|
||||||
|
|
||||||
|
pattern_Grpc_GetByDate_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 1, 0, 4, 1, 5, 1, 1, 0, 4, 1, 5, 2}, []string{"events", "Range", "Date"}, ""))
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
forward_Grpc_Create_0 = runtime.ForwardResponseMessage
|
||||||
|
|
||||||
|
forward_Grpc_Update_0 = runtime.ForwardResponseMessage
|
||||||
|
|
||||||
|
forward_Grpc_Delete_0 = runtime.ForwardResponseMessage
|
||||||
|
|
||||||
|
forward_Grpc_List_0 = runtime.ForwardResponseMessage
|
||||||
|
|
||||||
|
forward_Grpc_GetByID_0 = runtime.ForwardResponseMessage
|
||||||
|
|
||||||
|
forward_Grpc_GetByDate_0 = runtime.ForwardResponseMessage
|
||||||
|
)
|
|
@ -13,7 +13,7 @@ import (
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
var conf = config.Config{Server: config.Server{Address: "localhost", Port: "50511"}, GRPC: config.Server{Address: "localhost", Port: "50512"}, Logger: config.Logger{File: "calendar.log", Level: "INFO", MuteStdout: false}, Storage: config.Storage{InMemory: true, SQLHost: "", SQLPort: "", SQLDbase: "", SQLUser: "", SQLPass: ""}}
|
var conf = config.Config{HTTP: config.Server{Address: "localhost", Port: "50511"}, GRPC: config.Server{Address: "localhost", Port: "50512"}, Logger: config.Logger{File: "calendar.log", Level: "INFO", MuteStdout: false}, Storage: config.Storage{InMemory: true, SQLHost: "", SQLPort: "", SQLDbase: "", SQLUser: "", SQLPass: ""}}
|
||||||
|
|
||||||
var storeConf = store.Config(conf.Storage)
|
var storeConf = store.Config(conf.Storage)
|
||||||
|
|
||||||
|
@ -41,13 +41,16 @@ func (suite *TestSuite) SetupTest() {
|
||||||
func (s *TestSuite) TestCreateEvent() {
|
func (s *TestSuite) TestCreateEvent() {
|
||||||
controlEvent := testEvt1
|
controlEvent := testEvt1
|
||||||
s.createEvent(&controlEvent)
|
s.createEvent(&controlEvent)
|
||||||
|
|
||||||
createdEvent := s.getEventByDate(controlEvent.Date)
|
createdEvent := s.getEventByDate(controlEvent.Date)
|
||||||
|
s.Require().GreaterOrEqual(len(createdEvent), 1)
|
||||||
s.Equal(&controlEvent, createdEvent[0])
|
s.Equal(&controlEvent, createdEvent[0])
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *TestSuite) TestUpdateEvent() {
|
func (s *TestSuite) TestUpdateEvent() {
|
||||||
oldEvent := testEvt1
|
oldEvent := testEvt1
|
||||||
s.createEvent(&oldEvent)
|
s.createEvent(&oldEvent)
|
||||||
|
|
||||||
newEvent := testEvt2
|
newEvent := testEvt2
|
||||||
s.updateEvent(oldEvent, newEvent)
|
s.updateEvent(oldEvent, newEvent)
|
||||||
updatedEvent := s.getEventByID(oldEvent.ID)
|
updatedEvent := s.getEventByID(oldEvent.ID)
|
||||||
|
@ -58,7 +61,9 @@ func (s *TestSuite) TestDeleteEvent() {
|
||||||
testEvent := testEvt1
|
testEvent := testEvt1
|
||||||
s.createEvent(&testEvent)
|
s.createEvent(&testEvent)
|
||||||
createdEvent := s.getEventByDate(testEvent.Date)
|
createdEvent := s.getEventByDate(testEvent.Date)
|
||||||
|
s.Require().GreaterOrEqual(len(createdEvent), 1)
|
||||||
s.Equal(&testEvent, createdEvent[0])
|
s.Equal(&testEvent, createdEvent[0])
|
||||||
|
|
||||||
s.deleteEvent(createdEvent[0].ID)
|
s.deleteEvent(createdEvent[0].ID)
|
||||||
controlEvent := s.getEventByDate(testEvent.Date)
|
controlEvent := s.getEventByDate(testEvent.Date)
|
||||||
s.Equal(0, len(controlEvent))
|
s.Equal(0, len(controlEvent))
|
||||||
|
@ -67,14 +72,16 @@ func (s *TestSuite) TestDeleteEvent() {
|
||||||
func (s *TestSuite) TestListEvent() {
|
func (s *TestSuite) TestListEvent() {
|
||||||
testEvent := testEvt1
|
testEvent := testEvt1
|
||||||
s.createEvent(&testEvent)
|
s.createEvent(&testEvent)
|
||||||
|
|
||||||
eventList := s.listEvents()
|
eventList := s.listEvents()
|
||||||
s.Equal(1, len(eventList))
|
s.GreaterOrEqual(len(eventList),1)
|
||||||
s.Equal(testEvt1.Title, eventList[0].Title)
|
s.Equal(testEvt1.Title, eventList[0].Title)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *TestSuite) TestGetEventByID() {
|
func (s *TestSuite) TestGetEventByID() {
|
||||||
testEvent := testEvt1
|
testEvent := testEvt1
|
||||||
s.createEvent(&testEvent)
|
s.createEvent(&testEvent)
|
||||||
|
|
||||||
eventList := s.getEventByID(testEvent.ID)
|
eventList := s.getEventByID(testEvent.ID)
|
||||||
s.Equal(testEvent.Title, eventList.Title)
|
s.Equal(testEvent.Title, eventList.Title)
|
||||||
}
|
}
|
||||||
|
@ -82,8 +89,9 @@ func (s *TestSuite) TestGetEventByID() {
|
||||||
func (s *TestSuite) TestGetEventByDate() {
|
func (s *TestSuite) TestGetEventByDate() {
|
||||||
testEvent := testEvt1
|
testEvent := testEvt1
|
||||||
s.createEvent(&testEvent)
|
s.createEvent(&testEvent)
|
||||||
|
|
||||||
eventList := s.getEventByDate(testEvent.Date)
|
eventList := s.getEventByDate(testEvent.Date)
|
||||||
s.Equal(1, len(eventList))
|
s.GreaterOrEqual(len(eventList),1)
|
||||||
s.Equal(testEvent.Title, eventList[0].Title)
|
s.Equal(testEvent.Title, eventList[0].Title)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,33 +0,0 @@
|
||||||
package http
|
|
||||||
|
|
||||||
import (
|
|
||||||
"net"
|
|
||||||
"net/http"
|
|
||||||
|
|
||||||
"github.com/tiburon-777/HW_OTUS/hw12_13_14_15_calendar/internal/app"
|
|
||||||
)
|
|
||||||
|
|
||||||
type Server struct {
|
|
||||||
server *http.Server
|
|
||||||
app app.App
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewServer(app *app.App, address string, port string) *Server {
|
|
||||||
return &Server{server: &http.Server{Addr: net.JoinHostPort(address, port), Handler: app.LoggingMiddleware(app.Handler)}, app: *app}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *Server) Start() error {
|
|
||||||
if err := s.server.ListenAndServe(); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
s.app.Logger.Infof("Server starting")
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *Server) Stop() error {
|
|
||||||
if err := s.server.Close(); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
s.app.Logger.Infof("Server stoped")
|
|
||||||
return nil
|
|
||||||
}
|
|
Loading…
Reference in New Issue