Skip to content

Latest commit

 

History

History
43 lines (36 loc) · 1.75 KB

README.md

File metadata and controls

43 lines (36 loc) · 1.75 KB

Tests on Linux, MacOS and Windows Go Report Card GoDoc

Plugins API for https://github.com/gohugoio/hugoreleaser

A plugin is a Go Module with a main func, e.g., using the API provided by the archiveplugin package:

func main() {
	var archiveClient archiveClient
	server, err := server.New(
		server.Options[model.Config, archiveplugin.Request, any, model.Receipt]{
			Init: func(c model.Config, prococol execrpc.ProtocolInfo) error {
				archiveClient.cfg = c
				return nil
			},
			Handle: func(call *execrpc.Call[archiveplugin.Request, any, model.Receipt]) {
				model.Infof(call, "Creating archive %s", call.Request.OutFilename)
				var receipt model.Receipt
				if !archiveClient.cfg.Try {
					if err := archiveClient.createArchive(call.Request); err != nil {
						receipt.Error = model.NewError(name, err)
					}
				}
				receipt = <-call.Receipt()
				call.Close(false, receipt)
			},
		},
	)
	if err != nil {
		log.Fatalf("Failed to create server: %s", err)
	}

	if err := server.Start(); err != nil {
		log.Fatalf("Failed to start server: %s", err)
	}
}

See the Deb Plugin for a more complete example.