File: README.md

package info (click to toggle)
golang-github-francoispqt-gojay 1.2.13-5
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 1,456 kB
  • sloc: makefile: 86
file content (61 lines) | stat: -rw-r--r-- 1,620 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# Gojay code generator
This package provides a command line tool to generate gojay's marshaling and unmarshaling interface implementation for custom struct type(s)


## Get started

```sh
go install github.com/francoispqt/gojay/gojay
```

## Generate code

### Basic command
The basic command is straightforward and easy to use:
```sh
cd $GOPATH/src/github.com/user/project
gojay -s . -p true -t MyType -o output.go
```
If you just want to the output to stdout, omit the -o flag.

### Using flags
- s Source file/dir path, can be a relative or absolute path
- t Types to generate with all its dependencies (comma separated)
- a Annotation tag used to read metadata (default: json)
- o Output file (relative or absolute path)
- p Pool to reuse object (using sync.Pool)

Examples:

- Generate `SomeType` type in `/tmp/myproj` go package, write to file `output.go`:
```sh
gojay -s /tmp/myproj -t SomeType -o output.go
```

- Generate type `SomeType` in file `somegofile.go`, with custom tag `gojay`, write to stdout:
```sh
gojay -s somegofile.go -a gojay -t SomeType
```


## Generator tags
You can add tags to your structs to control:

- the JSON key
- skip a struct field
- the use of omitempty methods for marshaling
- timeFormat (java style data format)
- timeLayout (golang time layout)


### Example:
```go
type A struct {
	Str          string     `json:"string"`
	StrOmitEmpty string     `json:"stringOrEmpty,omitempty"`
	Skip         string     `json:"-"`
	StartTime    time.Time  `json:"startDate" timeFormat:"yyyy-MM-dd HH:mm:ss"`
	EndTime      *time.Time `json:"endDate" timeLayout:"2006-01-02 15:04:05"`
}
```