github.com/uppal0016/docker_new@v0.0.0-20240123060250-1c98be13ac2c/pkg/plugins/pluginrpc-gen/README.md (about)

     1  Plugin RPC Generator
     2  ====================
     3  
     4  Generates go code from a Go interface definition for proxying between the plugin
     5  API and the subsystem being extended.
     6  
     7  ## Usage
     8  
     9  Given an interface definition:
    10  
    11  ```go
    12  type volumeDriver interface {
    13  	Create(name string, opts opts) (err error)
    14  	Remove(name string) (err error)
    15  	Path(name string) (mountpoint string, err error)
    16  	Mount(name string) (mountpoint string, err error)
    17  	Unmount(name string) (err error)
    18  }
    19  ```
    20  
    21  **Note**: All function options and return values must be named in the definition.
    22  
    23  Run the generator:
    24  
    25  ```bash
    26  $ pluginrpc-gen --type volumeDriver --name VolumeDriver -i volumes/drivers/extpoint.go -o volumes/drivers/proxy.go
    27  ```
    28  
    29  Where:
    30  - `--type` is the name of the interface to use
    31  - `--name` is the subsystem that the plugin "Implements"
    32  - `-i` is the input file containing the interface definition
    33  - `-o` is the output file where the the generated code should go
    34  
    35  **Note**: The generated code will use the same package name as the one defined in the input file
    36  
    37  Optionally, you can skip functions on the interface that should not be
    38  implemented in the generated proxy code by passing in the function name to `--skip`.
    39  This flag can be specified multiple times.
    40  
    41  You can also add build tags that should be prepended to the generated code by
    42  supplying `--tag`. This flag can be specified multiple times.
    43  
    44  ## Known issues
    45  
    46  The parser can currently only handle types which are not specifically a map or
    47  a slice.  
    48  You can, however, create a type that uses a map or a slice internally, for instance:
    49  
    50  ```go
    51  type opts map[string]string
    52  ```
    53  
    54  This `opts` type will work, whreas using a `map[string]string` directly will not.
    55  
    56  ## go-generate
    57  
    58  You can also use this with go-generate, which is pretty awesome.  
    59  To do so, place the code at the top of the file which contains the interface
    60  definition (i.e., the input file):
    61  
    62  ```go
    63  //go:generate pluginrpc-gen -i $GOFILE -o proxy.go -type volumeDriver -name VolumeDriver
    64  ```
    65  
    66  Then cd to the package dir and run `go generate`
    67  
    68  **Note**: the `pluginrpc-gen` binary must be within your `$PATH`