generator

package
v1.0.0-alpha Latest Latest
Warning

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

Go to latest
Published: Mar 25, 2024 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ApplyMainFunctionDirTemplate = "/cmd/apply"
	ApplyMainFunctionTemplate    = `` /* 1468-byte string literal not displayed */

)
View Source
const (
	ConfigDir      = "configs"
	ConfigFile     = "app"
	ConfigTemplate = `` /* 670-byte string literal not displayed */

)
View Source
const (
	ControllerDir      = "internal/controllers"
	ControllerTemplate = `package {{ .Package }}
{{- if gt (len .Imports) 0 }}

import (
{{- range .Imports}}
	{{.}}
{{- end}}
)
{{- end }}

type {{ .Name }}Request struct {
	{{- if not .RequestFields}} // Add your request data {{ else }}
	{{- range .RequestFields}}
	{{ .Field }} {{ .Type }} {{ .Tag }}
	{{- end }}
	{{- end }}
}

type {{ .Name }}Response struct {
	{{- if not .ResponseFields}} // Add your response data {{ else }}
	{{- range .ResponseFields}}
	{{ .Field }} {{ .Type }} {{ .Tag }}
	{{- end}}
	{{- end }}
}

type {{ .Name }}Controller struct {
	raiden.ControllerBase
	Http	string ` + "{{ .HttpTag }}" + `
	Payload	*{{ .Name }}Request
	Result	{{ .Name }}Response
}

func (c *{{ .Name }}Controller) Get(ctx raiden.Context) error {
	{{ .DefaultAction }}
	return ctx.SendJson(c.Result)
}
`
)
View Source
const (
	ImportMainFunctionDirTemplate = "/cmd/import"
	ImportMainFunctionTemplate    = `` /* 1469-byte string literal not displayed */

)
View Source
const (
	MainFunctionDirTemplate = "/cmd/%s"
	MainFunctionTemplate    = `` /* 370-byte string literal not displayed */

)
View Source
const (
	ModelDir      = "internal/models"
	ModelTemplate = `package {{ .Package }}
{{- if gt (len .Imports) 0 }}

import (
{{- range .Imports}}
	"{{.}}"
{{- end}}
)
{{- end }}

type {{ .StructName }} struct {
	raiden.ModelBase
{{- range .Columns }}
	{{ .Name | ToGoIdentifier }} {{ .Type }} ` + "`{{ .Tag }}`" + `
{{- end }}

	// Table information
	Metadata string ` + "`json:\"-\" schema:\"{{ .Schema}}\" rlsEnable:\"{{ .RlsEnable }}\" rlsForced:\"{{ .RlsForced }}\"`" + `

	// Access control
	Acl string ` + "`json:\"-\" {{ .RlsTag }}`" + `
	
{{- if gt (len .Relations) 0 }}

	// Relations
{{- end }}
{{- range .Relations }}
	{{ .Table | ToGoIdentifier }} {{ .Type }} ` + "`{{ .Tag }}`" + `
{{- end }}
}
`
)
View Source
const (
	ModelRegisterFilename = "models.go"
	ModelRegisterDir      = "internal/bootstrap"
	ModelRegisterTemplate = `` /* 263-byte string literal not displayed */

)
View Source
const (
	RoleDir      = "internal/roles"
	RoleTemplate = `` /* 1591-byte string literal not displayed */

)
View Source
const (
	RoleRegisterFilename = "roles.go"
	RoleRegisterDir      = "internal/bootstrap"
	RoleRegisterTemplate = `` /* 258-byte string literal not displayed */

)
View Source
const (
	RouterFilename = "route.go"
	RouterDir      = "internal/bootstrap"
	RouterTemplate = `` /* 491-byte string literal not displayed */

)
View Source
const (
	RpcDir      = "internal/rpc"
	RpcTemplate = `package {{ .Package }}
{{- if gt (len .Imports) 0 }}

import (
{{- range .Imports}}
	{{.}}
{{- end}}
)
{{- end }}

type {{ .Name }}Params struct {
	{{- range .Params }}
	{{ .Field }} {{ .Type }} ` + "`{{ .Tag }}`" + `
	{{- end }}
}

{{- if gt (len .ReturnColumn) 0 }}
type {{ .Name }}Item struct {
	{{- range .ReturnColumn }}
	{{ .Field }} {{ .Type }} ` + "`{{ .Tag }}`" + `
	{{- end }}
}

type {{ .Name }}Result {{ if .IsReturnArr }}[]{{ end }}{{ .Name }}Item
{{- else }}
type {{ .Name }}Result {{ if .IsReturnArr }}[]{{ end }}{{ .ReturnDecl }}
{{- end }}

type {{ .Name }} struct {
	raiden.RpcBase
	Params   *{{ .Name }}Params ` + "`json:\"-\"`" + `
	Return   {{ .Name }}Result ` + "`json:\"-\"`" + `
}

func (r *{{ .Name }}) GetName() string {
	return "{{ .Name | ToSnakeCase }}"
}

{{- if ne .Schema "public" }}

func (r *{{.Name }}) GetSchema() string {
	return "{{ .Schema }}"
}

{{- end }}
{{- if not .UseParamPrefix }}

func  (r *{{.Name }}) UseParamPrefix() bool {
	return false
}

{{- end }}
{{- if ne .Security "RpcSecurityTypeInvoker" }}

func (r *{{.Name }}) GetSecurity() raiden.RpcSecurityType {
	return raiden.{{ .Security }}
}
{{- end }}
{{- if ne .Behavior "RpcBehaviorVolatile" }}

func (r *{{.Name }}) GetBehavior() raiden.RpcBehaviorType {
	return raiden.{{ .Behavior }}
}
{{- end }}

func (r *{{.Name }}) GetReturnType() raiden.RpcReturnDataType {
	return raiden.{{ .ReturnType }}
}
{{- if ne .Models "" }}

func (r *{{ .Name }}) BindModels() {
	{{ .Models }}
}
{{- end }}

func (r *{{ .Name }}) GetRawDefinition() string {
	return ` + "`{{ .Definition }}`" + `
}`
)
View Source
const (
	RpcRegisterFilename = "rpc.go"
	RpcRegisterDir      = "internal/bootstrap"
	RpcRegisterTemplate = `` /* 251-byte string literal not displayed */

)

