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
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
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
@@ -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)
@@ -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 {
23 changes: 23 additions & 0 deletions cmd/builder/gen/config.go
Original file line number Diff line number Diff line change
@@ -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)
3 changes: 2 additions & 1 deletion cmd/builder/gen/filters.go
Original file line number Diff line number Diff line change
@@ -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("")),

Unchanged files with check annotations Beta

return cmd
}
func runRun(cmd *cobra.Command, args []string) {

Check warning on line 47 in cmd/builder/command/run.go

GitHub Actions / analysis

parameter 'cmd' seems to be unused, consider removing or renaming it as _

Check warning on line 47 in cmd/builder/command/run.go

GitHub Actions / analysis

parameter 'args' seems to be unused, consider removing or renaming it as _
ctx, stop := utils.WithInterrupt(context.Background())
defer stop()
}
// Inherit inherits previous generation of Fallback.
func (f *Fallback) Inherit(previousGeneration filters.Filter) {

Check warning on line 93 in pkg/filters/fallback/fallback.go

GitHub Actions / analysis

parameter 'previousGeneration' seems to be unused, consider removing or renaming it as _
f.Init()
}
s.profile.UpdateMemoryProfile(spr.Path)
}
func (s *Server) stopProfile(w http.ResponseWriter, r *http.Request) {

Check warning on line 126 in pkg/api/profile.go

GitHub Actions / analysis

parameter 'w' seems to be unused, consider removing or renaming it as _

Check warning on line 126 in pkg/api/profile.go

GitHub Actions / analysis

parameter 'r' seems to be unused, consider removing or renaming it as _
s.profile.Lock()
defer s.profile.Unlock()
}
}
func (s *Server) deleteAllCustomDataKind(w http.ResponseWriter, r *http.Request) {

Check warning on line 115 in pkg/api/customdata.go

GitHub Actions / analysis

parameter 'w' seems to be unused, consider removing or renaming it as _

Check warning on line 115 in pkg/api/customdata.go

GitHub Actions / analysis

parameter 'r' seems to be unused, consider removing or renaming it as _
err := s.cds.DeleteAllKinds()
if err != nil {
ClusterPanic(err)
// These methods which operate with cluster guarantee atomicity.
func (s *Server) listMembers(w http.ResponseWriter, r *http.Request) {

Check warning on line 57 in pkg/api/member.go

GitHub Actions / analysis

parameter 'r' seems to be unused, consider removing or renaming it as _
kv, err := s.cluster.GetPrefix(s.cluster.Layout().StatusMemberPrefix())
if err != nil {
ClusterPanic(err)
}
}
func (s *Server) readObjectSpec(w http.ResponseWriter, r *http.Request) (*supervisor.Spec, error) {

Check warning on line 114 in pkg/api/object.go

GitHub Actions / analysis

parameter 'w' seems to be unused, consider removing or renaming it as _
body, err := io.ReadAll(r.Body)
if err != nil {
return nil, fmt.Errorf("read body failed: %v", err)
}
// Inherit inherits previous generation of RemoteFilter.
func (rf *RemoteFilter) Inherit(previousGeneration filters.Filter) {

Check warning on line 163 in pkg/filters/remotefilter/remotefilter.go

GitHub Actions / analysis

parameter 'previousGeneration' seems to be unused, consider removing or renaming it as _
rf.Init()
}