Skip to content

Commit

Permalink
docs: update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
OhYee committed Oct 5, 2019
1 parent 6ce6158 commit aac37b7
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 9 deletions.
21 changes: 16 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,39 @@ Using json file and go template to generate go code.
## Installation

```bash
go get github.com/OhYee/gcg
go get -u github.com/OhYee/gcg
go install github.com/OhYee/gcg
```

## Usage

```bash
gcg data.json compare.go
gcg data.json
```

## Document

The json file must have these field:


|name|type||
|:---|:---|:---|
|variable|`map[string]interface{}`|gloable variable|
|files|`[]goFile`|the list of generated files|

goFile struct like below:

|name|type||
|:---|:---|:---|
|package|string|package name|
|package|`string`|package name|
|import|`[]string` or `[][]string`|import part of the file|
|body|`[]strut{template string, args interface{}}` or `[]struct{template []string, args interface{}}`|the go file body|
|output|`string`|the output filename|
|body|`[]strut{template string, args []interface{}}` or `[]struct{template []string, args []interface{}}`|the go file body|

The `template` and `args` in `body` will be the arguments of go `text/template`

If the item of `args` is `string`, and match `variable`'s key, it will be replaced to the value.

### Function

|name|args||
Expand All @@ -51,7 +62,7 @@ The `template` and `args` in `body` will be the arguments of go `text/template`

## Example

See [number compare package](https://github.com/OhYee/gcg/tree/master/example/compare), you can delete `compare.go` and using `gcg data.json compare.go` or `go generate g.go` to re-generate it.
See [number compare package](https://github.com/OhYee/gcg/tree/master/example/compare), you can delete `compare.go` and using `gcg data.json` or `go generate g.go` to re-generate it.

## LICENSE

Expand Down
18 changes: 14 additions & 4 deletions README_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,38 @@
## 安装

```
go get github.com/OhYee/gcg
go get -u github.com/OhYee/gcg
go install github.com/OhYee/gcg
```

## 使用

```
gcg data.json compare.go
gcg data.json
```

## 文档

JSON文件字段要求

|name|type||
|:---|:---|:---|
|variable|`map[string]interface{}`|全局变量|
|files|`[]goFile`|要生成的文件列表|

`goFile`结构如下:

|名称|类型||
|:---|:---|:---|
|package|string|生成文件的包名|
|import|`[]string` or `[][]string`|Go文件的引入包部分|
|body|`[]strut{template string, args interface{}}` or `[]struct{template []string, args interface{}}`|Go文件主体|
|output|`string`|输出文件名|
|body|`[]strut{template string, args []interface{}}` or `[]struct{template []string, args []interface{}}`|Go文件主体|

`body``template``args` 将用于 Go `text/template` 的参数

如果`args`的列表项为`string`,并且是`variable`的键,则它会被替换成对应的值

### 函数

|名称|参数||
Expand All @@ -51,7 +61,7 @@ JSON文件字段要求

## 样例

详情见 [大小比较包](https://github.com/OhYee/gcg/tree/master/example/compare), 你可以先删除 `compare.go` 然后使用 `gcg data.json compare.go` 或者 `go generate g.go` 来重新生成它.
详情见 [大小比较包](https://github.com/OhYee/gcg/tree/master/example/compare), 你可以先删除 `compare.go` 然后使用 `gcg data.json` 或者 `go generate g.go` 来重新生成它.

## 协议

Expand Down

0 comments on commit aac37b7

Please sign in to comment.