github.com/easysoft/zendata@v0.0.0-20240513203326-705bd5a7fd67/internal/pkg/domain/def.go (about) 1 package domain 2 3 import ( 4 "time" 5 6 consts "github.com/easysoft/zendata/internal/pkg/const" 7 ) 8 9 type ClsInfo struct { 10 Title string `yaml:"title"` 11 Desc string `yaml:"desc"` 12 Author string `yaml:"author,omitempty"` 13 Version string `yaml:"version,omitempty"` 14 } 15 type ClsBase struct { 16 ClsInfo `yaml:",inline"` 17 From string `yaml:"from,omitempty"` 18 Type string `yaml:"type,omitempty"` 19 } 20 21 // config res 22 type ResConfig struct { 23 ClsInfo `yaml:",inline"` 24 FieldSimple `yaml:",inline"` 25 } 26 27 // range res 28 type ResRanges struct { 29 ClsInfo `yaml:",inline"` 30 FileDir string `yaml:"fileDir,omitempty"` 31 Ranges map[string]string `yaml:"ranges"` 32 } 33 34 // instance res 35 type ResInstances struct { 36 ClsBase `yaml:",inline"` 37 FileDir string `yaml:"fileDir,omitempty"` 38 Instances []ResInstancesItem `yaml:"instances,flow"` 39 } 40 type ResInstancesItem struct { 41 FieldBase `yaml:",inline"` 42 Instance string `yaml:"instance"` 43 Fields []DefField `yaml:"fields,flow"` 44 Froms []DefField `yaml:"froms,flow"` 45 } 46 47 // common item 48 type DefData struct { 49 ClsBase `yaml:",inline"` 50 Fields []DefField `yaml:"fields"` 51 52 Content string `yaml:"content,omitempty"` // for article only 53 } 54 type DefField struct { 55 FieldBase `yaml:",inline"` 56 Fields []DefField `yaml:"fields,omitempty"` 57 Length int `yaml:"length,omitempty"` 58 LeftPad string `yaml:"leftpad,omitempty"` 59 RightPad string `yaml:"rightpad,omitempty"` 60 Path string `yaml:"path,omitempty"` 61 FileDir string `yaml:"fileDir,omitempty"` 62 Join bool `yaml:"join,omitempty"` 63 64 Froms []DefField `yaml:"froms,flow,omitempty"` 65 66 Values []interface{} `yaml:"-"` 67 ValuesWithPlaceholder []string `yaml:"-"` 68 } 69 70 type DefArticle struct { 71 Author string `yaml:"author"` 72 From string `yaml:"from"` 73 Title string `yaml:"title"` 74 Type string `yaml:"type"` 75 Version string `yaml:"version"` 76 Content string `yaml:"content"` 77 } 78 79 // base struct 80 type FieldBase struct { 81 FieldSimple `yaml:",inline"` 82 83 Config string `yaml:"config,omitempty"` 84 Where string `yaml:"where,omitempty"` 85 Limit int `yaml:"limit,omitempty"` 86 87 IsNumb bool `yaml:"isNumb,omitempty"` 88 Expect string `yaml:"expect,omitempty"` 89 90 Precision int `yaml:"precision,omitempty"` 91 } 92 type DefSimple struct { 93 ClsBase `yaml:",inline"` 94 Fields []FieldSimple `yaml:"fields"` 95 } 96 type FieldSimple struct { 97 Field string `yaml:"field,omitempty"` 98 Note string `yaml:"note,omitempty"` 99 Range string `yaml:"range,omitempty"` 100 RangeLiteral string `yaml:"rangeLiteral,omitempty" json:"rangeLiteral,omitempty"` 101 Value string `yaml:"value,omitempty"` 102 Prefix string `yaml:"prefix,omitempty"` 103 Postfix string `yaml:"postfix,omitempty"` 104 Divider string `yaml:"divider,omitempty"` 105 Loop string `yaml:"loop,omitempty"` 106 Loopfix string `yaml:"loopfix,omitempty"` 107 Format string `yaml:"format,omitempty"` 108 Rand bool `yaml:"rand,omitempty"` 109 Type string `yaml:"type,omitempty"` 110 Mode string `yaml:"mode,omitempty"` 111 Items int `yaml:"records,omitempty"` 112 //ParentItems int `yaml:"-"` 113 //ParentJoin bool `yaml:"-"` 114 From string `yaml:"from,omitempty"` 115 Use string `yaml:"use,omitempty"` 116 Select string `yaml:"select,omitempty"` 117 118 LoopStart int `yaml:"-"` 119 LoopEnd int `yaml:"-"` 120 LoopIndex int `yaml:"-"` 121 IsRand bool `yaml:"-"` 122 ReferToAnotherYaml bool `yaml:"-"` 123 124 PrefixRange *Range `yaml:"-"` 125 PostfixRange *Range `yaml:"-"` 126 } 127 128 type Range struct { 129 Values []interface{} 130 IsRand bool 131 } 132 133 type FieldWithValues struct { 134 FieldBase `yaml:",inline"` 135 Field string `yaml:"field"` 136 Values []interface{} 137 ValuesWithPlaceholder []string 138 } 139 140 type DefInfo struct { 141 Title string `yaml:"title"` 142 Desc string `yaml:"desc"` 143 144 Fields interface{} `yaml:"fields,omitempty"` // is yaml 145 Range string `yaml:"range,omitempty"` // is config 146 Ranges interface{} `yaml:"ranges,omitempty"` // is ranges 147 Instances interface{} `yaml:"instances,omitempty"` // is instances 148 } 149 150 func (def *DefSimple) Init(tableName, author, desc, version string) { 151 def.Title = "table " + tableName 152 def.Author = author 153 def.Desc = desc 154 def.Version = version 155 } 156 func (fld *FieldSimple) Init(field string) { 157 fld.Field = field 158 } 159 160 type DefExport struct { 161 ClsBase `yaml:",inline"` 162 XFields []DefFieldExport `yaml:"xfields,flow"` // control orders 163 } 164 type DefFieldExport struct { 165 Field string `yaml:"field"` 166 Prefix string `yaml:"prefix,omitempty"` 167 Postfix string `yaml:"postfix,omitempty"` 168 Divider string `yaml:"divider,omitempty"` 169 Select string `yaml:"select,omitempty"` 170 Where string `yaml:"where,omitempty"` 171 Rand bool `yaml:"rand"` 172 Limit int `yaml:"limit,omitempty"` 173 } 174 type Article struct { 175 Title string `yaml:"title"` 176 Desc string `yaml:"desc"` 177 Author string `yaml:"author"` 178 Type string `yaml:"type"` 179 XFields []ArticleField `yaml:"xfields,flow"` // control orders 180 } 181 type ArticleField struct { 182 Field string `yaml:"field"` 183 Range string `yaml:"range,omitempty"` 184 Prefix string `yaml:"prefix,omitempty"` 185 Postfix string `yaml:"postfix,omitempty"` 186 } 187 type ArticleSent struct { 188 Type string 189 Val string 190 IsParag bool 191 IsSent bool 192 } 193 194 type ResFile struct { 195 Path string `json:"path"` 196 Title string `json:"title"` 197 Desc string `json:"desc"` 198 ResType string `json:"resType"` 199 UpdatedAt time.Time `json:"updatedAt"` 200 201 FileName string `json:"fileName"` 202 ReferName string `json:"referName"` 203 } 204 type ResField struct { 205 ID uint `json:"id"` 206 Index int `json:"index"` 207 Name string `json:"name"` 208 } 209 210 type Dir struct { 211 Name string `json:"name"` 212 Path string `json:-` 213 } 214 215 type MockData struct { 216 Id int `json:"id" yaml:"-"` 217 Title string `json:"title"` 218 Desc string `json:"desc"` 219 Author string `json:"author"` 220 Version string `json:"version"` 221 222 Paths MockPathMap `json:"paths"` 223 } 224 type MockPathMap map[string]map[string]map[string]map[string]*EndPoint 225 226 type EndPoint struct { 227 Method HttpMethod `json:"method"` 228 Summary string `json:"summary,omitempty"` 229 Config string `json:"config"` 230 Fields string `json:"fields"` 231 MediaType string `json:"mediaType"` 232 Type consts.OpenApiSchemaType `json:"type"` 233 Lines int `json:"lines"` 234 Samples map[string]string `json:"samples"` 235 } 236 237 type MockPreviewReq struct { 238 Id int `json:"id"` 239 Url string `json:"url"` 240 Method string `json:"method"` 241 Code string `json:"code"` 242 Media string `json:"media"` 243 } 244 245 type MockChangeSampleSrcReq struct { 246 Key string `json:"key"` 247 Value string `json:"value"` 248 } 249 250 type HttpMethod string 251 252 const ( 253 Get HttpMethod = "get" 254 Post HttpMethod = "post" 255 Put HttpMethod = "put" 256 Delete HttpMethod = "delete" 257 258 Patch HttpMethod = "path" 259 Head HttpMethod = "head" 260 Connect HttpMethod = "connect" 261 Options HttpMethod = "options" 262 Trace HttpMethod = "trace" 263 ) 264 265 func (e HttpMethod) String() string { 266 return string(e) 267 }