interfacer

command module
v0.0.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 3, 2022 License: Apache-2.0 Imports: 11 Imported by: 0

README

Interfacer

中文文档

Implement new methods in the interface everywhere

Tips: some problems may be encountered during use, as the tool is currently under development.

Have you ever encountered such a problem

When you add a method to an interface, the corresponding implementation cannot be found after adding the method. Because of the addition of an additional method, the previous implementations are all invalid. In general, adding a method to an interface is cumbersome and time-consuming.

Effect

effect

Getting started

install
go install github.com/SimFG/interfacer

Tips: If you use the windows, you can download the source code and build the tool.

Parameter description

There are two ways to set parameters, which are:

  1. yaml file
project_dir: "/Users/derek/fubang/interfacer/example/all"
project_module: "github.com/SimFG/interfacer/example/all"
interface_full_name: "github.com/SimFG/interfacer/example/all/i.Component"
new_method: "Hello(f int64) (int, error)"
return_default_values: "0,nil"
write_paths:
  - "github.com/SimFG/interfacer/example/proxy/all/s.Node,/Users/derek/xxx/interfacer/example/all/s/st.go"
exclude_dirs:
  - "foo"
enable_debug: false
enable_record: false
  1. command params
go run interfacer.go
    --project-dir=/Users/derek/fubang/interfacer/example/all
    --project-module=github.com/SimFG/interfacer/example/all 
    --interface=github.com/SimFG/interfacer/example/all/i.Component 
    --method="Hello(f int64) (int, error)" 
    --returns="0,nil"
  • project dir: full project dir
  • project module: it can be found in the go.mod file
  • interface: the interface you want to add a new method to it. And its full name is required
  • method: declaration of the newly added method
  • returns: the default return values of new method
  • exclude dirs: these dirs will be ignored
  • enable_debug: set true if you find a problem while using this tool, and the processing speed will slow because it needs to write a lot of logs to the files.
  • enable_record: set true if you want to get the relations between all structs and interfaces.
Source build
  1. clone the repository
git clone github.com/SimFG/interfacer
  1. run
go run interfacer.go

TODO

  • Dealing with generated code out of order of comments
    • for interface (done)
    • for struct method
  • Handle some special struct or interface
  • Check the input params
  • Exclude dirs or files
  • More readable codes
  • Debug mode, print the detail info (done)
  • More useful tool of reading and writing go file
  • customer the insert position
  • idea plugin

Documentation

The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL