Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

optim egbuilder to provide build.yaml and corrent filter comments #1247

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 9 additions & 0 deletions cmd/builder/command/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ func initRun(cmd *cobra.Command, args []string) {
utils.ExitWithErrorf("directory %s is not empty, please call init in an empty directory", cwd)
}

initBuildYaml(cmd, cwd)
initGenerateFiles(cmd, cwd)
initGenerateMod(ctx, cmd)
err = initConfig.Save(cwd)
Expand All @@ -99,6 +100,14 @@ func initRun(cmd *cobra.Command, args []string) {
}
}

func initBuildYaml(_ *cobra.Command, cwd string) {
err := initConfig.GenBuildYaml(cwd)
if err != nil {
utils.ExitWithError(err)
}
fmt.Println("generate build.yaml success")
}

func initGenerateFiles(_ *cobra.Command, cwd string) {
err := initConfig.GenFilters(cwd)
if err != nil {
Expand Down
23 changes: 23 additions & 0 deletions cmd/builder/gen/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,29 @@ func (c *Config) CheckDuplicate(conf *Config) error {
return nil
}

func (c *Config) GenBuildYaml(dir string) error {
buildYaml := `
# egVersion: the version of Easegress used for building. Supports versions v2.5.2 and later.
# An empty egVersion value means using the latest version of Easegress.
egVersion: ""

# plugins: custom plugins.
# It is recommended to use plugins created with "egbuilder init".
# Generally, any plugin containing "registry/registry.go" can utilize the "egbuilder build" command.
# You can initialize a project to see for yourself.
plugins:
- module: %s
version: ""
replacement: "."

# output: path of output file.
output: "./easegress-server"
`
buildYaml = fmt.Sprintf(buildYaml, c.Repo)
fileName := path.Join(dir, "build.yaml")
return os.WriteFile(fileName, []byte(buildYaml), os.ModePerm)
}

func (c *Config) GenFilters(dir string) error {
for _, f := range c.Filters {
err := os.MkdirAll(getModulePath(dir, moduleFilter, f, false), os.ModePerm)
Expand Down
3 changes: 2 additions & 1 deletion cmd/builder/gen/filters.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,8 @@ func defineFilterMethods(file *j.File, info *FilterInfo) {
handleFunc.Params = []j.Code{j.Id("ctx").Op("*").Qual(egContext, "Context")}
handleFunc.Returns = []j.Code{j.String()}
handleFunc.Block = []j.Code{
j.Comment("hint: req := ctx.GetRequest().(*httpprot.Request)"),
j.Comment("hint: req := ctx.GetInputRequest().(*httpprot.Request)"),
j.Comment("hint: use req.HTTPHeader() to get the http headers"),
j.Comment("empty string means success"),
j.Comment(yourCodeHere),
j.Return(j.Lit("")),
Expand Down