Skip to content

gohugoio/hugoreleaser-plugins-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.