Go data specification generator
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
drafts
gospec
.gitignore
.travis.yml
LICENSE.md
Makefile
README.md
main.go

README.md

go-specgen

Go specgen is a minimalistic library for generating format specification into various languages.

It uses Go semantics (see drafts/foo.gspec.go) and currently generates the specifications to various formats.

Features / Things to do

  • Add more languages/formats
    • C/C++
    • Go
    • JSON
    • Markdown
    • Python
    • Rust
    • C#
    • Java
  • k-d array support
  • Improve error handling
  • Implement enum types
  • Make use of field tags

How to use

Simply go get github.com/zaklaus/go-specgen/gospec or clone the repository.

Usage: Tool

You can compile go-specgen and use it as a tool to generate various outputs easily.

You can generate output to supported language by doing:

specgen --file=<path-to-file> --lang=<lang-mode>

such as

specgen --file=drafts/foo.gspec.go --lang=c

which will print out the output to the stdout stream.

For instance, you could pipe the output of Go lang into gofmt to get nicely formatted Go source code:

specgen --file=drafts/foo.gspec.go --lang=go | gofmt

Usage: Library

You can also use go-specgen as a library, for instance:

package main

import (
    "fmt"

    "github.com/zaklaus/go-specgen/gospec"
)

func main() {
    // Parse the gspec file containing data specifications
    ctx, err := gospec.ParseFile("drafts/foo.gspec.go")

    if err != nil {
        fmt.Printf("Error: %v\n", err)
        return
    }

    // Export it to Markdown tables
    ctx.ExportMD()
}

You can also look at main.go itself.

License

This project is licensed under Apache 2.0, see LICENSE.md