go mysql生成struct结构体实例

package main

import (
	"fmt"
	"github.com/gohouse/converter"
)
type MysqlConfig struct {
	Host     string `mapstructure:"host" orm:"host"`
	Port     int    `mapstructure:"port" orm:"port"`
	Name     string `mapstructure:"db" orm:"db"`
	User     string `mapstructure:"user" orm:"user"`
	Password string `mapstructure:"password" orm:"password"`
}
func main(){
	c := MysqlConfig{
		Host:     "139.196.123.83",
		Port:     3306,
		Name:     "nt_product",
		User:     "nt_php",
		Password: "账号密码",
	}
	dsn := fmt.Sprintf("%s:%s@tcp(%s:%d)/%s?charset=utf8mb4&parseTime=True&loc=Local",
		c.User, c.Password, c.Host, c.Port, c.Name)
	err :=converter.NewTable2Struct().SavePath("./model.go").Dsn(dsn).TagKey("orm").EnableJsonTag(true).Table("nt_product_pool").Run()
	fmt.Println(err)
}

  

 

posted on 2022-06-09 16:35  kevin_yang123  阅读(320)  评论(0编辑  收藏  举报