writer

package
v0.0.0-...-5afa41d Latest Latest
Warning

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

Go to latest
Published: Aug 20, 2023 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CompileAndWrite

func CompileAndWrite(
	ctx context.Context,
	path string,
	filename string,
	tmpl string,
	data interface{},
) error

CompileAndWrite will compile the given template, autoformat and write to file

func FuncMap

func FuncMap() template.FuncMap

FuncMap returns a map of functions to be used for template generation

Types

type GoWriter

type GoWriter struct {
	*TextWriter
}

GoWriter formats and writes go code It overrides Compile and Write functions of TextWriter

func NewGoWriter

func NewGoWriter(path, file string) *GoWriter

NewGoWriter is the constructor for GoWriter

func (*GoWriter) Format

func (w *GoWriter) Format(ctx context.Context) error

Format formats gocode using gofmt and goimports

type IWriter

type IWriter interface {
	Compile(context.Context, string, interface{}) error
	Format(context.Context) error
	Write(context.Context) error
}

IWriter implements a code writer

func GetWriter

func GetWriter(path, filename string) IWriter

GetWriter is a factory method for writers

type TextWriter

type TextWriter struct {
	// contains filtered or unexported fields
}

TextWriter writes any text files

func NewTextWriter

func NewTextWriter(path, filename, header string) *TextWriter

NewTextWriter returns an instance of TextWriter

func (*TextWriter) Compile

func (w *TextWriter) Compile(ctx context.Context, tmpl string, data interface{}) error

Compile should compile the template and get the code as bytes

func (*TextWriter) Format

func (*TextWriter) Format(ctx context.Context) error

Format is supposed to format the code, as text formatter can be any type of code we cant implement any formatter. This leave as an empty function to implement Writer interface

func (*TextWriter) Write

func (w *TextWriter) Write(ctx context.Context) error

Write will write contents to given file

type Type

type Type int

Type will be used to define enums for code types

const (
	// TypeGoCode writes go source code
	TypeGoCode Type = iota
	// TypeText writes any text file, this will be used as a common code
	// writers for all types which does not have any formatter available
	TypeText
)

Jump to

Keyboard shortcuts

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