Code Monkey home page Code Monkey logo

type2md's Introduction

Type2md - Golang Type To Markdown

Support to define golang data type as markdown table

  • Support for custom structure tags
  • Support annotation parsing
  • Support default value definition
  • support is required
  • Support external mod type reference resolution.

Usage

$ type2md -h
Usage of type2md:
  -f string
        file path
  -t string
        file title
  -tag string
        struct tag name (default "json")
  -v    show version

Example

package test

import "github.com/eleztian/type2md/test/ext"

//go:generate type2md -f ../docs/doc_config.md github.com/eleztian/type2md/test Config

// Config doc.
type Config struct {
	Pre     ext.Hook
	Post    *ext.Hook
	Servers map[string]struct {
		Host string `json:"host,omitempty"`
		Port int    `json:"port" enums:"22,65522" require:"false"`
	} `json:"servers"` // server list
	InlineStruct `json:",inline"` // inline struct
	Slice        []string         // sss
	MapData      map[string]map[int]*OtherStruct
	ArrayData    [][2]string   `json:"array_data"`
	C            []interface{} // slice interface{}
}

// InlineStruct inline struct.
type InlineStruct struct {
	A string `json:"a"` // inline struct field a
}

// OtherStruct other struct
// this is use for test.
type OtherStruct struct {
	A string                 `json:"a" require:"true" default:"default value"`
	B [][2]ext.Mode          `json:"b"` // array string
	C map[string]interface{} `json:"c"` // map[string]interface{}
	D *OtherStruct           `json:"d"` // nested struct
}

execute the following commands

$ go generate  ./...          
2022/10/28 23:56:16 Current Module: github.com/eleztian/type2md
2022/10/28 23:56:16 start generate github.com/eleztian/type2md/test.Config
2022/10/28 23:56:16 start to save to ../docs/doc_config.md

Get the following documentation:

Config Doc

Config doc.

Key Type Require Default Describe
Pre Hook true
Post Hook true
servers.{string}.host string false
servers.{string}.port int false - 22
- 65522
a string true inline struct field a.
Slice.[] string true sss.
MapData.{string}.{int}. OtherStruct true
array_data.[] .[2] string true
C.[] any true slice interface{}.
ext.Hook

Hook hook config.

Key Type Require Default Describe
name string false example hook name.
commands.[] string true command list.
envs.{string} string true env key map.
mode Mode true 1 run mode.
OtherStruct

OtherStruct other struct this is use for test.

Key Type Require Default Describe
a string true default value
b.[] .[2] Mode true array string.
c.{string} any true map[string] interface{}.
d OtherStruct true nested struct.
ext.Mode

Type: int Mode mode define.

Enum Value Describe
1 mode q.
2 mode a.

github.com/eleztian/type2md/test.Config GENERATED BY THE COMMAND type2md

type2md's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.