config

package
v0.0.7 Latest Latest
Warning

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

Go to latest
Published: Apr 25, 2024 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ConfigFile string

The filepath to the config file which will be used by ParseFile to load the configuration. If not provided ParseFile will look for a config file in the caller's git project root.

NOTE This value is set by the ParseFlags method.

View Source
var DefaultConfig = Config{
	WorkingDirectory:         String{Value: "."},
	Recursive:                Bool{Value: false},
	InputFiles:               StringSlice{},
	InputFileRegexps:         StringSlice{},
	OutputFileNameFormat:     String{Value: "%s_gosql.go"},
	DatabaseDSN:              String{Value: ""},
	QuoteIdentifiers:         Bool{Value: false},
	FilterColumnKeyTag:       String{Value: "json"},
	FilterColumnKeyBase:      Bool{Value: false},
	FilterColumnKeySeparator: String{Value: "."},
	MethodName:               String{Value: "Exec"},
	MethodWithContext:        Bool{Value: false},
	MethodArgumentType: GoType{
		Name:    "Conn",
		PkgPath: "github.com/frk/gosql",
		PkgName: "gosql",
	},
}

Functions

This section is empty.

Types

type Bool

type Bool struct {
	Value bool
	IsSet bool
}

Bool implements both the flag.Value and the json.Unmarshal interfaces enforcing priority of flags over json, meaning that json.Unmarshal will not override the value if it was previously set by flag.Var.

func (Bool) Get

func (b Bool) Get() interface{}

Get implements the flag.Getter interface.

func (Bool) IsBoolFlag

func (b Bool) IsBoolFlag() bool

IsBoolFlag indicates that the Bool type can be used as a boolean flag.

func (*Bool) Set

func (b *Bool) Set(value string) error

Set implements the flag.Value interface.

func (Bool) String

func (b Bool) String() string

String implements the flag.Value interface.

func (*Bool) UnmarshalJSON

func (b *Bool) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the json.Unmarshaler interface.

type Config

type Config struct {
	// The directory in which the tool will search for files to process.
	// If not provided, the current working directory will be used by default.
	WorkingDirectory String `json:"working_directory"`
	// If set to true, the tool will search the hierarchy of the working
	// directory for files to process.
	Recursive Bool `json:"recursive"`
	// List of files to be used as input for the tool.
	// The files must be located in the working directory.
	InputFiles StringSlice `json:"input_files"`
	// List of regular expressions to match input files that the tool should
	// process. The regular expressions must match files that are located in
	// the working directory.
	InputFileRegexps StringSlice `json:"input_file_regexps"`
	// The format used for generating the name of the output files.
	//
	// The format can contain one (and only one) "%s" placeholder which the
	// tool will replace with the input file's base name, if no placeholder is
	// present then the input file's base name will be prefixed to the format.
	//
	// If not provided, the format "%s_gosql.go" will be used by default.
	OutputFileNameFormat String `json:"output_file_name_format"`
	// The connection string of the database that will be used for type checking.
	// This value is required.
	DatabaseDSN String `json:"database_dsn"`
	// If set to true, the generator will quote postgres identifiers like
	// column names, table names, etc.
	QuoteIdentifiers Bool `json:"quote_identifiers"`
	// If set to a non-empty string, it specifies the struct tag to be used
	// for constructing the column keys of a FilterXxx type. A valid tag must
	// begin with a letter (A-z) or an underscore (_), subsequent characters
	// in the tag can be letters, underscores, and digits (0-9).
	// If set to "" (empty string), the generator will default to use the
	// field names instead of struct tags to construct the column keys.
	//
	// If not provided, the tag "json" will be used by default.
	FilterColumnKeyTag String `json:"filter_column_key_tag"`
	// If set, instructs the generator to use only the base of a tag/field
	// chain to construct the column keys of a FilterXxx type.
	//
	// If not provided, `false` will be used by default.
	FilterColumnKeyBase Bool `json:"filter_column_key_base"`
	// The separator to be used to join a chain of tag/field values for
	// constructing the column keys of a FilterXxx type. The separator can
	// be at most one byte long.
	//
	// If not provided, the separator "." will be used by default.
	FilterColumnKeySeparator String `json:"filter_column_key_separator"`
	// The name to be used for the generated method.
	//
	// If not provided, the name "Exec" will be used by default.
	MethodName String `json:"method_name"`
	// If set, the generator will produce methods that take context.Context
	// as its first argument and they will pass that argument to the XxxContext
	// query executing methods of the Conn type.
	//
	// If not provided, `false` will be used by default.
	MethodWithContext Bool `json:"method_with_context"`
	// The Go type to be used as the "querier" argument for the generated methods.
	//
	// The string value must be of the format "[*]package/path.TypeName" and
	// the type represented by it must implement the following interface:
	//	{
	// 	     Exec(query string, args ...interface{}) (sql.Result, error)
	// 	     ExecContext(ctx context.Context, query string, args ...interface{}) (sql.Result, error)
	// 	     Query(query string, args ...interface{}) (*sql.Rows, error)
	// 	     QueryContext(ctx context.Context, query string, args ...interface{}) (*sql.Rows, error)
	// 	     QueryRow(query string, args ...interface{}) *sql.Row
	// 	     QueryRowContext(ctx context.Context, query string, args ...interface{}) *sql.Row
	// 	}
	//
	// If not provided, the type github.com/frk/gosql.Conn will be used by default.
	MethodArgumentType GoType `json:"method_argument_type"`
	// contains filtered or unexported fields
}

