envgen

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2023 License: GPL-3.0 Imports: 10 Imported by: 0

README

envgen

codebeat badge Go Report Card Go Doc Release

Utility to parse golang env structures into .env files.

Getting started

  1. Download swag by using:
go install github.com/Batyachelly/envgen/cmd/envgen@latest
  1. Run envgen in the project's root folder which contains a config files.
envgen -target=example/config.go -structs=Config,AnotherConfig1,AnotherConfig2 -output_dir example/generated

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidASTObjectType = errors.New("invalid type")

ErrInvalidASTObjectType ast object has a type different from the type declaration.

Functions

func DefaultMarshal

func DefaultMarshal(envs []Env) []byte

DefaultMarshal default marshal function.

Types

type Env

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

type EnvFile

type EnvFile struct {
	Envs []Env
}

type EnvFiles

type EnvFiles map[string]EnvFile

func (EnvFiles) Save

func (efs EnvFiles) Save(outputDir string) error

Save saves parsed environment variables to files using the DefaultMarshal.

func (EnvFiles) SaveWithCustomMarshal

func (efs EnvFiles) SaveWithCustomMarshal(outputDir string, marshal func([]Env) []byte) error

SaveWithCustomMarshal saves parsed environment variables to files using the received function.

type EnvParser

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

EnvParser implement envs parsing from .go file.

func NewParserFromASTObjects

func NewParserFromASTObjects(objects map[string]*ast.Object) EnvParser

NewParserFromASTObjects creates a new parser based on the AST object map.

func NewParserFromFile

func NewParserFromFile(filePath string) (EnvParser, error)

NewParserFromFile creates a new parser based on the .go file.

func NewParserFromReader

func NewParserFromReader(r io.Reader) (EnvParser, error)

NewParserFromReader creates a new parser based on data from the io.Reader.

func (EnvParser) FindStructs

func (ep EnvParser) FindStructs(targetStructs []string) (EnvParser, error)

FindStructs filters structures leaving only those specified in the argument.

func (EnvParser) ParseFields

func (ep EnvParser) ParseFields() EnvFiles

ParseFields parse structs to EnvFiles.

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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