resources.go 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656
  1. package got
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "os"
  6. "strings"
  7. "sync"
  8. "time"
  9. . "git.eugeniocarvalho.dev/eugeniucarvalho/apicodegen/common"
  10. G "github.com/dave/jennifer/jen"
  11. "github.com/davecgh/go-spew/spew"
  12. )
  13. type Middleware struct {
  14. Id string `json:"id"`
  15. Type string `json:"type"`
  16. Fn func(ctx *MiddlewareContext) error `json:"-"`
  17. }
  18. type MiddlewareContext struct {
  19. Project *Project
  20. Method *Method
  21. Statement *G.Statement
  22. Middleware *Middleware
  23. File *G.File
  24. }
  25. var (
  26. Middlewares = map[string]*Middleware{
  27. "post": GenCreateStmts,
  28. "put": GenUpdateStmts,
  29. "patch": GenPatchStmts,
  30. "delete": GenDeleteStmts,
  31. "get_one": GenGetStmtsOne,
  32. "filter": GenGetFilter,
  33. "get_list": GenGetStmtsList,
  34. "undelete": GenUndeleteStmts,
  35. "implement": GenImplement,
  36. }
  37. ResourceWG = sync.WaitGroup{}
  38. )
  39. func InitFile(file *G.File, resource *Resource, p *Project) {
  40. now := time.Now().UnixNano()
  41. // file.ImportAlias(
  42. // file.ImportName(
  43. // fmt.Sprintf("%s/%s/models", p.Custom["go.package.repository"].(string), p.Package),
  44. // "models",
  45. // )
  46. if _, defined := p.Custom["go.package.repository"]; !defined {
  47. panic("go.package.repository not defined in project.json")
  48. }
  49. file.Var().Defs(
  50. G.Id(fmt.Sprintf("_%s_bson_%d_ *", resource.Entity, now)).Qual(BSON, "M"),
  51. G.Id(fmt.Sprintf("_%s_error_%d_ *", resource.Entity, now)).Qual(API_ERROR, "Error"),
  52. G.Id(fmt.Sprintf("_%s_sync_%d_ *", resource.Entity, now)).Qual("sync", "WaitGroup"),
  53. G.Id(fmt.Sprintf("_%s_primitive_%d_ *", resource.Entity, now)).Qual("go.mongodb.org/mongo-driver/bson/primitive", "ObjectID"),
  54. G.Id(fmt.Sprintf("_%s_models_%d_ *", resource.Entity, now)).Qual(
  55. fmt.Sprintf("%s/build/%s/models", p.Custom["go.package.repository"].(string), p.Package),
  56. "Entity",
  57. ),
  58. G.Id(fmt.Sprintf("_%s_actions_%d_ *", resource.Entity, now)).Qual(
  59. fmt.Sprintf("%s/build/%s/actions", p.Custom["go.package.repository"].(string), p.Package),
  60. "Action",
  61. ),
  62. )
  63. file.Func().Id("init").Params().BlockFunc(func(s *G.Group) {
  64. for _, v := range resource.Formats {
  65. s.Add(G.Id("FormatSelection").Index(G.Lit(resource.ID + "." + v.Id)).Op("=").Lit(v.Fields))
  66. }
  67. })
  68. }
  69. func CreateDummy(p *Project, resource *Resource, method *Method) error {
  70. // Verifica se existe um arquivo na pasta de include.
  71. // Caso o arquivo não exista um novo arquivo é criado.
  72. outputfile := fmt.Sprintf("%s/include/go/%s_%s.go", CurrentDirectory, strings.ToLower(resource.ID), strings.ToLower(method.ID))
  73. if _, err := os.Stat(outputfile); os.IsNotExist(err) {
  74. file := G.NewFile(p.Package)
  75. file.Comment(method.Description)
  76. if o, err := json.MarshalIndent(method, "", " "); err == nil {
  77. file.Comment(string(o))
  78. }
  79. file.Func().Params(
  80. G.Id("t").Op("*").Id(ResourceStructId(resource)),
  81. ).Id(method.ID).Params(
  82. G.Id("ctx").Qual(IRIS_CTX, "Context"),
  83. ).Params(
  84. G.Id("resp").Interface(),
  85. G.Id("err").Op("*").Qual(API_ERROR, "Error"),
  86. ).Block(G.Return())
  87. // if err = Write(path, file); err != nil {
  88. // return err
  89. // }
  90. return Write(outputfile, file)
  91. }
  92. return nil
  93. }
  94. func GenResources(p *Project) (err error) {
  95. var (
  96. file *G.File
  97. path string
  98. )
  99. if err = generateActionCommonFile(p); err != nil {
  100. return
  101. }
  102. for _, resource := range p.Resources {
  103. // Registra os campos retornados nos formatos do metodo list
  104. // FormatMap = map[string]string{}
  105. // Cria um novo arquivo para cada recurso
  106. file = G.NewFile(p.Package)
  107. InitFile(file, resource, p)
  108. // Inseri os comentarios de cada recurso no inicio do arquivo
  109. file.Comment(resource.Description).Line()
  110. // Define um tipo para registrar os metodos da api
  111. file.Type().Id(ResourceStructId(resource)).Struct().Line()
  112. for _, method := range resource.Methods {
  113. switch method.Template {
  114. case "", "implement":
  115. CreateDummy(p, resource, method)
  116. default:
  117. GenMethod(p, file, resource, method)
  118. }
  119. }
  120. // file.Var().DefsFunc(func(s *G.Group) {
  121. // values := G.Dict{}
  122. // for k, v := range FormatMap {
  123. // values[G.Lit(k)] = G.Lit(v)
  124. // }
  125. // s.Add(
  126. // G.Id("Format" + resource.Entity).Op("=").Map(G.String()).String().Values(values),
  127. // )
  128. // })
  129. file.Func().Params(
  130. G.Id("t").Op("*").Id(ResourceStructId((resource))),
  131. ).Id("Fields").Params(
  132. G.Id("filter").Op("*").Qual(API_URL, "Filter"),
  133. ).Params(
  134. G.Id("err").Op("*").Qual(API_ERROR, "Error"),
  135. ).Block(
  136. G.Id(`
  137. if filter.Fields != nil {
  138. return
  139. }
  140. if filter.Format == "full" {
  141. filter.Fields = nil
  142. return
  143. }
  144. if fields, has := FormatSelection[`).Lit(fmt.Sprintf("%s.", resource.ID)).Id(`+filter.Format]; has {
  145. filter.Fields = api.MgoFields(fields)
  146. } else {
  147. err = errs.InvalidArgument().Details(&errs.Detail{
  148. Message: `).Qual("fmt", "Sprintf").Id(`("Invalid value for projection '%s'",filter.Format),
  149. })
  150. }
  151. return
  152. `),
  153. // G.If(
  154. // // G.List(G.Id("fields"), G.Id("has")).Op(":=").Id("FormatSelection"+resource.Entity).Index(G.Id("filter").Dot("Format")),
  155. // G.List(G.Id("fields"), G.Id("has")).Op(":=").Id("FormatSelection").Index(
  156. // G.Lit(resource.ID+".").Op("+").Id("filter").Dot("Format"),
  157. // ),
  158. // G.Id("has"),
  159. // ).Block(
  160. // G.Id("filter").Dot("Fields").Op("=").Id("api").Dot("MgoFields").Call(G.Id("fields")),
  161. // ).Else().Block(
  162. // G.Id("err").Op("=").Qual(API_URL, "Error").Call(
  163. // G.Qual(API_URL, "ERR_INVALID_PARAM_VALUE"),
  164. // G.Lit("Invalid value for %s"),
  165. // ),
  166. // // .Dot("Add").Call(
  167. // // G.Op("&").Qual(API_URL, "ErrDescription").Values(G.Dict{
  168. // // G.Id("Message"): G.Lit(""),
  169. // // }),
  170. // // ),
  171. // ),
  172. )
  173. // Fim do loop de methods
  174. // GenCall(f, resource)
  175. path = fmt.Sprintf("%s/%s/api_%s_gen.go", p.OutPath, p.Package, strings.ToLower(resource.ID))
  176. if err = Write(path, file); err != nil {
  177. return err
  178. }
  179. }
  180. // Fim do loop de recursos
  181. ResourceWG.Add(2)
  182. go GenIndexApi(p)
  183. ResourceWG.Wait()
  184. return nil
  185. }
  186. func GenQueries(p *Project, resourcesIdMap map[string]bool) {
  187. defer func() { ResourceWG.Done() }()
  188. if len(p.Queries.Queries) == 0 {
  189. return
  190. }
  191. file := G.NewFile(p.Package)
  192. queries := func(s *G.Statement) {
  193. var (
  194. query string
  195. found bool
  196. )
  197. for key, _ := range resourcesIdMap {
  198. if query, found = p.Queries.Queries[fmt.Sprintf("go.%s", key)]; !found {
  199. query = "{}"
  200. }
  201. s.Add(G.Qual(API_URL, "RegisterQuery(").Lit(key).Id(",").Lit(query).Id(")").Line())
  202. }
  203. }
  204. file.Id(`
  205. func init() {`).Do(queries).Id(`}`)
  206. if err := Write(fmt.Sprintf("%s/%s/%s_gen.go", p.OutPath, p.Package, "queries"), file); err != nil {
  207. panic(err)
  208. }
  209. }
  210. func GenIndexApi(p *Project) error {
  211. defer func() { ResourceWG.Done() }()
  212. var (
  213. stmt *G.Statement
  214. params string
  215. statments G.Statement
  216. idString string
  217. middlewares []string
  218. Index = G.NewFile(p.Package)
  219. RequestParams = G.Id(`RequestParams := `).Qual(CODE_GEN_V2_COMMON, "RequestParams")
  220. jwt = G.Id(`JWT := `).Qual(CODE_GEN_V2_AUTHORIZATION, "Handler")
  221. addJwt = false
  222. queryIndexsMap = map[string]bool{}
  223. callActionId = "apply"
  224. )
  225. statments = append(statments, G.Id(fmt.Sprintf("%s := ", callActionId)).Qual(API_URL, "CallAction"))
  226. statments = append(statments, RequestParams)
  227. // statments = append(statments)
  228. // Inicializa o mapa de filtros da api
  229. Index.Id(`
  230. var (
  231. filtersApiReference = map[string]*`).Qual(CODE_GEN_V2_COMMON, "ApiFilter").Id(`{}
  232. FormatSelection = map[string]string{}
  233. )
  234. func init(){
  235. var (
  236. entity *common.ApiFilter
  237. files []`).Qual("os", "FileInfo").Id(`
  238. path = "./filters"
  239. err error
  240. )
  241. files, _ = `).Qual(CODE_GEN_V2_COMMON, "GetFiles").Id(`(path)
  242. for _, file := range files {
  243. if !file.IsDir() {
  244. entity = &common.ApiFilter{}
  245. if err = common.ParseJson(`).Qual("path/filepath", "Join").Id(`(path, file.Name()), entity); err != nil {
  246. panic(err)
  247. }
  248. filtersApiReference[entity.Id] = entity
  249. }
  250. }
  251. }
  252. func executeAction(ctx context.Context, actions ...func(context.Context) (interface{}, *`).Qual(API_ERROR, "Error").Id(`)) (resp interface{},err *errs.Error){
  253. for _, action := range actions {
  254. if resp, err = action(ctx); err != nil || resp != nil {
  255. return
  256. }
  257. }
  258. return
  259. }
  260. `)
  261. for rindex, resource := range p.Resources {
  262. stmt = G.Line().Id(resource.ID).Op(":=").Id(ResourceStructId(resource)).Values().Line()
  263. for k, method := range resource.Methods {
  264. // fmt.Println("----------------------------")
  265. args := []G.Code{
  266. G.Lit(method.HttpMethod),
  267. G.Lit(p.GetPath(method)),
  268. }
  269. middlewares = []string{}
  270. if len(method.ParametersString) > 0 {
  271. params = strings.Join(method.ParametersString, ",")
  272. // fmt.Println(fmt.Sprintf(`%s|RequestParams("%s", UserRequestParams)`, API_URL, params))
  273. stmt.Add(G.Line().Comment(
  274. "Lista de parametros a serem validados durante a requisição",
  275. ).Line().Id(fmt.Sprintf(`args%d%d := "%s"`, rindex, k, params)).Line())
  276. middlewares = append(middlewares, fmt.Sprintf(`RequestParams(args%d%d, UserRequestParams)`, rindex, k))
  277. }
  278. middlewares = append(middlewares, p.Middlewares...)
  279. middlewares = append(middlewares, method.Middlewares...)
  280. data := map[string]interface{}{
  281. "ResourceId": resource.ID,
  282. "MethodId": method.ID,
  283. }
  284. idString = fmt.Sprintf("%s:%s", resource.ID, method.ID)
  285. queryIndexsMap[idString] = true
  286. for _, m := range middlewares {
  287. if strings.Contains(m, "JWT") && !addJwt {
  288. addJwt = true
  289. RequestParams.Line().Add(jwt)
  290. }
  291. m = ResolveParams(m, data)
  292. parts := strings.Split(m, "|")
  293. // Quando parts possui tamanho maior que
  294. // significa que foi especificado um middleware de outro pacote.
  295. if len(parts) > 1 {
  296. args = append(args, G.Line().Id(callActionId).Call(
  297. G.Id(parts[1]),
  298. G.Qual(parts[0], parts[1]),
  299. ))
  300. } else {
  301. args = append(args, G.Line().Id(callActionId).Call(
  302. G.Lit(m),
  303. G.Id(m),
  304. ))
  305. }
  306. }
  307. args = append(args, G.Line().Id(callActionId).Call(
  308. G.Lit(fmt.Sprintf("%s.%s", resource.ID, method.ID)),
  309. G.Id(resource.ID).Dot(method.ID),
  310. ))
  311. if len(method.Postresponse) > 0 {
  312. args = append(args, G.Line().Id(method.Postresponse[0]))
  313. }
  314. stmt.Add(G.Line().Comment(method.Description).Line().Id("app").Dot("Handle").Call(args...).Line())
  315. }
  316. statments = append(statments, stmt)
  317. }
  318. // Cria a funcao que trata os filtros
  319. // statments = append(statments, G.Line().Comment("Filter request").Line().Id("app").Dot("Handle").Call(
  320. // G.Lit("GET"),
  321. // G.Lit(p.BasePath+"/filters/{id:string}"),
  322. // // G.Func().Params(G.Id("ctx").Qual(IRIS_CTX, "Context")).Block(),
  323. // G.Id(fmt.Sprintf(`FilterHandle("../api/%s/filters")`, p.Package)),
  324. // ))
  325. // Cria a funcao que trata os metodos options
  326. statments = append(statments, G.Line().Comment("Options request").Line().Id("app").Dot("Options").Call(
  327. G.Lit("/{url:path}"),
  328. G.Func().Params(G.Id("ctx").Qual(IRIS_CTX, "Context")).Block(
  329. G.Id(`ctx.ResponseWriter().Header().Set("Access-Control-Allow-Origin", ctx.GetHeader("Origin"))`),
  330. ),
  331. ))
  332. // Cria a funcao que registra as urls da api no arquivo api_index_gen.go
  333. Index.Func().Id("Register").Params(
  334. G.Id("app").Op("*").Qual(IRIS, "Application"),
  335. ).Block(
  336. statments...,
  337. ).Line()
  338. go GenQueries(p, queryIndexsMap)
  339. return Write(fmt.Sprintf("%s/%s/api_index_gen.go", p.OutPath, p.Package), Index)
  340. }
  341. func GenMethod(p *Project, f *G.File, r *Resource, method *Method) error {
  342. f.Comment(method.Description)
  343. if o, err := json.MarshalIndent(method, "", " "); err == nil {
  344. f.Comment(string(o))
  345. }
  346. stmt := f.Func().Params(
  347. // G.Id("t").Op("*").Id(strings.Title(r.ID)),
  348. G.Id("t").Op("*").Id(ResourceStructId(r)),
  349. ).Id(method.ID).Params(
  350. G.Id("ctx").Qual(IRIS_CTX, "Context"),
  351. // G.Id("resp").Op("*").Qual(API_URL, "ApiResponse"),
  352. ).Params(
  353. G.Id("resp").Interface(),
  354. G.Id("err").Op("*").Qual(API_ERROR, "Error"),
  355. )
  356. generateActionsFiles(p, f, r, method)
  357. if middle, found := Middlewares[method.Template]; found {
  358. ctx := &MiddlewareContext{
  359. Project: p,
  360. Method: method,
  361. Middleware: middle,
  362. Statement: stmt,
  363. File: f,
  364. }
  365. return middle.Fn(ctx)
  366. }
  367. return fmt.Errorf("Method '%s' template not defined!", method.ID)
  368. }
  369. func generateActionCommonFile(p *Project) (err error) {
  370. path := fmt.Sprintf(
  371. "%s/include/go/actions/index_gen.go",
  372. CurrentDirectory,
  373. )
  374. if _, fileErr := os.Stat(path); os.IsNotExist(fileErr) {
  375. file := G.NewFile("actions")
  376. file.Id(`
  377. type Action struct {
  378. ID string
  379. }
  380. `).Line()
  381. err = Write(path, file)
  382. }
  383. return
  384. }
  385. func generateActionsFiles(p *Project, f *G.File, r *Resource, method *Method) {
  386. actions := []Action{}
  387. if method.Preconditions != nil {
  388. actions = append(actions, method.Preconditions...)
  389. }
  390. if method.BeforeResponse != nil {
  391. actions = append(actions, method.BeforeResponse...)
  392. }
  393. for _, action := range actions {
  394. path := fmt.Sprintf(
  395. "%s/include/go/actions/%s_gen.go",
  396. CurrentDirectory,
  397. action.ID,
  398. // method.Entity,
  399. // method.ID,
  400. // hookId,
  401. )
  402. if _, fileErr := os.Stat(path); os.IsNotExist(fileErr) {
  403. // methodId := fmt.Sprintf("%s%s%s", strings.Title(hookId), method.Entity, strings.Title(method.ID))
  404. file := G.NewFile("actions")
  405. context := map[string]interface{}{
  406. "imports": map[string]string{
  407. "errs": "git.eugeniocarvalho.dev/eugeniucarvalho/apicodegen/api/errs",
  408. "context": "github.com/kataras/iris/v12/context",
  409. },
  410. "function": strings.Title(action.ID),
  411. "hasContext": action.Context != nil,
  412. }
  413. spew.Dump(action.ID)
  414. spew.Dump(action.Context)
  415. out, _ := TemplateToString(hookStmtsTmpl, context)
  416. file.Id(out).Line()
  417. Write(path, file)
  418. }
  419. }
  420. // for hookId, _ := range method.Hooks {
  421. // // methodId := fmt.Sprintf("%s%s%s", strings.Title(hookId), method.Entity, strings.Title(method.ID))
  422. // path := fmt.Sprintf(
  423. // "%s/include/go/actions/%s_%s_%s_gen.go",
  424. // CurrentDirectory,
  425. // method.Entity,
  426. // method.ID,
  427. // hookId,
  428. // )
  429. // if _, fileErr := os.Stat(path); os.IsNotExist(fileErr) {
  430. // file := G.NewFile(p.Package)
  431. // context := map[string]interface{}{
  432. // "imports": map[string]string{
  433. // // "api": "git.eugeniocarvalho.dev/eugeniucarvalho/apicodegen/api",
  434. // "errs": "git.eugeniocarvalho.dev/eugeniucarvalho/apicodegen/api/errs",
  435. // "context": "github.com/kataras/iris/v12/context",
  436. // },
  437. // }
  438. // out, _ := TemplateToString(hookStmtsTmpl, context)
  439. // file.Id(out).Line()
  440. // Write(path, file)
  441. // }
  442. // }
  443. }
  444. func GenFromGenericModel(p *Project, entity *EntityInfo) {
  445. var (
  446. posfix string
  447. propertie *G.Statement
  448. tproperties G.Statement
  449. // file = G.NewFile(p.Package)
  450. file = G.NewFile("models")
  451. cproperties = map[string]*G.Statement{}
  452. properties = G.Statement{}
  453. values = G.Dict{}
  454. model = p.GetSchema(entity.Name)
  455. entityName = entity.NewName
  456. // filename = "model_" + strings.ToLower(entityName)
  457. filename = "models/" + CamelToUnder(entityName)
  458. propName string
  459. )
  460. for _, meta := range model.Properties {
  461. propName = UpFirst(meta.ID)
  462. propertie = G.Id(propName)
  463. meta.FillTags(p, propName)
  464. posfix = ""
  465. // Registra a relaao entre as entidades
  466. if meta.Relation {
  467. posfix = "Ref"
  468. SR.Add(&Relation{
  469. Source: meta.GetType(),
  470. Target: model.ID,
  471. Attr: strings.Replace(meta.Tags["bson"], ",omitempty", "", 1),
  472. DB: model.DB,
  473. Collection: model.Collection,
  474. IsArray: meta.Array,
  475. })
  476. }
  477. if meta.Array {
  478. propertie.Index()
  479. }
  480. propertie.Id(entity.TranslateType(meta.Type) + posfix)
  481. // propertie.Id(meta.Type + posfix)
  482. // Adiciona as tags caso sejam definidas
  483. if meta.Tags != nil {
  484. propertie.Tag(meta.Tags)
  485. // if name, ok := meta.Tags["json"]; ok {
  486. // }
  487. }
  488. // Adiciona a crescricao como comentario
  489. if meta.Description != "" {
  490. propertie.Comment(meta.Description)
  491. }
  492. cproperties[meta.ID] = propertie
  493. if meta.ID == "ID" {
  494. values[G.Id("ID")] = G.Qual(BSON_PRIMITIVE, "NewObjectID").Call()
  495. }
  496. // Verifica se possui valor padrão
  497. if meta.Default != nil {
  498. values[G.Id(meta.ID)] = G.Lit(meta.Default)
  499. }
  500. properties = append(properties, propertie)
  501. }
  502. if model.Representations != nil {
  503. for posfix, rep := range model.Representations {
  504. tproperties = G.Statement{}
  505. for _, attr := range rep {
  506. tproperties = append(tproperties, cproperties[attr])
  507. }
  508. file.Comment(
  509. "Representação " + posfix,
  510. ).Line().Type().Id(
  511. model.ID + posfix,
  512. ).Struct(tproperties...)
  513. }
  514. }
  515. // Cria a entidade normal
  516. file.Line().Comment(model.Description).Line().Comment("Representação Completa")
  517. file.Type().Id(entityName).Struct(properties...)
  518. file.Comment(fmt.Sprintf("Cria uma instancia de %s.", entityName))
  519. // Cria a função de instanciar um novo elemento com os valores padrão determinados
  520. file.Func().Id("New" + entityName).Params().Op("*").Id(entityName).Block(
  521. G.Return(G.Op("&").Id(entityName).Values(values)),
  522. )
  523. // Salva o arquivo da entidade
  524. // if err := f.Save(fmt.Sprintf("%s/%s/%s_gen.go", p.OutPath, p.Package, filename)); err != nil {
  525. // fmt.Printf("%s/%s/%s_gen.go", p.OutPath, p.Package, filename)
  526. if err := Write(fmt.Sprintf("%s/%s/%s_gen.go", p.OutPath, p.Package, filename), file); err != nil {
  527. panic(err)
  528. }
  529. }
  530. func Write(path string, file *G.File) error {
  531. // fmt.Println(fmt.Sprintf("Write -> %#v", path))
  532. return FilePutContents(path, fmt.Sprintf("%#v", file), 0777)
  533. }
  534. func ResourceStructId(resource *Resource) string {
  535. return strings.Title(resource.ID) + "Resource"
  536. }