godmt

module
v1.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 31, 2020 License: MIT

README

GoDMT

Build Go Report Card PkgGoDev Maintainability codecov Issues License

GoDMT, the one and only Go Data Model Translator. The goal of this project is to provide a tool that can parse Go files that include var, const, map, struct and type into an abstract syntax tree, aka AST.

That AST will then be transformed into data models for several programming languages. Currently GoDMT can perform translations to:

  • TypeScript
  • Swift (using Decodable structs)
  • JSON
  • PHP

Some small adjustments may need to be made to integrate the output into a project, but this should already save you a lot of time and hassle, and will help you stay in sync with the Go version of your data models, in other languages. Comments will be carried over 😉.

Currently, the supported operating systems are all of UNIX family:

  • Linux
  • BSD
  • macOS

Talk is cheap, show code

Feel free to browse some examples that I am happy to provide here:

Usage

go run main.go -dir={scanDirectory} -translation={language} -preserve -tree
  • scanDirectory represents a string that is the relative path of the directory whose Go files you want to scan. The scan occurs in a recursive manner, so all files from all contained folders will be scanned.
  • language represents the output mode. If the -translation flag is not specified it will default to JSON. Currently supported options are:
    • ts or typescript for TypeScript conversion
    • swift for Swift conversion
    • json for JSON conversion
    • php for PHP conversion
  • preserve is an optional boolean flag which will make the output structs preserve the original names, instead of using the (json:"tag").
  • tree is an optional boolean that when present will prevent any file operations being performed, and instead will show you the full abstract syntax tree of your files in the standard output.

Example usage:

go run main.go -dir=../../tests/data/ -translation=ts

After a successful run, the program will output a result folder in the current working directory with subfolders for respective scanned packages. Filenames will be respected and maintained, with only changes to the extension.

Building

To build this application as a binary simply navigate to cmd/godmt and run go build.

Directories

Path Synopsis
cmd
godmt command
internal
pkg
tests

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL