All Projects → Xuanwo → gg

Xuanwo / gg

Licence: Apache-2.0 license
General Golang Code Generator

Programming Languages

go
31211 projects - #10 most used programming language
Makefile
30231 projects

Projects that are alternatives of or similar to gg

EasyEE-Auto
EasyEE 自动化代码生成器。EasyEE Automated code generator.
Stars: ✭ 39 (-55.68%)
Mutual labels:  code-generation, codegen
Graphql Typed Client
A tool that generates a strongly typed client library for any GraphQL endpoint. The client allows writing GraphQL queries as plain JS objects (with type safety, awesome code completion experience, custom scalar type mapping, type guards and more)
Stars: ✭ 194 (+120.45%)
Mutual labels:  code-generation, codegen
evon
Fast and versatile event dispatcher code generator for Golang
Stars: ✭ 15 (-82.95%)
Mutual labels:  code-generation, codegen
atbuild
Use JavaScript to generate JavaScript
Stars: ✭ 26 (-70.45%)
Mutual labels:  code-generation, codegen
CreateAPI
Delightful code generator for OpenAPI specs
Stars: ✭ 176 (+100%)
Mutual labels:  code-generation, codegen
Graphqlgen
⚙️ Generate type-safe resolvers based upon your GraphQL Schema
Stars: ✭ 796 (+804.55%)
Mutual labels:  code-generation, codegen
Weaver
Dependency Injection framework for Swift (iOS/macOS/Linux)
Stars: ✭ 546 (+520.45%)
Mutual labels:  code-generation, codegen
Xcassetpacker
A command line tool for converting a folder of images into an .xcasset package for Xcode
Stars: ✭ 150 (+70.45%)
Mutual labels:  code-generation, codegen
Syncmap
A typed implementation of the Go sync.Map using code generation
Stars: ✭ 200 (+127.27%)
Mutual labels:  code-generation
Kotlinpoet
A Kotlin API for generating .kt source files.
Stars: ✭ 3,004 (+3313.64%)
Mutual labels:  code-generation
Charlatan
Go Interface Mocking Tool
Stars: ✭ 195 (+121.59%)
Mutual labels:  code-generation
Convalida
A simple, lightweight and powerful field validation library for Android.
Stars: ✭ 201 (+128.41%)
Mutual labels:  code-generation
generator
Any Code generator
Stars: ✭ 421 (+378.41%)
Mutual labels:  codegen
pony-capnp
Cap’n Proto plugin for generating serializable Pony classes. 🐴 - 🎩'n 🅿️
Stars: ✭ 19 (-78.41%)
Mutual labels:  code-generation
Swift Enum Properties
🤝 Struct and enum data access in harmony.
Stars: ✭ 191 (+117.05%)
Mutual labels:  code-generation
Pylustrator
Visualisations of data are at the core of every publication of scientific research results. They have to be as clear as possible to facilitate the communication of research. As data can have different formats and shapes, the visualisations often have to be adapted to reflect the data as well as possible. We developed Pylustrator, an interface to directly edit python generated matplotlib graphs to finalize them for publication. Therefore, subplots can be resized and dragged around by the mouse, text and annotations can be added. The changes can be saved to the initial plot file as python code.
Stars: ✭ 192 (+118.18%)
Mutual labels:  code-generation
go-zero
A cloud-native Go microservices framework with cli tool for productivity.
Stars: ✭ 23,294 (+26370.45%)
Mutual labels:  code-generation
sisyphus-js
Sisyphus customized protobuf and gRPC runtime and code generator for JavaScript/TypeScript
Stars: ✭ 19 (-78.41%)
Mutual labels:  code-generation
Amplication
Amplication is an open‑source development tool. It helps you develop quality Node.js applications without spending time on repetitive coding tasks.
Stars: ✭ 3,630 (+4025%)
Mutual labels:  code-generation
Weld
High-performance runtime for data analytics applications
Stars: ✭ 2,709 (+2978.41%)
Mutual labels:  code-generation

Build Status Go dev License matrix

gg

gg is a General Golang Code Generator: A Good Game to play with Golang.

package main

import (
	"fmt"

	. "github.com/Xuanwo/gg"
)

func main() {
	f := NewGroup()
	f.AddPackage("main")
	f.NewImport().
		AddPath("fmt")
	f.NewFunction("main").AddBody(
		String(`fmt.Println("%s")`, "Hello, World!"),
	)
	fmt.Println(f.String())
}

Output (after go fmt)

package main

import "fmt"

func main() {
	fmt.Println("Hello, World!")
}

Design

gg is a general golang code generator that designed for resolving problems exists in the following tools:

  • text/template: Additional syntax, Steep learning curve, Complex logic is difficult to maintain
  • dave/jennifer: Overly abstract APIs, user need to take care about (), , everywhere.
  • kubernetes-sigs/kubebuilder: Parse data from struct tags/comments, not a general code generator.

In short, gg will provide near-native golang syntax and helpful API so play a good game with Golang. With gg, we can generate golang code more easily and understandable.

Usage

Package Name

f := Group()
f.AddPackage("main")
// package main

Imports

f := Group()
f.NewImport().
    AddPath("context").
	AddDot("math").
	AddBlank("time").
	AddAlias("x", "testing")
// import (
//      "context"
//      . "math"
//      _ "time"
//      x "testing"
// )

Function

f := Group()
f.NewFunction("hello").
    WithReceiver("v", "*World").
    AddParameter("content", "string").
    AddParameter("times", "int").
    AddResult("v", "string").
    AddBody(gg.String(`return fmt.Sprintf("say %s in %d times", content, times)`))
// func (v *World) hello(content string, times int) (v string) {
//  return fmt.Sprintf("say %s in %d times", content, times)
//}

Struct

f := Group()
f.NewStruct("World").
    AddField("x", "int64").
    AddField("y", "string")
// type World struct {
//    x int64
//    y string
//}

Acknowledgement

  • gg is inspired by dave/jennifer, I borrowed most ideas and some code from it. Nice work!
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].