Variables

This section is empty.

Functions

func CreateInternalFolder

func CreateInternalFolder(basePath string) (err error)

func DefaultWriter

func DefaultWriter(filePath string) (*os.File, error)

----- Generate functionality -----

func ExtractRpcParam

func ExtractRpcParam(fn *objects.Function) (params []raiden.RpcParam, usePrefix bool, err error)

func ExtractRpcTable

func ExtractRpcTable(def string) (string, map[string]*RpcScannedTable, error)

func Generate

func Generate(input GenerateInput, writer io.Writer) error

func GenerateApplyMainFunction

func GenerateApplyMainFunction(basePath string, config *raiden.Config, generateFn GenerateFn) error

func GenerateConfig

func GenerateConfig(basePath string, config *raiden.Config, generateFn GenerateFn) error

func GenerateController

func GenerateController(file string, data GenerateControllerData, generateFn GenerateFn) error

----- Generate controller -----

func GenerateHelloWordController

func GenerateHelloWordController(basePath string, generateFn GenerateFn) (err error)

----- Generate hello word -----

func GenerateImportMainFunction

func GenerateImportMainFunction(basePath string, config *raiden.Config, generateFn GenerateFn) error

func GenerateMainFunction

func GenerateMainFunction(basePath string, config *raiden.Config, generateFn GenerateFn) error

func GenerateModel

func GenerateModel(folderPath string, input *GenerateModelInput, generateFn GenerateFn) error

func GenerateModelRegister

func GenerateModelRegister(basePath string, projectName string, generateFn GenerateFn) error

func GenerateModels

func GenerateModels(basePath string, tables []*GenerateModelInput, generateFn GenerateFn) (err error)

func GenerateRole

func GenerateRole(folderPath string, role objects.Role, generateFn GenerateFn) error

func GenerateRoleRegister

func GenerateRoleRegister(basePath string, projectName string, generateFn GenerateFn) error

func GenerateRoles

func GenerateRoles(basePath string, roles []objects.Role, generateFn GenerateFn) (err error)

func GenerateRoute

func GenerateRoute(basePath string, projectName string, generateFn GenerateFn) error

Generate route configuration file

func GenerateRpc

func GenerateRpc(basePath string, projectName string, functions []objects.Function, generateFn GenerateFn) (err error)

func GenerateRpcRegister

func GenerateRpcRegister(basePath string, projectName string, generateFn GenerateFn) error

func RpcNormalizeTableAliases

func RpcNormalizeTableAliases(mapTables map[string]*RpcScannedTable) error

func WalkScanModel

func WalkScanModel(roleDir string) ([]string, error)

func WalkScanRole

func WalkScanRole(roleDir string) ([]string, error)

func WalkScanRpc

func WalkScanRpc(rpcDir string) ([]string, error)

Types

type ControllerFieldAttribute

type ControllerFieldAttribute struct {
	Field string
	Type  string
	Tag   string
}

----- Define type, variable and constant -----

type ExtractRpcDataResult

type ExtractRpcDataResult struct {
	Rpc                raiden.RpcBase
	MapScannedTable    map[string]*RpcScannedTable
	OriginalReturnType string
	UseParamPrefix     bool
}

----- Define type, variable and constant -----

func ExtractRpcFunction

func ExtractRpcFunction(fn *objects.Function) (result ExtractRpcDataResult, err error)

func (*ExtractRpcDataResult) GetBehavior

func (r *ExtractRpcDataResult) GetBehavior() (behavior string)

func (*ExtractRpcDataResult) GetModelDecl

func (r *ExtractRpcDataResult) GetModelDecl() (modelDecl string)

func (*ExtractRpcDataResult) GetParams

func (r *ExtractRpcDataResult) GetParams(mapImports map[string]bool) (columns []RpcColumn, err error)

func (*ExtractRpcDataResult) GetReturn

func (r *ExtractRpcDataResult) GetReturn(mapImports map[string]bool) (returnDecl string, returnColumns []RpcColumn, isReturnArr bool, err error)

func (*ExtractRpcDataResult) GetSecurity

func (r *ExtractRpcDataResult) GetSecurity() (security string)

type FoundRoute

type FoundRoute struct {
	Package string
	Name    string
	Tag     string
	Methods []string
	Model   string
}

----- Define type, variable and constant -----

type GenerateApplyMainFunctionData

type GenerateApplyMainFunctionData struct {
	Package string
	Imports []string
}

----- Define type, variable and constant -----

type GenerateControllerData

type GenerateControllerData struct {
	DefaultAction  string
	HttpTag        string
	Imports        []string
	Name           string
	Package        string
	RequestFields  []ControllerFieldAttribute
	ResponseFields []ControllerFieldAttribute
}

type GenerateFn

type GenerateFn func(input GenerateInput, writer io.Writer) error

type GenerateImportMainFunctionData

type GenerateImportMainFunctionData struct {
	Package string
	Imports []string
}

----- Define type, variable and constant -----

type GenerateInput

type GenerateInput struct {
	BindData     any
	Template     string
	TemplateName string
	OutputPath   string
	FuncMap      []template.FuncMap
}

----- Define type, variable and constant -----

type GenerateMainFunctionData

type GenerateMainFunctionData struct {
	Package string
	Imports []string
}

----- Define type, variable and constant -----

type GenerateModelColumn

type GenerateModelColumn struct {
	Name string
	Type string
	Tag  string
}

----- Define type, variable and constant -----

type GenerateModelData

type GenerateModelData struct {
	Columns    []GenerateModelColumn
	Imports    []string
	Package    string
	Relations  []state.Relation
	RlsTag     string
	RlsEnable  bool
	RlsForced  bool
	StructName string
	Schema     string
}

----- Define type, variable and constant -----

type GenerateModelInput

type GenerateModelInput struct {
	Table     objects.Table
	Relations []state.Relation
	Policies  objects.Policies
}

----- Define type, variable and constant -----

type GenerateRegisterModelData

type GenerateRegisterModelData struct {
	Imports []string
	Package string
	Models  []string
}

----- Define type, variable and constant -----

type GenerateRegisterRoleData

type GenerateRegisterRoleData struct {
	Imports []string
	Package string
	Roles   []string
}

----- Define type, variable and constant -----

type GenerateRegisterRpcData

type GenerateRegisterRpcData struct {
	Imports []string
	Package string
	Rpc     []string
}

----- Define type, variable and constant -----

type GenerateRoleData

type GenerateRoleData struct {
	Imports                []string
	Package                string
	Name                   string
	DefaultLimitConnection int
	ConnectionLimit        int
	InheritRole            bool
	IsReplicationRole      bool
	IsSuperuser            bool
	CanBypassRls           bool
	CanCreateDB            bool
	CanCreateRole          bool
	CanLogin               bool
	ValidUntil             string
}

----- Define type, variable and constant -----

type GenerateRouteItem

type GenerateRouteItem struct {
	Type       string
	Path       string
	Methods    string
	Controller string
	Model      string
}

----- Define type, variable and constant -----

func WalkScanControllers

func WalkScanControllers(controllerPath string) ([]GenerateRouteItem, error)

type GenerateRouterData

type GenerateRouterData struct {
	Imports []string
	Package string
	Routes  []GenerateRouteItem
}

----- Define type, variable and constant -----

type GenerateRpcData

type GenerateRpcData struct {
	Package string
	Imports []string

	UseParamPrefix bool
	Params         []RpcColumn

	ReturnType   string
	ReturnColumn []RpcColumn
	ReturnDecl   string
	IsReturnArr  bool

	Name     string
	Schema   string
	Security string
	Behavior string

	Models     string
	Definition string
}

----- Define type, variable and constant -----

type Rls

type Rls struct {
	CanWrite []string
	CanRead  []string
}

----- Define type, variable and constant -----

type RpcColumn

type RpcColumn struct {
	Field string
	Type  string
	Tag   string
}

----- Define type, variable and constant -----

type RpcScannedTable

type RpcScannedTable struct {
	Name     string
	Alias    string
	Relation []string
}

----- Define type, variable and constant -----

Jump to

Keyboard shortcuts

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