internal

package
v0.0.0-...-3a91a05 Latest Latest
Warning

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

Go to latest
Published: Apr 12, 2022 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

使用template模板方式,将Struct对象转换为go文件

Index

Constants

View Source
const (
	AppName = "dbcoder"
	VERSION = "v1.0.0"
)

Variables

View Source
var GormTemplete = `func BeforunUpdaet()  {

}

func AfterUpdaet()  {

}`

Functions

func Execute

func Execute(w io.Writer, tpl *GenTemplate) error

模板生成输出内容

func IfComment

func IfComment(comment string) string

自定义模板表达式:成员注释

func IfImports

func IfImports(imports []string) string

自定义模板表达式:加载依赖包

Types

type Field

type Field struct {
	Name    string // 字段名称
	Type    string // 字段类型
	Tag     string // 字段标签
	Comment string // 字段注释
}

Go文件中的结构体字段

type GenTemplate

type GenTemplate struct {
	Generator string   // 生成器名称
	Version   string   // 生成器版本
	Source    string   // 生成的来源(模板数据来源,如:192.168.0.10:5432/testdb/tableName)
	Date      string   // 生成日期
	Package   string   // 包名
	Imports   []string // 依赖包
	Structs   []Struct // 结构体
}

type Generator

type Generator struct {
	schema.Driver // 数据库驱动类型
	Profile       // 配置文件
}

func (*Generator) Generate

func (g *Generator) Generate() error

执行生成命令

func (*Generator) Supported

func (g *Generator) Supported() bool

Determine whether the driver is supported

type Method

type Method struct {
}

todo:Go文件中的方法

type Profile

type Profile struct {
	AppName string   // 应用名称
	Version string   // 应用版本
	Host    string   // 主机
	Port    int      // 端口,具化默认值
	User    string   // 用户,具化默认值
	Auth    string   // 密码,具化默认值
	DbName  string   // 数据库
	Ignores []string // 忽略的数据表
	Package string   // 包名
	Plump   bool     // 生成增删改查等数据操作代码
	Out     string   // 输出路径
	Pile    bool     // 单文件输出
}

代码生成器概要信息

func (*Profile) String

func (c *Profile) String() string

type Struct

type Struct struct {
	Name    string   // 结构体名称
	Comment string   // 结构体注释
	Fields  []Field  // 结构体字段
	Methods []Method // todo:结构体方法
}

Go文件中的结构体

Jump to

Keyboard shortcuts

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