github.com/wawandco/oxpecker@v1.5.7-0.20210910201653-5958d4afdd89/tools/buffalo/app/initializer.go (about)

     1  package app
     2  
     3  import (
     4  	"context"
     5  	"embed"
     6  	"errors"
     7  	"path/filepath"
     8  
     9  	"github.com/wawandco/oxpecker/internal/source"
    10  	"github.com/wawandco/oxpecker/lifecycle/new"
    11  )
    12  
    13  var (
    14  	//go:embed templates
    15  	templates embed.FS
    16  
    17  	ErrIncompleteArgs = errors.New("incomplete args")
    18  )
    19  
    20  // Initializer
    21  type Initializer struct{}
    22  
    23  func (i Initializer) Name() string {
    24  	return "model/initializer"
    25  }
    26  
    27  func (i *Initializer) Initialize(ctx context.Context, options new.Options) error {
    28  	appGo, err := templates.ReadFile("templates/app.go.tmpl")
    29  	if err != nil {
    30  		return err
    31  	}
    32  
    33  	err = source.Build(filepath.Join(options.Folder, "app", "app.go"), string(appGo), options)
    34  	if err != nil {
    35  		return err
    36  	}
    37  
    38  	routesGo, err := templates.ReadFile("templates/routes.go.tmpl")
    39  	if err != nil {
    40  		return err
    41  	}
    42  
    43  	err = source.Build(filepath.Join(options.Folder, "app", "routes.go"), string(routesGo), options)
    44  	if err != nil {
    45  		return err
    46  	}
    47  
    48  	return nil
    49  }