Add more meta fields (fix #6)

This commit is contained in:
Manfred Touron 2016-11-07 09:23:59 +01:00
parent 9e79d2b3aa
commit 84c1d65fd3
No known key found for this signature in database
GPG Key ID: 9CCF47DF1FD978A1
3 changed files with 856 additions and 8 deletions

View File

@ -3,8 +3,10 @@ package main
import ( import (
"bytes" "bytes"
"log" "log"
"os"
"path/filepath" "path/filepath"
"text/template" "text/template"
"time"
"github.com/golang/protobuf/protoc-gen-go/descriptor" "github.com/golang/protobuf/protoc-gen-go/descriptor"
"github.com/golang/protobuf/protoc-gen-go/plugin" "github.com/golang/protobuf/protoc-gen-go/plugin"
@ -20,9 +22,13 @@ type GenericTemplateBasedEncoder struct {
} }
type Ast struct { type Ast struct {
Filename string BuildDate time.Time `json:"build-date"`
Service *descriptor.ServiceDescriptorProto BuildHostname string `json:"build-hostname"`
File *descriptor.FileDescriptorProto BuildUser string `json:"build-user"`
Debug bool `json:"debug"`
File *descriptor.FileDescriptorProto `json:"file"`
Filename string `json:"filename"`
Service *descriptor.ServiceDescriptorProto `json:"service"`
} }
func NewGenericTemplateBasedEncoder(templateDir string, service *descriptor.ServiceDescriptorProto, file *descriptor.FileDescriptorProto, debug bool) (e *GenericTemplateBasedEncoder) { func NewGenericTemplateBasedEncoder(templateDir string, service *descriptor.ServiceDescriptorProto, file *descriptor.FileDescriptorProto, debug bool) (e *GenericTemplateBasedEncoder) {
@ -79,10 +85,14 @@ func (e *GenericTemplateBasedEncoder) buildContent(templateFilename string) (str
return "", err return "", err
} }
hostname, _ := os.Hostname()
ast := Ast{ ast := Ast{
Filename: templateFilename, BuildDate: time.Now(),
Service: e.service, BuildHostname: hostname,
File: e.file, BuildUser: os.Getenv("USER"),
File: e.file,
Filename: templateFilename,
Service: e.service,
} }
buffer := new(bytes.Buffer) buffer := new(bytes.Buffer)

View File

@ -1 +1,839 @@
{"Filename":"export.json.tmpl","Service":{"name":"DummyService","method":[{"name":"Hhh","input_type":".dummy.Dummy1","output_type":".dummy.Dummy2","options":{}},{"name":"Iii","input_type":".dummy.Dummy2","output_type":".dummy.Dummy1","options":{}}]},"File":{"name":"dummy.proto","package":"dummy","message_type":[{"name":"Dummy1","field":[{"name":"aaa","number":1,"label":1,"type":2,"json_name":"aaa"},{"name":"bbb","number":2,"label":1,"type":9,"json_name":"bbb"},{"name":"ccc","number":3,"label":1,"type":5,"json_name":"ccc"},{"name":"ddd","number":4,"label":1,"type":3,"json_name":"ddd"},{"name":"eee","number":5,"label":3,"type":9,"json_name":"eee"}]},{"name":"Dummy2","field":[{"name":"fff","number":1,"label":1,"type":2,"json_name":"fff"},{"name":"ggg","number":2,"label":1,"type":11,"type_name":".dummy.Dummy1","json_name":"ggg"}]},{"name":"Dummy3"}],"service":[{"name":"DummyService","method":[{"name":"Hhh","input_type":".dummy.Dummy1","output_type":".dummy.Dummy2","options":{}},{"name":"Iii","input_type":".dummy.Dummy2","output_type":".dummy.Dummy1","options":{}}]}],"source_code_info":{"location":[{"span":[0,0,22,1]},{"path":[12],"span":[0,0,18]},{"path":[2],"span":[2,8,13]},{"path":[4,0],"span":[4,0,10,1]},{"path":[4,0,1],"span":[4,8,14]},{"path":[4,0,2,0],"span":[5,2,16]},{"path":[4,0,2,0,4],"span":[5,2,4,16]},{"path":[4,0,2,0,5],"span":[5,2,7]},{"path":[4,0,2,0,1],"span":[5,8,11]},{"path":[4,0,2,0,3],"span":[5,14,15]},{"path":[4,0,2,1],"span":[6,2,17]},{"path":[4,0,2,1,4],"span":[6,2,5,16]},{"path":[4,0,2,1,5],"span":[6,2,8]},{"path":[4,0,2,1,1],"span":[6,9,12]},{"path":[4,0,2,1,3],"span":[6,15,16]},{"path":[4,0,2,2],"span":[7,2,16]},{"path":[4,0,2,2,4],"span":[7,2,6,17]},{"path":[4,0,2,2,5],"span":[7,2,7]},{"path":[4,0,2,2,1],"span":[7,8,11]},{"path":[4,0,2,2,3],"span":[7,14,15]},{"path":[4,0,2,3],"span":[8,2,16]},{"path":[4,0,2,3,4],"span":[8,2,7,16]},{"path":[4,0,2,3,5],"span":[8,2,7]},{"path":[4,0,2,3,1],"span":[8,8,11]},{"path":[4,0,2,3,3],"span":[8,14,15]},{"path":[4,0,2,4],"span":[9,2,26]},{"path":[4,0,2,4,4],"span":[9,2,10]},{"path":[4,0,2,4,5],"span":[9,11,17]},{"path":[4,0,2,4,1],"span":[9,18,21]},{"path":[4,0,2,4,3],"span":[9,24,25]},{"path":[4,1],"span":[12,0,15,1]},{"path":[4,1,1],"span":[12,8,14]},{"path":[4,1,2,0],"span":[13,2,16]},{"path":[4,1,2,0,4],"span":[13,2,12,16]},{"path":[4,1,2,0,5],"span":[13,2,7]},{"path":[4,1,2,0,1],"span":[13,8,11]},{"path":[4,1,2,0,3],"span":[13,14,15]},{"path":[4,1,2,1],"span":[14,2,17]},{"path":[4,1,2,1,4],"span":[14,2,13,16]},{"path":[4,1,2,1,6],"span":[14,2,8]},{"path":[4,1,2,1,1],"span":[14,9,12]},{"path":[4,1,2,1,3],"span":[14,15,16]},{"path":[4,2],"span":[17,0,17]},{"path":[4,2,1],"span":[17,8,14]},{"path":[6,0],"span":[19,0,22,1]},{"path":[6,0,1],"span":[19,8,20]},{"path":[6,0,2,0],"span":[20,2,37]},{"path":[6,0,2,0,1],"span":[20,6,9]},{"path":[6,0,2,0,2],"span":[20,10,16]},{"path":[6,0,2,0,3],"span":[20,27,33]},{"path":[6,0,2,1],"span":[21,2,37]},{"path":[6,0,2,1,1],"span":[21,6,9]},{"path":[6,0,2,1,2],"span":[21,10,16]},{"path":[6,0,2,1,3],"span":[21,27,33]}]},"syntax":"proto3"}} {
"build-date": "2016-11-07T09:21:48.495773574+01:00",
"build-hostname": "moul-rose.local",
"build-user": "moul",
"debug": false,
"file": {
"name": "dummy.proto",
"package": "dummy",
"message_type": [
{
"name": "Dummy1",
"field": [
{
"name": "aaa",
"number": 1,
"label": 1,
"type": 2,
"json_name": "aaa"
},
{
"name": "bbb",
"number": 2,
"label": 1,
"type": 9,
"json_name": "bbb"
},
{
"name": "ccc",
"number": 3,
"label": 1,
"type": 5,
"json_name": "ccc"
},
{
"name": "ddd",
"number": 4,
"label": 1,
"type": 3,
"json_name": "ddd"
},
{
"name": "eee",
"number": 5,
"label": 3,
"type": 9,
"json_name": "eee"
}
]
},
{
"name": "Dummy2",
"field": [
{
"name": "fff",
"number": 1,
"label": 1,
"type": 2,
"json_name": "fff"
},
{
"name": "ggg",
"number": 2,
"label": 1,
"type": 11,
"type_name": ".dummy.Dummy1",
"json_name": "ggg"
}
]
},
{
"name": "Dummy3"
}
],
"service": [
{
"name": "DummyService",
"method": [
{
"name": "Hhh",
"input_type": ".dummy.Dummy1",
"output_type": ".dummy.Dummy2",
"options": {}
},
{
"name": "Iii",
"input_type": ".dummy.Dummy2",
"output_type": ".dummy.Dummy1",
"options": {}
}
]
}
],
"source_code_info": {
"location": [
{
"span": [
0,
0,
22,
1
]
},
{
"path": [
12
],
"span": [
0,
0,
18
]
},
{
"path": [
2
],
"span": [
2,
8,
13
]
},
{
"path": [
4,
0
],
"span": [
4,
0,
10,
1
]
},
{
"path": [
4,
0,
1
],
"span": [
4,
8,
14
]
},
{
"path": [
4,
0,
2,
0
],
"span": [
5,
2,
16
]
},
{
"path": [
4,
0,
2,
0,
4
],
"span": [
5,
2,
4,
16
]
},
{
"path": [
4,
0,
2,
0,
5
],
"span": [
5,
2,
7
]
},
{
"path": [
4,
0,
2,
0,
1
],
"span": [
5,
8,
11
]
},
{
"path": [
4,
0,
2,
0,
3
],
"span": [
5,
14,
15
]
},
{
"path": [
4,
0,
2,
1
],
"span": [
6,
2,
17
]
},
{
"path": [
4,
0,
2,
1,
4
],
"span": [
6,
2,
5,
16
]
},
{
"path": [
4,
0,
2,
1,
5
],
"span": [
6,
2,
8
]
},
{
"path": [
4,
0,
2,
1,
1
],
"span": [
6,
9,
12
]
},
{
"path": [
4,
0,
2,
1,
3
],
"span": [
6,
15,
16
]
},
{
"path": [
4,
0,
2,
2
],
"span": [
7,
2,
16
]
},
{
"path": [
4,
0,
2,
2,
4
],
"span": [
7,
2,
6,
17
]
},
{
"path": [
4,
0,
2,
2,
5
],
"span": [
7,
2,
7
]
},
{
"path": [
4,
0,
2,
2,
1
],
"span": [
7,
8,
11
]
},
{
"path": [
4,
0,
2,
2,
3
],
"span": [
7,
14,
15
]
},
{
"path": [
4,
0,
2,
3
],
"span": [
8,
2,
16
]
},
{
"path": [
4,
0,
2,
3,
4
],
"span": [
8,
2,
7,
16
]
},
{
"path": [
4,
0,
2,
3,
5
],
"span": [
8,
2,
7
]
},
{
"path": [
4,
0,
2,
3,
1
],
"span": [
8,
8,
11
]
},
{
"path": [
4,
0,
2,
3,
3
],
"span": [
8,
14,
15
]
},
{
"path": [
4,
0,
2,
4
],
"span": [
9,
2,
26
]
},
{
"path": [
4,
0,
2,
4,
4
],
"span": [
9,
2,
10
]
},
{
"path": [
4,
0,
2,
4,
5
],
"span": [
9,
11,
17
]
},
{
"path": [
4,
0,
2,
4,
1
],
"span": [
9,
18,
21
]
},
{
"path": [
4,
0,
2,
4,
3
],
"span": [
9,
24,
25
]
},
{
"path": [
4,
1
],
"span": [
12,
0,
15,
1
]
},
{
"path": [
4,
1,
1
],
"span": [
12,
8,
14
]
},
{
"path": [
4,
1,
2,
0
],
"span": [
13,
2,
16
]
},
{
"path": [
4,
1,
2,
0,
4
],
"span": [
13,
2,
12,
16
]
},
{
"path": [
4,
1,
2,
0,
5
],
"span": [
13,
2,
7
]
},
{
"path": [
4,
1,
2,
0,
1
],
"span": [
13,
8,
11
]
},
{
"path": [
4,
1,
2,
0,
3
],
"span": [
13,
14,
15
]
},
{
"path": [
4,
1,
2,
1
],
"span": [
14,
2,
17
]
},
{
"path": [
4,
1,
2,
1,
4
],
"span": [
14,
2,
13,
16
]
},
{
"path": [
4,
1,
2,
1,
6
],
"span": [
14,
2,
8
]
},
{
"path": [
4,
1,
2,
1,
1
],
"span": [
14,
9,
12
]
},
{
"path": [
4,
1,
2,
1,
3
],
"span": [
14,
15,
16
]
},
{
"path": [
4,
2
],
"span": [
17,
0,
17
]
},
{
"path": [
4,
2,
1
],
"span": [
17,
8,
14
]
},
{
"path": [
6,
0
],
"span": [
19,
0,
22,
1
]
},
{
"path": [
6,
0,
1
],
"span": [
19,
8,
20
]
},
{
"path": [
6,
0,
2,
0
],
"span": [
20,
2,
37
]
},
{
"path": [
6,
0,
2,
0,
1
],
"span": [
20,
6,
9
]
},
{
"path": [
6,
0,
2,
0,
2
],
"span": [
20,
10,
16
]
},
{
"path": [
6,
0,
2,
0,
3
],
"span": [
20,
27,
33
]
},
{
"path": [
6,
0,
2,
1
],
"span": [
21,
2,
37
]
},
{
"path": [
6,
0,
2,
1,
1
],
"span": [
21,
6,
9
]
},
{
"path": [
6,
0,
2,
1,
2
],
"span": [
21,
10,
16
]
},
{
"path": [
6,
0,
2,
1,
3
],
"span": [
21,
27,
33
]
}
]
},
"syntax": "proto3"
},
"filename": "export.json.tmpl",
"service": {
"name": "DummyService",
"method": [
{
"name": "Hhh",
"input_type": ".dummy.Dummy1",
"output_type": ".dummy.Dummy2",
"options": {}
},
{
"name": "Iii",
"input_type": ".dummy.Dummy2",
"output_type": ".dummy.Dummy1",
"options": {}
}
]
}
}

View File

@ -1 +1 @@
{{ . | json }} {{ . | prettyjson }}