forked from xmlking/grpc-starter-kit
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(account): account tested with native gRPC
- Loading branch information
Showing
51 changed files
with
998 additions
and
17,862 deletions.
There are no files selected for viewing
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
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
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
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
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,45 @@ | ||
package micro | ||
|
||
|
||
|
||
import ( | ||
"net" | ||
|
||
"github.com/pkg/errors" | ||
"github.com/soheilhy/cmux" | ||
"google.golang.org/grpc/grpclog" | ||
) | ||
|
||
type MicroServer struct { | ||
mux cmux.CMux | ||
lis net.Listener | ||
} | ||
type Interface interface { | ||
Serve(l net.Listener) error | ||
Shutdown() | ||
} | ||
|
||
func NewService(mux cmux.CMux, lis net.Listener) Interface { | ||
return &MicroServer{ | ||
mux: mux, | ||
lis: lis, | ||
} | ||
} | ||
// Serve implements Server.Serve | ||
func (s *MicroServer) Serve(net.Listener) error { | ||
grpclog.Info("mux is starting %s", s.lis.Addr()) | ||
|
||
err := s.mux.Serve() | ||
|
||
grpclog.Infof("mux is closed: %v", err) | ||
|
||
return errors.Wrap(err, "failed to serve cmux server") | ||
} | ||
|
||
// Shutdown implements Server.Shutdown | ||
func (s *MicroServer) Shutdown() { | ||
err := s.lis.Close() | ||
if err != nil { | ||
grpclog.Errorf("failed to close cmux's listener: %v", err) | ||
} | ||
} |
Oops, something went wrong.