Movatterモバイル変換


[0]ホーム

URL:


plugin

package
v0.20.0Latest Latest
Warning

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

Go to latest
Published: Apr 4, 2025 License:MITImports:9Imported by:2

Details

Repository

github.com/terraform-docs/terraform-docs

Links

Documentation

Overview

Package plugin contains the implementations needed to makethe built binary act as a plugin.

A plugin is implemented as an RPC server and the host actsas the client, sending analysis requests to the plugin.Note that the server-client relationship here is the opposite ofthe communication that takes place during the checking phase.

Implementation details are hidden in go-plugin. This package isessentially a wrapper for go-plugin.

Usage

A simple plugin can look like this:

package mainimport (    _ "embed" //nolint    "github.com/terraform-docs/terraform-docs/plugin"    "github.com/terraform-docs/terraform-docs/print"    "github.com/terraform-docs/terraform-docs/template"    "github.com/terraform-docs/terraform-docs/terraform")func main() {    plugin.Serve(&plugin.ServeOpts{        Name:    "template",        Version: "0.1.0",        Printer: printerFunc,    })}//go:embed sections.tmplvar tplCustom []byte// printerFunc the function being executed by the plugin client.func printerFunc(config *print.Config, module *terraform.Module) (string, error) {    tpl := template.New(config,        &template.Item{Name: "custom", Text: string(tplCustom)},    )    rendered, err := tpl.Render("custom", module)    if err != nil {        return "", err    }    return rendered, nil}

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

funcNewClient

func NewClient(opts *ClientOpts) *goplugin.Client

NewClient is a wrapper of plugin.NewClient.

funcServe

func Serve(opts *ServeOpts)

Serve is a wrapper of plugin.Serve. This is entrypoint of all plugins.

Types

typeClient

type Client struct {// contains filtered or unexported fields}

Client is an RPC Client for the host.

func (*Client)Execute

func (c *Client) Execute(args *ExecuteArgs) (string,error)

Execute calls the server-side Execute method and returns generated output.

func (*Client)Name

func (c *Client) Name() (string,error)

Name calls the server-side Name method and returns its version.

func (*Client)Version

func (c *Client) Version() (string,error)

Version calls the server-side Version method and returns its version.

typeClientOpts

type ClientOpts struct {Cmd *exec.Cmd}

ClientOpts is an option for initializing a Client.

typeExecuteArgs

type ExecuteArgs struct {Module *terraform.ModuleConfig *print.Config}

ExecuteArgs is the collection of arguments being sent by terraform-docscore while executing the plugin command.

typeServeOpts

type ServeOpts struct {NamestringVersionstringPrinter printFunc}

ServeOpts is an option for serving a plugin.

typeServer

type Server struct {// contains filtered or unexported fields}

Server is an RPC Server acting as a plugin.

func (*Server)Execute

func (s *Server) Execute(args *ExecuteArgs, resp *string)error

Execute returns the generated output.

func (*Server)Name

func (s *Server) Name(args interface{}, resp *string)error

Name returns the version of the plugin.

func (*Server)Version

func (s *Server) Version(args interface{}, resp *string)error

Version returns the version of the plugin.

Source Files

View all Source files

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f orF : Jump to
y orY : Canonical URL
go.dev uses cookies from Google to deliver and enhance the quality of its services and to analyze traffic.Learn more.

[8]ページ先頭

©2009-2025 Movatter.jp