Tool that can parse Go files into an abstract syntax tree and translate it to several programming languages.

GoDMT

Build Go Report Card PkgGoDev Maintainability codecov 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 tested operating systems are:

  • Linux (amd64)
  • FreeBSD (amd64)
  • macOS (amd64)
  • Windows (amd64)

Feel free to expand this list if you have successfully used the tool in other environments. You will find pre-compiled binaries of the tool in the releases page.

Talk is cheap, show code

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

Usage

See the CLI Usage wiki page for more details on using the tool.

See the Tags and Name Conversion section to understand more about how entities get parsed and converted to other languages.

Building

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

Owner
Josep Jesus Bigorra Algaba
Software Engineer, Backend/Middleware
Josep Jesus Bigorra Algaba
Comments
  • Fix: godmt may break because of invalid path on windows.

    Fix: godmt may break because of invalid path on windows.

    Closes #12

    The code successfully executed on windows with expected results, without modifying the code. However, transforming the directory paths to a unified format may save us in some cases.

  • Configure WhiteSource Bolt for GitHub

    Configure WhiteSource Bolt for GitHub

    Welcome to WhiteSource Bolt for GitHub! This is an onboarding PR to help you understand and configure settings before WhiteSource starts scanning your repository for security vulnerabilities.

    :vertical_traffic_light: WhiteSource Bolt for GitHub will start scanning your repository only once you merge this Pull Request. To disable WhiteSource Bolt for GitHub, simply close this Pull Request.


    What to Expect

    This PR contains a '.whitesource' configuration file which can be customized to your needs. If no changes were applied to this file, WhiteSource Bolt for GitHub will use the default configuration.

    Before merging this PR, Make sure the Issues tab is enabled. Once you merge this PR, WhiteSource Bolt for GitHub will scan your repository and create a GitHub Issue for every vulnerability detected in your repository.

    If you do not want a GitHub Issue to be created for each detected vulnerability, you can edit the '.whitesource' file and set the 'minSeverityLevel' parameter to 'NONE'.


    :question: Got questions? Check out WhiteSource Bolt for GitHub docs. If you need any further assistance then you can also request help here.

  • Let users specify the output directory

    Let users specify the output directory

    Is your feature request related to a problem? Please describe.

    The users may want to put the generated files to a desired directory.

    Describe the solution you'd like

    A flag, preferably `-o=path/to/output/dir", can help.

    Describe alternatives you've considered N/A

    Additional context N/A

  • When the json label is not given a syntax error occurs

    When the json label is not given a syntax error occurs

    type Example struct {
      ID string `uri:"id"`
    }
    

    for example this will generate:

    export interface Example {
    	"`uri:"id"`": string;
    }
    

    and should generate:

    export interface Example {
    	ID: string;
    }
    

    A the name should be used as a fallback for a json label.


    Here is a happy flow with json label:

    type Example struct {
      ID string `json:"id"`
    }
    
    export interface Example {
    	id: string;
    }
    
  • [ImgBot] Optimize images

    [ImgBot] Optimize images

  • Support iota enums

    Support iota enums

    In Go you can use the special iota expression for auto incrementing values of an enum. This should be supported in GoDMT by translating those enums to the correct value (based on position)

  • Slice of imported entity is not correctly translated.

    Slice of imported entity is not correctly translated.

    Describe the bug When a struct has a field that is an imported entity, and in the form of a slice of those entities, the translation is not correct.

    Expected behavior

    Media       []ProductCategoryImage `json:"media"`
    

    would produce:

    media: ProductCategoryImage[];
    

    Actual result

    Media       []ProductCategoryImage `json:"media"`
    

    produces:

    media: ProductCategoryImage | null[];
    

    OS (please complete the following information):

    • macOS
    • Big Sur
  • Reduce usage of package reflect

    Reduce usage of package reflect

    There is actually no valid reason (apart from laziness) to use the reflect package for GoDMT. Reducing its usage as much as possible will bring more performance, type safety, cleaner code and more handling of edge cases.

  • PHP embedded structs support

    PHP embedded structs support

    Some creativity and investigation will be required for this. My idea is to create a second class perhaps and an instance property of the parent class whose type is the 2nd class.

Generate plantuml diagrams from go source files or directories
Generate plantuml diagrams from go source files or directories

go-plantuml go-plantuml generates plantuml diagrams from go source files or directories. Installation go get -u github.com/bykof/go-plantuml Please co

Jan 1, 2023
gosivy - Another visualization tool for Go process metrics
gosivy - Another visualization tool for Go process metrics

gosivy Another visualization tool for Go process metrics. Gosivy tracks Go process's metrics and plot their evolution over time right into your termin

Nov 27, 2022
Tool to visualize the graph of embedded structs in Go projects
Tool to visualize the graph of embedded structs in Go projects

Visualize a hierarchy of embedded Go structs This tool scans a directory of Go source code files to create a visualization of struct embedding in the

Nov 27, 2022
Interactive dependency graph visualization tool for golang
Interactive dependency graph visualization tool for golang

Interactive dependency graph visualization tool for golang using the awesome cytoscape graph visualizer.

Sep 1, 2022
An SVG-based tool to visualize public transport journeys retrieved from a HAFAS system
An SVG-based tool to visualize public transport journeys retrieved from a HAFAS system

Time-Space Train Planner An SVG-based tool to visualize public transport journeys retrieved from a HAFAS system, in order to see all possible connecti

Dec 17, 2022
Helm : a tool for managing Charts

Helm is a tool for managing Charts. Charts are packages of pre-configured Kubernetes resources.

Aug 25, 2022
A repository for plotting and visualizing data

gonum/plot is the new, official fork of code.google.com/p/plotinum. It provides an API for building and drawing plots in Go

Jan 5, 2023
Callgraph analysis and visualization for Go
Callgraph analysis and visualization for Go

Gocyto A Go SSA callgraph builder and visualizer, by @protolambda. Features: output to generic Cytoscape JSON format. (list of nodes, list of edges) o

Nov 3, 2022
A repository for plotting and visualizing data

Gonum Plot gonum/plot is the new, official fork of code.google.com/p/plotinum. It provides an API for building and drawing plots in Go. Note that this

Jun 3, 2021
Interactive Terraform visualization. State and configuration explorer.
Interactive Terraform visualization. State and configuration explorer.

Rover - Terraform Visualizer Rover is a Terraform visualizer. In order to do this, Rover: generates a plan file and parses the configuration in the ro

Jan 9, 2023
Ltree Visualizer - A golang library to visualize postgres ltree type data using DOT language and Graphviz
Ltree Visualizer - A golang library to visualize postgres ltree type data using DOT language and Graphviz

Ltree Visualizer A golang library to visualize postgres ltree type data using DOT language and Graphviz What is Ltree? Ltree is a data type which is u

Jun 12, 2022
termdbms: A TUI for viewing and editing databases, written in Go
 termdbms: A TUI for viewing and editing databases, written in Go

termdbms: A TUI for viewing and editing databases, written in Go Database Support SQLite made with modernc.org/sqlite, charmbracelet/bubbletea, and c

Dec 26, 2022
Using NFP (Number Format Parser) you can get an Abstract Syntax Tree (AST) from Excel number format expression

NFP (Number Format Parser) Using NFP (Number Format Parser) you can get an Abstract Syntax Tree (AST) from Excel number format expression. Installatio

Feb 4, 2022
Translate your Go program into multiple languages with similar fmt.Sprintf format syntax.

Loafer-i18n Loafer-i18n is a Go package and a command that helps you translate Go programs into multiple languages. Supports pluralized strings with =

Dec 22, 2021
go-i18n is a Go package and a command that helps you translate Go programs into multiple languages.

go-i18n is a Go package and a command that helps you translate Go programs into multiple languages.

Jan 2, 2023
Translate your Go program into multiple languages.

go-i18n go-i18n is a Go package and a command that helps you translate Go programs into multiple languages. Supports pluralized strings for all 200+ l

Jan 1, 2023
libraries for various programming languages that make it easy to generate per-process trace files that can be loaded into chrome://tracing
libraries for various programming languages that make it easy to generate per-process trace files that can be loaded into chrome://tracing

chrometracing: chrome://tracing trace_event files The chrometracing directory contains libraries for various programming languages that make it easy t

Oct 6, 2022
Split multiple Kubernetes files into smaller files with ease. Split multi-YAML files into individual files.

Split multiple Kubernetes files into smaller files with ease. Split multi-YAML files into individual files.

Dec 29, 2022
Split multiple Kubernetes files into smaller files with ease. Split multi-YAML files into individual files.

kubectl-slice: split Kubernetes YAMLs into files kubectl-slice is a neat tool that allows you to split a single multi-YAML Kubernetes manifest into mu

Jan 3, 2023
Show Languages In Code. A fast and lightweight CLI to generate stats on the languages inside your project
Show Languages In Code. A fast and lightweight CLI to generate stats on the languages inside your project

slic Show Languages In Code. Usage Run it with an -h flag to list all commands. -d flag can be used to specify the directory of search -i flag can be

Dec 25, 2021