Socket
Socket
Sign inDemoInstall

github.com/swipe-io/swipe/v2

Package Overview
Dependencies
18
Alerts
File Explorer

Install Socket

Detect and block malicious and high-risk dependencies

Install

    github.com/swipe-io/swipe/v2


Version published

Readme

Source

package generator

import ( "context" "html/template" "io/ioutil" "os" "path/filepath"

"github.com/swipe-io/swipe/v2/internal/git"
"github.com/swipe-io/swipe/v2/internal/usecase/generator"
"github.com/swipe-io/swipe/v2/internal/writer"

)

const defaultTemplate = `# {{.ServiceName}} : A short description of the service. {{ .GIT.LastTag.Name }} A complete description of the service and what it does.

Example

go run ./cmd/service

Docs

ToDo.

Contributing

ToDo.

Contributors

ToDo.

Author

ToDo.

Changelog

ToDo.

Versions

{{range $index, $tag := .GIT.Tags -}} {{if gt $index 0 -}}, {{end -}} {{$tag.Name}} {{end -}} `

type readmeGeneratorOptionsGateway interface { AppID() string AppName() string JSONRPCDocOutput() string ReadmeOutput() string ReadmeTemplatePath() string }

type readmeGenerator struct { writer.BaseWriter options readmeGeneratorOptionsGateway basePkgPath string outputDir string workDir string gitTags []git.Tag markdownOutput string tpl *template.Template }

func (g *readmeGenerator) Prepare(ctx context.Context) (err error) { g.outputDir, err = filepath.Abs(filepath.Join(g.workDir, g.options.ReadmeOutput())) if err != nil { return err } g.markdownOutput, err = filepath.Abs(filepath.Join(g.workDir, g.options.JSONRPCDocOutput())) if err != nil { return err } var templatePath string if templatePath == "" { templatePath, err = filepath.Abs(filepath.Join(g.workDir, ".swipe")) if err != nil { return err } if _, err := os.Stat(templatePath); err != nil { if err = os.MkdirAll(templatePath, 0755); err != nil { return err } } } else { templatePath, err = filepath.Abs(filepath.Join(g.workDir, g.options.ReadmeTemplatePath())) if err != nil { return err } } templateFilepath := filepath.Join(templatePath, "README.md.tpl") if _, err := os.Stat(templateFilepath); err != nil { err = ioutil.WriteFile(templateFilepath, []byte(defaultTemplate), 0755) if err != nil { return err } } data, err := ioutil.ReadFile(templateFilepath) if err != nil { return err } t, err := template.New("readmeGenerator").Parse(string(data)) if err != nil { return err } g.tpl = t return nil }

func (g *readmeGenerator) Process(ctx context.Context) (err error) { return g.tpl.Execute(g, map[string]interface{}{ "ID": g.options.AppID(), "ServiceName": g.options.AppName(), "PkgPath": g.basePkgPath, "GIT": map[string]interface{}{ "Tags": g.gitTags, }, }) }

func (g *readmeGenerator) PkgName() string { return "" }

func (g *readmeGenerator) OutputDir() string { return g.outputDir }

func (g *readmeGenerator) Filename() string { return "README.md" }

func NewReadme( options readmeGeneratorOptionsGateway, basePkgPath string, workDir string, gitTags []git.Tag, ) generator.Generator { return &readmeGenerator{ options: options, basePkgPath: basePkgPath, workDir: workDir, gitTags: gitTags, } }

FAQs

Last updated on 23 Mar 2021

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc