# Auto-generate Priest

What is Priest?

# Getting Started

The gone priest command scans for special comments in the code //go:gone to generate Priest functions. Currently, //go:gone is only used to mark functions in the form of func() gone.Goner and func() (gone.Goner, gone.GonerId). The functions must be exported (starting with a capital letter).

# 1. Install the gone auxiliary tool

Run the following command:

go install github.com/gone-io/gone/tools/gone@latest

For more information on gone, refer to the gone auxiliary tools documentation.

# 2. Write the Goner

Create a project and a file:

mkdir demo
cd demo
go mod init demo
touch demo.go

Edit the demo.go file with the following code:

package demo
import "github.com/gone-io/gone"
//go:gone
func NewDemo() gone.Goner {
    return &Demo{}
}
type Demo struct {
    gone.Flag
}

# 3. Generate code

Execute:

gone priest -s ./ -f Priest -o priest.go -p demo

This will generate the file priest.go with the following content:

// Code generated by gone; DO NOT EDIT.
package demo
import (
    "github.com/gone-io/gone"
)
func Priest(cemetery gone.Cemetery) error {
    cemetery.Bury(NewDemo())
    return nil
}

# Best Practices

  • Create a MasterPriest function for the Gone framework startup.
  • Call the Priest functions of project dependency packages in the MasterPriest function.
  • Place the "gone priest" command after the //go:generate comment in the MasterPriest function, for example:
package internal
import (
    "github.com/gone-io/gone"
    "github.com/gone-io/gone/goner"
)
//go:generate gone priest -s . -p $GOPACKAGE -f Priest -o priest.go
func MasterPriest(cemetery gone.Cemetery) error {
    // Call the Priest function of project dependency packages
    _ = goner.GinPriest(cemetery)
    // Call the generated Priest function
    _ = Priest(cemetery)
    return nil
}

tips: Running go generate ./... executes all commands following //go:generate comments.

  • Call the generated Priest function in the MasterPriest function.
  • Ignore the generated files in git by adding them to the .gitignore file.

Following this logic, we have created a reference Web blank project Demo (opens new window), which has been pushed to GitHub. Click to open it now. Additionally, you can run gone create web-app to generate a blank project, as explained in the Quick Start (opens new window) guide.