Created
May 24, 2024 09:38
-
-
Save xieyuschen/02b9a8857caee6020a3315efa2238f28 to your computer and use it in GitHub Desktop.
Mockgen Generate Code for GRPC Interface
This file contains hidden or 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
Due to the method of `UnimplementedUserServiceServer` interface isn't exported, we need to run | |
the shell here to manipulate the generated file again: | |
```shell | |
sed -i '' '/type MockUserServiceServer struct {/,/}/ { | |
/type MockUserServiceServer struct {/!b | |
a\ | |
\tholepb.UnimplementedUserServiceServer | |
}' proto/mockedpb/api_grpc.pb.go | |
``` | |
This command will append the default unimplementation into the generated structure: | |
```diff | |
// MockUserServiceServer is a mock of UserServiceServer interface. | |
type MockUserServiceServer struct { | |
+ holepb.UnimplementedUserServiceServer | |
ctrl *gomock.Controller | |
recorder *MockUserServiceServerMockRecorder | |
} | |
``` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment