1

这个 golang struct 是用的什么生成的

 2 years ago
source link: https://www.v2ex.com/t/879865
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

V2EX  ›  Go 编程语言

这个 golang struct 是用的什么生成的

  guanhui07 · 3 小时 37 分钟前 · 1436 次点击

ddl 语句如下:

CREATE TABLE `pf_station_info` (
  `id` int unsigned NOT NULL AUTO_INCREMENT,
  `name` varchar(20) NOT NULL DEFAULT '' COMMENT '站点名称',
  `location` json NOT NULL COMMENT '站点所在经纬度',
  `ip_address` varchar(15) NOT NULL DEFAULT '' COMMENT '站点 ip 地址,非此 IP 数据不接收',
  `tiger_shaped` char(32) NOT NULL DEFAULT '' COMMENT '握手符号',
  `heartbeat` int unsigned NOT NULL DEFAULT '0' COMMENT '上次心跳时间戳',
  `status` int NOT NULL DEFAULT '0' COMMENT '站点状态:0 正常,非 0 为停用时间戳',
  `add_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  `update_time` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=22 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;

要生成 如下 gorm struct , not null 以及 comment 也在 tag 里 且 location 类型 是 datatypes.JSON 类型

type Station struct {
	Id          int64          `json:"id" gorm:"primaryKey;autoIncrement;comment:主键 id"`
	Name        string         `gorm:"type:varchar(20);column:name;not null;comment:站点名称" json:"name"`
	Location    datatypes.JSON `gorm:"type:json;column:location;not null;comment:站点所在经纬度" json:"location"`
	IpAddress   string         `gorm:"type:varchar(15);column:ip_address;not null;comment:站点 ip 地址,非此 IP 数据不接收" json:"ip_address"`
	TigerShaped string         `gorm:"type:char(32);column:tiger_shaped;not null;comment:握手符号" json:"tiger_shaped"`
	Heartbeat   int64          `gorm:"type:int(10);column:heartbeat;not null;comment:上次心跳时间戳" json:"heartbeat"`
	Status      int64          `gorm:"type:int(11);column:status;comment:站点状态:0 正常,非 0 为停用时间戳" json:"status"`
	AddTime     time.Time      `gorm:"type:datetime;comment:创建时间" json:"add_time,omitempty"`
	UpdateTime  time.Time      `gorm:"type:datetime;comment:修改时间" json:"update_time,omitempty"`
}

有人知道 上面的 struct 是用 什么工具生成的吗?我猜不可能手写吧。

谷歌搜了下 看了好几个 根据 ddl 生成都不一样 ,比如下面的

https://www.qetool.com/sql_json_go/sql.html

http://sql2struct.atotoa.com/

utools 里的 sql2struct 生成也不一样

有没大佬推荐个好用点的 或 跟这个 生成一模一样的。


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK