Skip to content

Commit

Permalink
example: example/grpc update
Browse files Browse the repository at this point in the history
  • Loading branch information
dapeng committed Jun 19, 2024
1 parent a095015 commit 5622a8d
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 30 deletions.
8 changes: 2 additions & 6 deletions example/grpc/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,13 @@
.PHONY: client

pb:
make dep
go install google.golang.org/protobuf/cmd/protoc-gen-go@latest
go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest
protoc --go_out=. --go_opt=paths=source_relative \
--go-grpc_out=. --go-grpc_opt=paths=source_relative \
proto/hello.proto


dep:
go get google.golang.org/protobuf/cmd/protoc-gen-go
go install google.golang.org/protobuf/cmd/protoc-gen-go
go get google.golang.org/grpc/cmd/protoc-gen-go-grpc
go install google.golang.org/grpc/cmd/protoc-gen-go-grpc

server:
go run server/main.go
Expand Down
31 changes: 16 additions & 15 deletions example/grpc/client/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,21 @@ func (c *helloClient) Stub(conn *grpc.ClientConn) {
}

func main() {
gone.Prepare(func(cemetery gone.Cemetery) error {
_ = goner.BasePriest(cemetery)
_ = goner.GrpcClientPriest(cemetery)
gone.
Prepare(func(cemetery gone.Cemetery) error {
_ = goner.GrpcClientPriest(cemetery)

cemetery.Bury(&helloClient{})
return nil
}).AfterStart(func(in struct {
hello *helloClient `gone:"*"`
}) {
say, err := in.hello.Say(context.Background(), &proto.SayRequest{Name: "gone"})
if err != nil {
log.Printf("er:%v", err)
return
}
log.Printf("say result: %s", say.Message)
}).Run()
cemetery.Bury(&helloClient{})
return nil
}).
Run(func(in struct {
hello *helloClient `gone:"*"`
}) {
say, err := in.hello.Say(context.Background(), &proto.SayRequest{Name: "gone"})
if err != nil {
log.Printf("er:%v", err)
return
}
log.Printf("say result: %s", say.Message)
})
}
15 changes: 8 additions & 7 deletions example/grpc/server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,13 @@ func (s *server) RegisterGrpcServer(server *grpc.Server) {
}

func main() {
gone.Prepare(func(cemetery gone.Cemetery) error {
_ = goner.BasePriest(cemetery)
_ = cmux.Priest(cemetery)
_ = goner.GrpcServerPriest(cemetery)
gone.
Prepare(func(cemetery gone.Cemetery) error {
_ = cmux.Priest(cemetery)
_ = goner.GrpcServerPriest(cemetery)

cemetery.Bury(&server{})
return nil
}).Serve()
cemetery.Bury(&server{})
return nil
}).
Serve()
}
5 changes: 4 additions & 1 deletion goner/logrus/priest.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ import (
func Priest(cemetery gone.Cemetery) error {
t := cemetery.GetTomById(gone.IdGoneLogger)
if t != nil && t.GetGoner().(gone.Logger) != gone.GetSimpleLogger() {
t.GetGoner().(gone.Logger).Warn("logger is loaded, logrus logger not used")
_, ok := t.GetGoner().(*logger)
if !ok {
t.GetGoner().(gone.Logger).Warn("logger is loaded, logrus logger not used")

Check warning on line 14 in goner/logrus/priest.go

View check run for this annotation

Codecov / codecov/patch

goner/logrus/priest.go#L12-L14

Added lines #L12 - L14 were not covered by tests
}
return nil
}
_ = config.Priest(cemetery)
Expand Down
5 changes: 4 additions & 1 deletion goner/zap/priest.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ import (
func Priest(cemetery gone.Cemetery) error {
t := cemetery.GetTomById(gone.IdGoneLogger)
if t != nil && t.GetGoner().(gone.Logger) != gone.GetSimpleLogger() {
t.GetGoner().(gone.Logger).Warn("logger is loaded, zap logger not used")
_, ok := t.GetGoner().(*sugar)
if !ok {
t.GetGoner().(gone.Logger).Warn("logger is loaded, zap logger not used")

Check warning on line 14 in goner/zap/priest.go

View check run for this annotation

Codecov / codecov/patch

goner/zap/priest.go#L14

Added line #L14 was not covered by tests
}
return nil
}

Expand Down

0 comments on commit 5622a8d

Please sign in to comment.