1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00
moby--moby/pkg/plugins/pluginrpc-gen
Sebastiaan van Stijn 4203a97aad
staticcheck: ignore "SA1019: strings.Title is deprecated"
This function is marked deprecated in Go 1.18; however, the suggested replacement
brings in a large amount of new code, and most strings we generate will be ASCII,
so this would only be in case it's used for some user-provided string. We also
don't have a language to use, so would be using the "default".

Adding a `//nolint` comment to suppress the linting failure instead.

    daemon/logger/templates/templates.go:23:14: SA1019: strings.Title is deprecated: The rule Title uses for word boundaries does not handle Unicode punctuation properly. Use golang.org/x/text/cases instead. (staticcheck)
        "title":    strings.Title,
                    ^
    pkg/plugins/pluginrpc-gen/template.go:67:9: SA1019: strings.Title is deprecated: The rule Title uses for word boundaries does not handle Unicode punctuation properly. Use golang.org/x/text/cases instead. (staticcheck)
        return strings.Title(s)
               ^

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2022-03-16 12:11:54 +01:00
..
fixtures Add canonical import comment 2018-02-05 16:51:57 -05:00
main.go refactor: move from io/ioutil to io and os package 2021-08-27 14:56:57 +08:00
parser.go
parser_test.go Spelling fixes 2017-07-03 13:13:09 -07:00
README.md
template.go staticcheck: ignore "SA1019: strings.Title is deprecated" 2022-03-16 12:11:54 +01:00

Plugin RPC Generator

Generates go code from a Go interface definition for proxying between the plugin API and the subsystem being extended.

Usage

Given an interface definition:

type volumeDriver interface {
	Create(name string, opts opts) (err error)
	Remove(name string) (err error)
	Path(name string) (mountpoint string, err error)
	Mount(name string) (mountpoint string, err error)
	Unmount(name string) (err error)
}

Note: All function options and return values must be named in the definition.

Run the generator:

$ pluginrpc-gen --type volumeDriver --name VolumeDriver -i volumes/drivers/extpoint.go -o volumes/drivers/proxy.go

Where:

  • --type is the name of the interface to use
  • --name is the subsystem that the plugin "Implements"
  • -i is the input file containing the interface definition
  • -o is the output file where the generated code should go

Note: The generated code will use the same package name as the one defined in the input file

Optionally, you can skip functions on the interface that should not be implemented in the generated proxy code by passing in the function name to --skip. This flag can be specified multiple times.

You can also add build tags that should be prepended to the generated code by supplying --tag. This flag can be specified multiple times.

Known issues

go-generate

You can also use this with go-generate, which is pretty awesome.
To do so, place the code at the top of the file which contains the interface definition (i.e., the input file):

//go:generate pluginrpc-gen -i $GOFILE -o proxy.go -type volumeDriver -name VolumeDriver

Then cd to the package dir and run go generate

Note: the pluginrpc-gen binary must be within your $PATH