Skip to content

treepeck/gtt

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

GTT [Go Types Transpiler] transpiles the var, const, and struct declarations found in the named Go source code file into the JS with JSDoc types.

It is mostly usefull to keep transport-layer types synchronized between backend and frontend in projects that are written in Go and JS.

The development process is available on YouTube

Note

Only structs, vars (even with implicit types), and constants are supported. Comments are preserved in the transpiled code. All transpiled declarations are sorted in the Alphabetical order.

Example

The source code:

package test

// messageKind is enum.
type messageKind int

const (
	// messagePing is sent by the server to maintain a heartbeat and detect idle
	// connections. The payload contains the network latency in milliseconds.
	messagePing messageKind = iota
	// messagePong must be sent by the client immediately after receiving a
	// [messagePing].
	messagePong
	messageClientsCounter
)

const strConst = "some stuff"

// message is a struct.
type message struct {
	Payload  []byte      `json:"p"`
	// Kind is struct field with json tag.
	Kind     messageKind `json:"k"`
	SenderId string      `json:"-"`
}

const pi float64 = 3.14

var z = 3
var x = 2
// c is the untyped int variable.
var c = 2

The transpiled code:

// Generated by https://github.com/treepeck/gtt

/**
 * c is the untyped int variable.
 * @type {number}
 */
let c = 2

/**
 * message is a struct.
 * @typedef {Object} message
 * @property {[]} p
 * @property {messageKind} k - Kind is struct field with json tag.
 */

/**
 * messageKind is enum.
 * @readonly
 * @enum {number}
 */
const messageKind = {
    messageClientsCounter: 2,
    // messagePing is sent by the server to maintain a heartbeat and detect idle
    // connections. The payload contains the network latency in milliseconds.
    messagePing: 0,
    // messagePong must be sent by the client immediately after receiving a
    // [messagePing].
    messagePong: 1,
}

/**
 * @type {number}
 */
const pi = 3.14

/**
 * @type {string}
 */
const strConst = "some stuff"

/**
 * @type {number}
 */
let x = 2

/**
 * @type {number}
 */
let z = 3

Usage

git clone https://github.com/treepeck/gtt
cd gtt
go run cmd/gtt/main.go -src {Path to .go} -dst {Path to .js}

LICENSE

Copyright (c) 2026 Artem Bielikov

This project is available under the Mozilla Public License, v. 2.0.
See the LICENSE file for details.

About

Go Types Transpiler

Topics

Resources

License

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages