This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type BlogServiceServer interface { | |
CreateBlog(context.Context, *CreateBlogReq) (*CreateBlogRes, error) | |
ReadBlog(context.Context, *ReadBlogReq) (*ReadBlogRes, error) | |
UpdateBlog(context.Context, *UpdateBlogReq) (*UpdateBlogRes, error) | |
DeleteBlog(context.Context, *DeleteBlogReq) (*DeleteBlogRes, error) | |
ListBlogs(*ListBlogsReq, BlogService_ListBlogsServer) error | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func main() { | |
// STEP 1, STEP 2, STEP 3 | |
// ... | |
// Start the server in a child routine | |
go func() { | |
if err := s.Serve(listener); err != nil { | |
log.Fatalf("Failed to serve: %v", err) | |
} | |
}() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Global variables for db connection , collection and context | |
var db *mongo.Client | |
var blogdb *mongo.Collection | |
var mongoCtx context.Context | |
func main { | |
// STEP 1 & STEP 2 | |
// STEP 3 (gRPC server) | |
// ... | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import ( | |
// other imports ... | |
blogpb "../proto" | |
// ... | |
) | |
type BlogServiceServer struct {} | |
func main() { | |
// STEP 1 & STEP 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func main() { | |
// Configure 'log' package to give file name and line number on eg. log.Fatal | |
// Pipe flags to one another (log.LstdFLags = log.Ldate | log.Ltime) | |
log.SetFlags(log.LstdFlags | log.Lshortfile) | |
fmt.Println("Starting server on port :50051...") | |
// Start our listener, 50051 is the default gRPC port | |
listener, err := net.Listen("tcp", ":50051") | |
// Handle errors if any | |
if err != nil { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
syntax = "proto3"; | |
package blog; | |
option go_package = "blogpb"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
message ListBlogsRequest {} | |
message ListBlogsResponse { | |
Blog blog = 1; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
message DeleteBlogReq { | |
string id = 1; | |
} | |
message DeleteBlogRes { | |
bool success = 1; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
message UpdateBlogReq { | |
Blog blog = 1; | |
} | |
message UpdateBlogRes { | |
Blog blog = 1; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
message ReadBlogReq { | |
string id = 1; | |
} | |
message ReadBlogRes { | |
Blog blog = 1; | |
} |