Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save xieyuschen/02b9a8857caee6020a3315efa2238f28 to your computer and use it in GitHub Desktop.
Save xieyuschen/02b9a8857caee6020a3315efa2238f28 to your computer and use it in GitHub Desktop.
Mockgen Generate Code for GRPC Interface
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