Skip to content

Instantly share code, notes, and snippets.

View amsokol's full-sized avatar

Aleksandr Sokolovskii amsokol

View GitHub Profile
@amsokol
amsokol / (Read method only) todo-service.proto
Last active September 15, 2018 05:27
How to develop Go gRPC microservice with HTTP/REST endpoint, middleware, Kubernetes deployment, etc.
syntax = "proto3";
package v1;
import "google/protobuf/timestamp.proto";
// Taks we have to do
message ToDo {
// Unique integer identifier of the todo task
int64 id = 1;
// Title of the task
protoc --proto_path=api/proto/v1 --proto_path=third_party --go_out=plugins=grpc:pkg/api/v1 todo-service.proto
syntax = "proto3";
package v1;
import "google/protobuf/timestamp.proto";
// Taks we have to do
message ToDo {
// Unique integer identifier of the todo task
int64 id = 1;
CREATE TABLE `ToDo` (
`ID` bigint(20) NOT NULL AUTO_INCREMENT,
`Title` varchar(200) DEFAULT NULL,
`Description` varchar(1024) DEFAULT NULL,
`Reminder` timestamp NULL DEFAULT NULL,
PRIMARY KEY (`ID`),
UNIQUE KEY `ID_UNIQUE` (`ID`)
);
package v1
import (
"context"
"database/sql"
"fmt"
"time"
"github.com/golang/protobuf/ptypes"
"google.golang.org/grpc/codes"
package grpc
import (
"context"
"log"
"net"
"os"
"os/signal"
"google.golang.org/grpc"
package main
import (
"fmt"
"os"
"github.com/amsokol/go-grpc-http-rest-microservice-tutorial/pkg/cmd"
)
func main() {
package main
import (
"context"
"flag"
"log"
"time"
"github.com/golang/protobuf/ptypes"
"google.golang.org/grpc"
package cmd
import (
"context"
"database/sql"
"flag"
"fmt"
// mysql driver
_ "github.com/go-sql-driver/mysql"
@amsokol
amsokol / (gRPC+REST) todo-service.proto
Last active September 15, 2018 08:29
(gRPC+REST) todo-service.proto
syntax = "proto3";
package v1;
import "google/protobuf/timestamp.proto";
import "google/api/annotations.proto";
import "protoc-gen-swagger/options/annotations.proto";
option (grpc.gateway.protoc_gen_swagger.options.openapiv2_swagger) = {
info: {
title: "ToDo service";