-
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.
- Loading branch information
Showing
1 changed file
with
52 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
# stubgen | ||
|
||
A Golang library for generating interface stubs. | ||
|
||
## Installation | ||
|
||
```shell | ||
go install github.com/Gamazic/stubgen@latest | ||
``` | ||
|
||
## Example | ||
|
||
For example, we have go module with the following content: | ||
|
||
`testfile.go` | ||
```go | ||
package main | ||
|
||
type MyInterface interface { | ||
Method(id int) error | ||
} | ||
``` | ||
|
||
To generate stub for the file use command with arg `--inp-file`: | ||
|
||
```shell | ||
go run stubgen --inp-file testdata/testfile.go | ||
``` | ||
|
||
Result: | ||
|
||
```go | ||
type StubMyInterface struct { | ||
AnotherFuncRes0 error | ||
} | ||
|
||
func (s StubMyInterface) AnotherFunc(_ int, _ bool) error { | ||
return s.AnotherFuncRes0 | ||
} | ||
``` | ||
|
||
Alternatively, you can provide source code from stdin: | ||
|
||
```shell | ||
cat testdata/testfile.go | go run stubgen | ||
``` | ||
|
||
To save data in a file use the `--out-file` arg: | ||
|
||
```shell | ||
go run stubgen --inp-file testdata/testfile.go --out-file interface.go | ||
``` |