-
Notifications
You must be signed in to change notification settings - Fork 321
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5b949c7
commit 7ac4209
Showing
5 changed files
with
212 additions
and
1 deletion.
There are no files selected for viewing
Empty file.
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
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") | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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 { | ||
|
||
} |
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
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:. |