gosod

package module
v1.0.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 29, 2021 License: MIT Imports: 2 Imported by: 53

README


Scaffolding simplified

CodeFactor CodeFactor

Features:

  • Scaffold out project directories from templates
  • Uses Go's native templating engine
  • Uses fs.FS for input, so it works well with go:embed and debme
  • Go alternative to cookiecutter

Installation

go get github.com/leaanthony/gosod

Usage

  1. Define a template directory
  2. Define some data
  3. Extract to a target directory
package main

import (
	"log"

	"github.com/leaanthony/gosod"
)

type config struct {
	Name string
}


// mytemplate/
// ├── custom.filtername.txt
// ├── ignored.txt
// ├── subdir
// │   ├── included.txt
// │   └── sub.tmpl.go
// └── test.tmpl.go
//go:embed mytemplate/*
var mytemplate embed.FS

func main() {

	// Define a new Template directory
	basic, err := gosod.New(mytemplate)
	if err != nil {
		log.Fatal(err)
	}

	// Make some config data
	myConfig := &config{
		Name: "Mat",
	}
		
	// Ignore files
	basic.IgnoreFile("ignored.txt")
	
	// Custom template filters
	basic.SetTemplateFilters([]string{ ".filtername", ".tmpl" })

	// Create a new directory using the template and config
	err = basic.Extract("./generated", myConfig)
	if err != nil {
		log.Fatal(err)
	}
	
	// Ouput FS:
	// generated/
	// ├── custom.txt
	// ├── subdir
	// │   ├── included.txt
	// │   └── sub.go
	// └── test.go
}

Template Directories

A template directory is simply a directory structure contianing files you wish to copy. The algorithm for copying is:

  • Categorise all files into one of: directory, standard file and template files
    • Create the directory structure
    • Copy standard files
    • Copy template files, assembled using the given data

Template files, by default, are any file with ".tmpl" in their filename. To change this, use SetTemplateFilters([]string). This allows you to set any number of filters.

Files may also be ignored by using the IgnoreFilename(string) method.

What's with the name?

Google is your friend

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New added in v1.0.0

func New(fs fs.FS) *templatedir.TemplateDir

New creates a new TemplateDir structure for the given filesystem

Types

This section is empty.

Directories

Path Synopsis
examples
internal

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL