gen

package
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: May 28, 2020 License: MIT Imports: 26 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExecuteGoTools

func ExecuteGoTools(fileName string) error

ExecuteGoTools runs gofmt -w and goimports on the specified file

Types

type ColType

type ColType int

ColType specifies which type of db item is being interpreted

const (
	// KeyColumn is a hold-over from an older iternation of the code
	KeyColumn ColType = iota
	// DataColumn is used in a (now) pointless check
	DataColumn
)

type Config

type Config struct {
	ExternalAddress     string   `json:"external_address"`
	InternalAddress     string   `json:"internal_address"`
	Env                 string   `json:"env"`
	PingCycle           uint     `json:"ping_cycle"`
	FailureThreshold    uint64   `json:"failure_threshold"`
	Pepper              string   `json:"pepper"`
	HMACKey             string   `json:"hmac_key"`
	Database            DBConfig `json:"database"`
	CertFile            string   `json:"cert_file"`
	KeyFile             string   `json:"key_file"`
	RSA256PrivKeyFile   string   `json:"rsa256_priv_key_file"`
	RSA256PubKeyFile    string   `json:"rsa256_pub_key_file"`
	RSA384PrivKeyFile   string   `json:"rsa384_priv_key_file"`
	RSA384PubKeyFile    string   `json:"rsa384_pub_key_file"`
	RSA512PrivKeyFile   string   `json:"rsa512_priv_key_file"`
	RSA512PubKeyFile    string   `json:"rsa512_pub_key_file"`
	ECDSA256PrivKeyFile string   `json:"ecdsa256_priv_key_file"`
	ECDSA256PubKeyFile  string   `json:"ecdsa256_pub_key_file"`
	ECDSA384PrivKeyFile string   `json:"ecdsa384_priv_key_file"`
	ECDSA384PubKeyFile  string   `json:"ecdsa384_pub_key_file"`
	ECDSA521PrivKeyFile string   `json:"ecdsa521_priv_key_file"`
	ECDSA521PubKeyFile  string   `json:"ecdsa521_pub_key_file"`
	JWTSignMethod       string   `json:"jwt_sign_method"` // {EC256|EC384|EC521|RS256|RS384|RS312}
	JWTLifetime         uint     `json:"jwt_lifetime"`    // minutes
	// JWTPrivKeyFile     string              `json:"jwt_priv_key_file"`
	// JWTPubKeyFile      string              `json:"jwt_pub_key_file"`
	ServiceActivations []ServiceActivation `json:"service_activations"`
}

Config type holds the generated application's configuration info

func (*Config) GenerateAppConf

func (cfg *Config) GenerateAppConf(dstDir string) (fName string, err error)

GenerateAppConf generates the default application configuration source file appconf.go.

func (*Config) GenerateSampleConfig

func (cfg *Config) GenerateSampleConfig(dstDir string) error

GenerateSampleConfig creates a sample .config.json file to hold the production application config.

func (*Config) GenerateSampleDockerConfig

func (cfg *Config) GenerateSampleDockerConfig(dstDir string) error

GenerateSampleDockerConfig creates a sample .config.json file to hold the production application config.

func (Config) GetIsProd

func (cfg Config) GetIsProd() bool

GetIsProd returns a bool value indicating to the calling template that the cfg struct is holding production configuration.

func (Config) IsLastServiceActivationRec

func (cfg Config) IsLastServiceActivationRec(name string) bool

IsLastServiceActivationRec is used to determine whether the config.json.gotmpl has processed the last ServiceActivation while building the .dec / .prd config files.

type DBConfig

type DBConfig struct {
	DBDialect string `json:"db_dialect"`
	Host      string `json:"host"`
	Port      int    `json:"port"`
	Usr       string `json:"Usr"`
	Password  string `json:"Password"`
	Name      string `json:"name"`
}

DBConfig type holds db config info

func (DBConfig) ConnectionInfo

func (c DBConfig) ConnectionInfo() string

ConnectionInfo returns a DBConfig string

func (*DBConfig) Validate

func (c *DBConfig) Validate() error

Validate the default postgres configuration

type Entity

type Entity struct {
	Header    Info
	Fields    []Info
	Relations []Relation
	// CompositeIndexes []string  //
	AppPath string
}

Entity definition

func ReadModelFile

func ReadModelFile(mf string) ([]Entity, error)

ReadModelFile reads a model file

func (*Entity) BuildTestPostJSON

func (ent *Entity) BuildTestPostJSON(isUpdate bool) string

BuildTestPostJSON constructs a basic JSON message body based on the definition of the Entity passed in from the template. The intent is to create a body which can be edited by the developer in order to add more meaningful data.

  • string types will be assigned: "string_value"
  • float64 type will be assigned an incrementing float value starting at 9.91
  • int types will be assigned an incrementing int value starting at 10.
  • uint types will be assigned an incrementing uint value starting at 10.

`{"name":"test_product",

"height":55.5,
"cost":66.6,
"supplier":"Ace Hardware",
"weight":88.8,
"length":44.4,
"width":33.3,
"name":"TEST_PRODUCT",
"description":"a nice test product",
"uom":"EA"}`

func (*Entity) CreateControllerExtensionPointsFile

func (ent *Entity) CreateControllerExtensionPointsFile(tDir string) (fName string, err error)

CreateControllerExtensionPointsFile generates a controller extension- point implementation file for the Entity if the 'gen_controller' element is set to true in the user-defined model.json file. Returns the fully-qualified file-name / error.

func (*Entity) CreateControllerFile

func (ent *Entity) CreateControllerFile(tDir string) (fName string, err error)

CreateControllerFile generates a controller file for the Entity using the user-defined model.json file in conjunction with the controller.gotmpl text/template. Returns the fully-qualified file-name / error.

func (*Entity) CreateControllerRelationsFile

func (ent *Entity) CreateControllerRelationsFile(tDir string, entities []Entity) (fName string, err error)

CreateControllerRelationsFile generates a controller file for the Entity relations using the user-defined model.json file in conjunction with the controller_relationships.gotmpl text/template. The complete set of Entities is passed into the method in order to facilitate the validation of the ToEntity field used in the foreign-key definition. Returns the fully-qualified file-name / error.

func (*Entity) CreateModelExtensionPointsFile

func (ent *Entity) CreateModelExtensionPointsFile(tDir string) (fName string, err error)

CreateModelExtensionPointsFile generates a model extension-point implementation file for the Entity if the 'gen_controller' element is set to true in the user-defined model.json file. Returns the fully-qualified file-name / error.

func (*Entity) CreateModelFile

func (ent *Entity) CreateModelFile(tDir string) (fName string, err error)

CreateModelFile generates a model file for the Entity using the user-defined model.json file in conjunction with the model.gotmpl text/template. Returns the fully-qualified file-name / error. pkger is used to bundle the .gotmpl files into the binary. Pkger implements the File interface, so the file handling is a little more pedantic than it would be with ioutil.

func (*Entity) GetDateTimeStamp

func (ent *Entity) GetDateTimeStamp() string

GetDateTimeStamp returns a stringified date-time in RFC822 format for use in template execution. Called from within a text/template.

func (*Entity) GetHasStart

func (ent *Entity) GetHasStart() bool

GetHasStart returns a bool indicating whether or not an entity has been provided with a start-value for its id in the model file.

func (*Entity) GetLowerCasePrefixLetter

func (ent *Entity) GetLowerCasePrefixLetter() string

GetLowerCasePrefixLetter is a method that will be called from within the templates to return the first letter of the lower-case name of the entity. used for the model -> service vars. defaults to "e" for entity, but this should never occur. Called from within a text/template.

type Info

type Info struct {
	Name  string // field name from model
	Value string // type
	// LowerCaseName       string // field name in lower-case for query path - possibly deprecated
	SnakeCaseName    string // field name in sqac database format (snake_case)
	DBType           string
	IsKey            bool
	Start            uint64
	Format           string
	NoDB             bool // true = no persistence on the db
	Required         bool
	Unique           bool
	Index            string // unique, not-unique, ""
	Selectable       string // "eq,like,gt,lt,ge,le,ne"
	DefaultValue     string //
	DefaultFunc      string // "now; bot; eot etc."
	RefEntity        string // foreign-key reference entity for field
	RefField         string // foreign-key reference field
	SqacTagLine      string
	JSONTagLine      string // `json:"field_name,omitempty"`
	GenControllerExt bool
	GenValidatorExt  bool
	GenModelExt      bool
}

Info is used to hold name-value-pairs for Entity definitions

func (*Info) BuildTestValidationExpression

func (i *Info) BuildTestValidationExpression(isUpdate bool) string

BuildTestValidationExpression is used to build a starter-validation statement for each entity's Create / Update tests in main_test.go.

func (*Info) GetHasEQOp

func (i *Info) GetHasEQOp() bool

GetHasEQOp checks to see if an Entity field has been configured for simple-selection via the use of the 'EQ' operator.

func (*Info) GetHasGEOp

func (i *Info) GetHasGEOp() bool

GetHasGEOp checks to see if an Entity field has been configured for simple-selection via the use of the 'GE' operator.

func (*Info) GetHasGTOp

func (i *Info) GetHasGTOp() bool

GetHasGTOp checks to see if an Entity field has been configured for simple-selection via the use of the 'GT' operator.

func (*Info) GetHasLEOp

func (i *Info) GetHasLEOp() bool

GetHasLEOp checks to see if an Entity field has been configured for simple-selection via the use of the 'LE' operator.

func (*Info) GetHasLIKEOp

func (i *Info) GetHasLIKEOp() bool

GetHasLIKEOp checks to see if an Entity field has been configured for simple-selection via the use of the 'LIKE' operator.

func (*Info) GetHasLTOp

func (i *Info) GetHasLTOp() bool

GetHasLTOp checks to see if an Entity field has been configured for simple-selection via the use of the 'LT' operator.

func (*Info) GetHasNEOp

func (i *Info) GetHasNEOp() bool

GetHasNEOp checks to see if an Entity field has been configured for simple-selection via the use of the 'NE' operator.

func (*Info) GetJSONTagLine

func (i *Info) GetJSONTagLine() string

GetJSONTagLine returns a string containing the json tag directives for the column. Called from within readmodel.go/ReadModelFile()

func (*Info) GetPtrIfNullable

func (i *Info) GetPtrIfNullable() string

GetPtrIfNullable is used to provide a pointer-glyph (*) to the calling template as a preface to nullable model structure members. Called from within a text/template.

func (*Info) GetQueryComponentFuncCall

func (i *Info) GetQueryComponentFuncCall() string

GetQueryComponentFuncCall is used to determine the function to call in order to separate simple query strings into an operator and predicate value of the appropriate type. Called from within a text/template.

func (*Info) GetQueryOps

func (i *Info) GetQueryOps() []string

GetQueryOps is used to obtain a slice of the required simple query operators for the entity controller template. Acceptable types are 'EQ','LT','LE','GT','GE','LIKE'. Called from within a text/template.

func (*Info) GetSelBoolRegex

func (i *Info) GetSelBoolRegex() string

GetSelBoolRegex examines the Selectable field and generates a GET-type gorilla mux route regex based on the requested (and supported) operators for the bool type.

func (*Info) GetSelNumberRegex

func (i *Info) GetSelNumberRegex() string

GetSelNumberRegex examines the Selectable field and generates a GET-type gorilla mux route regex based on the requested (and supported) operators for the numeric type (uint, int, float).

func (*Info) GetSelStringRegex

func (i *Info) GetSelStringRegex() string

GetSelStringRegex examines the Selectable field and generates a GET-type gorilla mux route regex based on the requested (and supported) operators.

func (*Info) GetSqacTagLine

func (i *Info) GetSqacTagLine(b bool) string

GetSqacTagLine returns a string containing a set of sqac directives for the column attributes. Called from within readmodel.go/ReadModelFile()

func (*Info) IsBoolFieldType

func (i *Info) IsBoolFieldType() bool

IsBoolFieldType is used in the text/templates to determine whether an Info.Value is of type "bool", or other. Called from within a text/template.

func (*Info) IsFloatFieldType

func (i *Info) IsFloatFieldType() bool

IsFloatFieldType is used to determine whether an Info record has a float-type. Called internally via Info.IsNumberFieldType.

func (*Info) IsIntFieldType

func (i *Info) IsIntFieldType() bool

IsIntFieldType is used to determine whether an Info record has an int-type. Called internally via Info.IsNumberFieldType.

func (*Info) IsNumberFieldType

func (i *Info) IsNumberFieldType() bool

IsNumberFieldType is used in the text/templates to determine whether an Info.Value is of type uint*, int* or float*. Called from within a text/template.

func (*Info) IsStringFieldType

func (i *Info) IsStringFieldType() bool

IsStringFieldType is used in the text/templates to determine whether an Info.Value is of type "string", or other. Called from within a text/template.

func (*Info) IsUIntFieldType

func (i *Info) IsUIntFieldType() bool

IsUIntFieldType is used to determine whether an Info record has a uint-type. Called internally via Info.IsNumberFieldType.

type KeyConfig

type KeyConfig struct {
	RSABits uint // 0
	// ECDSACurve string   // "P256" || "P384" || "P521" // deprecated
	ECDSA     []string // {"256", "384", "521"}
	RSA       []string // {"256", "384", "512"},
	TargetDir string   // target directory to write keys to
}

KeyConfig holds the basic certificate configuration

func (*KeyConfig) GenerateJWTKeys

func (keyc *KeyConfig) GenerateJWTKeys(conf *Config) error

GenerateJWTKeys creates some ECDSA and RSA keys

type Relation

type Relation struct {
	RelName           string //  "ToStreetAddress" || "StreetAddress" for example
	RelNameLC         string //  "tostreetaddress" || "streetaddress" for example - used in mux route
	RefKey            string //  "ID" - default key name in FromEntity
	RefKeyOptional    bool   //  true/false
	RelType           string //  "hasOne; belongsTo; hasMany"
	FromEntity        string //  "Person"
	FromEntityLC      string //  "person"
	ToEntity          string //  "StreetAddress"
	ToEntityLC        string //  "streetaddress"
	ToEntInfo         []Info //  ToEntity-field-meta-data
	ForeignPK         string //  "<FromEntity>ID"
	ForeignPKOptional bool   //  true/false
}

Relation definition

func (*Relation) GetAreFromAndToKeysOpt

func (r *Relation) GetAreFromAndToKeysOpt(fromEntKeyName, toEntKeyName string, fromInfo, toInfo []Info) bool

GetAreFromAndToKeysOpt returns true if the fromEntKey and toEntKey are both defined as optional. Called from within the controller_relations text/template.

func (*Relation) GetAreFromAndToKeysReq

func (r *Relation) GetAreFromAndToKeysReq(fromEntKeyName, toEntKeyName string, fromInfo, toInfo []Info) bool

GetAreFromAndToKeysReq returns true if the fromEntKey and toEntKey are both defined as required. Called from within the controller_relations text/template.

func (*Relation) GetBelongsTo

func (r *Relation) GetBelongsTo() bool

GetBelongsTo is used to provide a boolean response indicating whether the relation is of relType 'belongsTo'. Called from within the controller_relations text/template.

func (*Relation) GetHasMany

func (r *Relation) GetHasMany() bool

GetHasMany is used to provide a boolean response indicating whether the relation is of relType 'hasMany'. Called from within the controller_relations text/template.

func (*Relation) GetHasOne

func (r *Relation) GetHasOne() bool

GetHasOne is used to provide a boolean response indicating whether the relation is of relType 'hasOne'. Called from within the controller_relations text/template.

func (*Relation) GetIsFromKeyOptAndToKeyReq

func (r *Relation) GetIsFromKeyOptAndToKeyReq(fromEntKeyName, toEntKeyName string, fromInfo, toInfo []Info) bool

GetIsFromKeyOptAndToKeyReq returns true if the fromEntKey has been defined as optional, the the toEntKey has been defined as required. Called from within the controller_relations text/template.

func (*Relation) GetIsFromKeyReqAndToKeyOpt

func (r *Relation) GetIsFromKeyReqAndToKeyOpt(fromEntKeyName, toEntKeyName string, fromInfo, toInfo []Info) bool

GetIsFromKeyReqAndToKeyOpt returns true if the fromEntKey has been defined as required, the the toEntKey has been defined as optional. Called from within the controller_relations text/template.

type ServiceActivation

type ServiceActivation struct {
	ServiceName   string `json:"service_name"`
	ServiceActive bool   `json:"service_active"`
}

ServiceActivation struct

type Static

type Static struct {
	SrcDir   string
	DstDir   string
	AppPath  string
	Entities []Entity
	ECDSA    []string
	RSA      []string
}

Static definition

func (*Static) GenerateGoMod

func (s *Static) GenerateGoMod() error

func (*Static) GenerateStaticTemplates

func (s *Static) GenerateStaticTemplates() (fNames []string, err error)

============================================================================================= static generation functions ============================================================================================= GenerateStaticTemplates reads the ./static folder and uses Glob to execute each template in-turn. Returns the fully-qualified file-names or an error. Processes .gotmpl files into .go files.

func (*Static) GetAddrConcatenatedEntities

func (s *Static) GetAddrConcatenatedEntities() string

GetAddrConcatenatedEntities returns a string of concatenated entity addresses in the form of "&Entity1{}, &Entity2{}, &Entity3{}". this is useful for AutoMigrate and DestructiveReset purposes. Called from within a text/template.

func (*Static) GetConcatenatedEntities

func (s *Static) GetConcatenatedEntities() string

GetConcatenatedEntities returns a string of concatenated entities in the form of "Entity1{}, Entity2{}, Entityn{}...". this is useful for AutoMigrate and DestructiveReset purposes. Called from within a text/template.

func (*Static) GetDateTimeStamp

func (s *Static) GetDateTimeStamp() string

GetDateTimeStamp returns a stringified date-time in RFC822 format for use in template execution. Called from within a text/template.

Jump to

Keyboard shortcuts

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