The Config struct is used to configure the gosql tool.

func (*Config) FileFilterFunc

func (c *Config) FileFilterFunc() (filter func(filePath string) bool)

func (*Config) ParseFile

func (c *Config) ParseFile() error

ParseFile looks for a gosql config file in the git project's root of the receiver's working directory, if it finds such a file it will then unmarshal it into the receiver.

func (*Config) ParseFlags

func (c *Config) ParseFlags(printUsage func())

ParseFlags unmarshals the cli flags into the receiver.

func (*Config) Validate

func (c *Config) Validate() (err error)

Validate checks the config for errors and updates some of the values to a more "normalized" format.

type GoType

type GoType struct {
	Name    string
	PkgPath string
	PkgName string
	IsPtr   bool

	IsSet bool
}

GoType implements both the flag.Value and the json.Unmarshal interfaces enforcing priority of flags over json, meaning that json.Unmarshal will not override the value if it was previously set by flag.Var.

func (GoType) Get

func (t GoType) Get() interface{}

Get implements the flag.Getter interface.

func (*GoType) Set

func (t *GoType) Set(value string) error

Set implements the flag.Value interface.

func (GoType) String

func (t GoType) String() string

String implements the flag.Value interface.

func (*GoType) UnmarshalJSON

func (t *GoType) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the json.Unmarshaler interface.

type String

type String struct {
	Value string
	IsSet bool
}

String implements both the flag.Value and the json.Unmarshal interfaces enforcing priority of flags over json, meaning that json.Unmarshal will not override the value if it was previously set by flag.Var.

func (String) Get

func (s String) Get() interface{}

Get implements the flag.Getter interface.

func (*String) Set

func (s *String) Set(value string) error

Set implements the flag.Value interface.

func (String) String

func (s String) String() string

String implements the flag.Value interface.

func (*String) UnmarshalJSON

func (s *String) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the json.Unmarshaler interface.

type StringSlice

type StringSlice struct {
	Value []string
	IsSet bool
}

StringSlice implements both the flag.Value and the json.Unmarshal interfaces enforcing priority of flags over json, meaning that json.Unmarshal will not override the value if it was previously set by flag.Var.

func (StringSlice) Get

func (ss StringSlice) Get() interface{}

Get implements the flag.Getter interface.

func (*StringSlice) Set

func (ss *StringSlice) Set(value string) error

Set implements the flag.Value interface.

func (StringSlice) String

func (ss StringSlice) String() string

String implements the flag.Value interface.

func (*StringSlice) UnmarshalJSON

func (ss *StringSlice) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the json.Unmarshaler interface.

Jump to

Keyboard shortcuts

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