# gen.ps1 - 极简版 & .\gentool.exe ` -dsn "root:gR9pV4tY7zR6qL3e@tcp(47.108.184.184:3306)/user_db?charset=utf8mb4&parseTime=True&loc=Local" ` -fieldSignable ` -outPath "./user_db/query" Get-ChildItem ./user_db/model/*.gen.go | ForEach-Object { $c = Get-Content $_.FullName -Raw -Encoding UTF8 if ($c -match '\bSn\s+string\b' -and $c -notmatch 'BeforeCreate') { $c -match 'type\s+(\w+)\s+struct' | Out-Null $n = $matches[1] $c = $c -replace '(?s)(import\s*\([^)]*)', "`$1`t`"git.hlsq.asia/mmorpg/service-common/utils`"`n" $hook = "`n`n// Auto sn`nfunc (m *$n) BeforeCreate(_ *gorm.DB) error {`n`tif m.Sn == `"`" {`n`t`tm.Sn = utils.SnowflakeInstance().Generate().String()`n`t}`n`treturn nil`n}" Set-Content $_.FullName ($c.TrimEnd() + $hook) -Encoding UTF8 } }