Convert Typescript DataModel into Golang.
- basic types (int, float, string, Date)
- container types (Record, Map, Array)
- nested class
- nullable member
(By Annotations)
- package name
- struct name
- tags to generate by auto naming
- extra tag contents
- custom naming to override auto naming
@GoModel({
packageName: 'model',
modelName: 'UserModel',
generateTags: ['json', 'gorm', 'bson'],
})
class User extends Base {
@ExtraTags({json: 'omitempty'})
id: string
@CustomNaming({bson: 'UserName'})
name: string
@ExtraTags({sometag: ['a', 'b']})
someArray: Date[]
someNullable?: string
someMap: Map<string, int[]>
someInlineType: {
a: int
b: string
}
}
Which converts to:
// Generated By Type2Go At SomeTime //
package model
import (
"time"
)
type UserModel struct {
Base
Id string `json:"id;omitempty" gorm:"id" bson:"Id"`
Name string `json:"name" gorm:"name" bson:"UserName"`
SomeArray []time.Time `json:"someArray" gorm:"some_array" bson:"SomeArray" sometag:"a,b"`
SomeNullable *string `json:"someNullable" gorm:"some_nullable" bson:"SomeNullable"` /* nullable */
SomeMap map[string][]int `json:"someMap" gorm:"some_map" bson:"SomeMap"`
SomeInlineType struct {
A int `json:"a"`
B string `json:"b"`
} `json:"someInlineType" gorm:"some_inline_type" bson:"SomeInlineType"`
}
- edit
config.js
- put your ts models into
config.inputModelPath
- maybe you want
model_helper.ts
for code suggestion and completion
- maybe you want
- mkdir
config.outputModelDir
- run
node main.js