Skip to content

Commit

Permalink
blog service setup
Browse files Browse the repository at this point in the history
  • Loading branch information
simplesteph committed Nov 2, 2018
1 parent 5b949c7 commit 7ac4209
Show file tree
Hide file tree
Showing 5 changed files with 212 additions and 1 deletion.
Empty file added blog/blog_client/client.go
Empty file.
50 changes: 50 additions & 0 deletions blog/blog_server/server.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package main

import (
"fmt"
"log"
"net"
"os"
"os/signal"

"github.com/simplesteph/grpc-go-course/blog/blogpb"
"google.golang.org/grpc"
)

type server struct {
}

func main() {
// if we crash the go code, we get the file name and line number
log.SetFlags(log.LstdFlags | log.Lshortfile)

fmt.Println("Blog Service Started")

lis, err := net.Listen("tcp", "0.0.0.0:50051")
if err != nil {
log.Fatalf("Failed to listen: %v", err)
}

opts := []grpc.ServerOption{}
s := grpc.NewServer(opts...)
blogpb.RegisterBlogServiceServer(s, &server{})

go func() {
fmt.Println("Starting Server...")
if err := s.Serve(lis); err != nil {
log.Fatalf("failed to serve: %v", err)
}
}()

// Wait for Control C to exit
ch := make(chan os.Signal, 1)
signal.Notify(ch, os.Interrupt)

// Block until a signal is received
<-ch
fmt.Println("Stopping the server")
s.Stop()
fmt.Println("Closing the listener")
lis.Close()
fmt.Println("End of Program")
}
144 changes: 144 additions & 0 deletions blog/blogpb/blog.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions blog/blogpb/blog.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
syntax = "proto3";

package blog;

option go_package = "blogpb";

message Blog {
string id = 1;
string author_id = 2;
string title = 3;
string content = 4;
}

service BlogService {

}
3 changes: 2 additions & 1 deletion generate.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/bin/bash

protoc greet/greetpb/greet.proto --go_out=plugins=grpc:.
protoc calculator/calculatorpb/calculator.proto --go_out=plugins=grpc:.
protoc calculator/calculatorpb/calculator.proto --go_out=plugins=grpc:.
protoc blog/blogpb/blog.proto --go_out=plugins=grpc:.

0 comments on commit 7ac4209

Please sign in to comment.