Compare commits
18 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
d6e112de34 | ||
|
f3d1bfdee9 | ||
|
066f210f39 | ||
|
b244c9cc31 | ||
|
3a6b47dc92 | ||
|
5b5d8bf81e | ||
|
42f1289ddc | ||
|
2d28c0f341 | ||
|
e4d1fef8fe | ||
|
1d71729a7c | ||
|
c6eca2356c | ||
|
3576fd314a | ||
|
f43d2a2ac8 | ||
|
baffaa4b6a | ||
|
db5e9b7f99 | ||
|
be3a88a34a | ||
|
bd48cf6168 | ||
|
6949b76e12 |
1
.github/CODEOWNERS
vendored
Normal file
1
.github/CODEOWNERS
vendored
Normal file
@@ -0,0 +1 @@
|
||||
* @moul
|
6
.github/FUNDING.yml
vendored
Normal file
6
.github/FUNDING.yml
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
#github: ["moul"]
|
||||
patreon: moul
|
||||
open_collective: moul
|
||||
custom:
|
||||
- "https://www.buymeacoffee.com/moul"
|
||||
- "https://manfred.life/donate"
|
31
.github/ISSUE_TEMPLATE/bug_report.md
vendored
Normal file
31
.github/ISSUE_TEMPLATE/bug_report.md
vendored
Normal file
@@ -0,0 +1,31 @@
|
||||
---
|
||||
name: Bug report
|
||||
about: Create a report to help us improve
|
||||
title: "[BUG] "
|
||||
labels: bug
|
||||
assignees: ''
|
||||
|
||||
---
|
||||
|
||||
**Describe the bug**
|
||||
A clear and concise description of what the bug is.
|
||||
|
||||
**To Reproduce**
|
||||
Steps to reproduce the behavior:
|
||||
1. Go to '...'
|
||||
2. Type '....'
|
||||
3. See error
|
||||
|
||||
**Expected behavior**
|
||||
A clear and concise description of what you expected to happen.
|
||||
|
||||
**Screenshots / Logs**
|
||||
If applicable, add screenshots or logs to help explain your problem.
|
||||
|
||||
**Versions (please complete the following information, if relevant):**
|
||||
- Software version: [e.g. v1.2.3, latest, building from sources]
|
||||
- OS: [e.g. Ubuntu, Mac, iOS, ...]
|
||||
- Golang version [e.g. 1.13]
|
||||
|
||||
**Additional context**
|
||||
Add any other context about the problem here.
|
8
.github/ISSUE_TEMPLATE/custom.md
vendored
Normal file
8
.github/ISSUE_TEMPLATE/custom.md
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
---
|
||||
name: Custom
|
||||
about: 'Anything else: questions, discussions, thanks, ascii-arts, ...'
|
||||
title: ''
|
||||
labels: discussion
|
||||
assignees: moul
|
||||
|
||||
---
|
20
.github/ISSUE_TEMPLATE/feature_request.md
vendored
Normal file
20
.github/ISSUE_TEMPLATE/feature_request.md
vendored
Normal file
@@ -0,0 +1,20 @@
|
||||
---
|
||||
name: Feature request
|
||||
about: Suggest an idea for this project
|
||||
title: "[IDEA] "
|
||||
labels: enhancement
|
||||
assignees: ''
|
||||
|
||||
---
|
||||
|
||||
**Is your feature request related to a problem? Please describe.**
|
||||
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
|
||||
|
||||
**Describe the solution you'd like**
|
||||
A clear and concise description of what you want to happen.
|
||||
|
||||
**Describe alternatives you've considered**
|
||||
A clear and concise description of any alternative solutions or features you've considered.
|
||||
|
||||
**Additional context**
|
||||
Add any other context or screenshots about the feature request here.
|
9
.github/PULL_REQUEST_TEMPLATE.md
vendored
Normal file
9
.github/PULL_REQUEST_TEMPLATE.md
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
<!--
|
||||
Thank you for your contribution to this repo!
|
||||
|
||||
Before submitting a pull request, please check the following:
|
||||
- reference any related issue, PR, link
|
||||
- use the "WIP" title prefix if you need help or more time to finish your PR
|
||||
|
||||
you can remove this markdown comment
|
||||
-->
|
6
.github/renovate.json
vendored
Normal file
6
.github/renovate.json
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"extends": [
|
||||
"config:base"
|
||||
],
|
||||
"groupName": "all"
|
||||
}
|
13
.github/workflows/release.yml
vendored
Normal file
13
.github/workflows/release.yml
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
name: Semantic Release
|
||||
|
||||
on: push
|
||||
|
||||
jobs:
|
||||
semantic-release:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@master
|
||||
- uses: codfish/semantic-release-action@v1
|
||||
if: github.ref == 'refs/heads/master'
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
8
.releaserc.js
Normal file
8
.releaserc.js
Normal file
@@ -0,0 +1,8 @@
|
||||
module.exports = {
|
||||
branch: 'master',
|
||||
plugins: [
|
||||
'@semantic-release/commit-analyzer',
|
||||
'@semantic-release/release-notes-generator',
|
||||
'@semantic-release/github',
|
||||
],
|
||||
};
|
@@ -153,6 +153,10 @@ $> docker run --rm -v "$(pwd):$(pwd)" -w "$(pwd)" moul/protoc-gen-gotemplate -I.
|
||||
* [translator](https://github.com/moul/translator): Translator Micro-service using Gettext and Go-Kit
|
||||
* [acl](https://github.com/moul/acl): ACL micro-service (gRPC/protobuf + http/json)
|
||||
|
||||
## See also
|
||||
|
||||
* [pbhbs](https://github.com/gponsinet/pbhbs): protobuf gen based on handlebarjs template
|
||||
|
||||
## License
|
||||
|
||||
MIT
|
||||
|
@@ -210,10 +210,8 @@ func (e *GenericTemplateBasedEncoder) Files() []*plugin_go.CodeGeneratorResponse
|
||||
case f := <-resultChan:
|
||||
files = append(files, f)
|
||||
case err = <-errChan:
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return files
|
||||
}
|
||||
|
@@ -94,15 +94,15 @@ var ProtoHelpersFuncMap = template.FuncMap{
|
||||
"trimstr": func(cutset, s string) string {
|
||||
return strings.Trim(s, cutset)
|
||||
},
|
||||
"index": func(array interface{}, i int32) interface{} {
|
||||
"index": func(array interface{}, i int) interface{} {
|
||||
slice := reflect.ValueOf(array)
|
||||
if slice.Kind() != reflect.Slice {
|
||||
panic("Error in index(): given a non-slice type")
|
||||
}
|
||||
if i < 0 || int(i) >= slice.Len() {
|
||||
if i < 0 || i >= slice.Len() {
|
||||
panic("Error in index(): index out of bounds")
|
||||
}
|
||||
return slice.Index(int(i)).Interface()
|
||||
return slice.Index(i).Interface()
|
||||
},
|
||||
"add": func(a int, b int) int {
|
||||
return a + b
|
||||
@@ -146,10 +146,14 @@ var ProtoHelpersFuncMap = template.FuncMap{
|
||||
"leadingComment": leadingComment,
|
||||
"trailingComment": trailingComment,
|
||||
"leadingDetachedComments": leadingDetachedComments,
|
||||
"stringFileOptionsExtension": stringFileOptionsExtension,
|
||||
"stringMessageExtension": stringMessageExtension,
|
||||
"stringFieldExtension": stringFieldExtension,
|
||||
"int64FieldExtension": int64FieldExtension,
|
||||
"int64MessageExtension": int64MessageExtension,
|
||||
"stringMethodOptionsExtension": stringMethodOptionsExtension,
|
||||
"boolMethodOptionsExtension": boolMethodOptionsExtension,
|
||||
"boolMessageExtension": boolMessageExtension,
|
||||
"boolFieldExtension": boolFieldExtension,
|
||||
"isFieldMap": isFieldMap,
|
||||
"fieldMapKeyType": fieldMapKeyType,
|
||||
@@ -157,6 +161,8 @@ var ProtoHelpersFuncMap = template.FuncMap{
|
||||
"replaceDict": replaceDict,
|
||||
"setStore": setStore,
|
||||
"getStore": getStore,
|
||||
"goPkg": goPkg,
|
||||
"goPkgLastElement": goPkgLastElement,
|
||||
}
|
||||
|
||||
var pathMap map[interface{}]*descriptor.SourceCodeInfo_Location
|
||||
@@ -343,6 +349,46 @@ func stringMethodOptionsExtension(fieldID int32, f *descriptor.MethodDescriptorP
|
||||
return *str
|
||||
}
|
||||
|
||||
// stringFileOptionsExtension extracts file options of a string type.
|
||||
// To define your own extensions see:
|
||||
// https://developers.google.com/protocol-buffers/docs/proto#customoptions
|
||||
// Typically the fieldID of private extensions should be in the range:
|
||||
// 50000-99999
|
||||
func stringFileOptionsExtension(fieldID int32, f *descriptor.FileDescriptorProto) string {
|
||||
if f == nil {
|
||||
return ""
|
||||
}
|
||||
if f.Options == nil {
|
||||
return ""
|
||||
}
|
||||
var extendedType *descriptor.FileOptions
|
||||
var extensionType *string
|
||||
|
||||
eds := proto.RegisteredExtensions(f.Options)
|
||||
if eds[fieldID] == nil {
|
||||
ed := &proto.ExtensionDesc{
|
||||
ExtendedType: extendedType,
|
||||
ExtensionType: extensionType,
|
||||
Field: fieldID,
|
||||
Tag: fmt.Sprintf("bytes,%d", fieldID),
|
||||
}
|
||||
proto.RegisterExtension(ed)
|
||||
eds = proto.RegisteredExtensions(f.Options)
|
||||
}
|
||||
|
||||
ext, err := proto.GetExtension(f.Options, eds[fieldID])
|
||||
if err != nil {
|
||||
return ""
|
||||
}
|
||||
|
||||
str, ok := ext.(*string)
|
||||
if !ok {
|
||||
return ""
|
||||
}
|
||||
|
||||
return *str
|
||||
}
|
||||
|
||||
func stringFieldExtension(fieldID int32, f *descriptor.FieldDescriptorProto) string {
|
||||
if f == nil {
|
||||
return ""
|
||||
@@ -386,7 +432,7 @@ func int64FieldExtension(fieldID int32, f *descriptor.FieldDescriptorProto) int6
|
||||
return 0
|
||||
}
|
||||
var extendedType *descriptor.FieldOptions
|
||||
var extensionType *string
|
||||
var extensionType *int64
|
||||
|
||||
eds := proto.RegisteredExtensions(f.Options)
|
||||
if eds[fieldID] == nil {
|
||||
@@ -394,7 +440,7 @@ func int64FieldExtension(fieldID int32, f *descriptor.FieldDescriptorProto) int6
|
||||
ExtendedType: extendedType,
|
||||
ExtensionType: extensionType,
|
||||
Field: fieldID,
|
||||
Tag: fmt.Sprintf("bytes,%d", fieldID),
|
||||
Tag: fmt.Sprintf("varint,%d", fieldID),
|
||||
}
|
||||
proto.RegisterExtension(ed)
|
||||
eds = proto.RegisteredExtensions(f.Options)
|
||||
@@ -413,6 +459,76 @@ func int64FieldExtension(fieldID int32, f *descriptor.FieldDescriptorProto) int6
|
||||
return *i
|
||||
}
|
||||
|
||||
func int64MessageExtension(fieldID int32, f *descriptor.DescriptorProto) int64 {
|
||||
if f == nil {
|
||||
return 0
|
||||
}
|
||||
if f.Options == nil {
|
||||
return 0
|
||||
}
|
||||
var extendedType *descriptor.MessageOptions
|
||||
var extensionType *int64
|
||||
|
||||
eds := proto.RegisteredExtensions(f.Options)
|
||||
if eds[fieldID] == nil {
|
||||
ed := &proto.ExtensionDesc{
|
||||
ExtendedType: extendedType,
|
||||
ExtensionType: extensionType,
|
||||
Field: fieldID,
|
||||
Tag: fmt.Sprintf("varint,%d", fieldID),
|
||||
}
|
||||
proto.RegisterExtension(ed)
|
||||
eds = proto.RegisteredExtensions(f.Options)
|
||||
}
|
||||
|
||||
ext, err := proto.GetExtension(f.Options, eds[fieldID])
|
||||
if err != nil {
|
||||
return 0
|
||||
}
|
||||
|
||||
i, ok := ext.(*int64)
|
||||
if !ok {
|
||||
return 0
|
||||
}
|
||||
|
||||
return *i
|
||||
}
|
||||
|
||||
func stringMessageExtension(fieldID int32, f *descriptor.DescriptorProto) string {
|
||||
if f == nil {
|
||||
return ""
|
||||
}
|
||||
if f.Options == nil {
|
||||
return ""
|
||||
}
|
||||
var extendedType *descriptor.MessageOptions
|
||||
var extensionType *string
|
||||
|
||||
eds := proto.RegisteredExtensions(f.Options)
|
||||
if eds[fieldID] == nil {
|
||||
ed := &proto.ExtensionDesc{
|
||||
ExtendedType: extendedType,
|
||||
ExtensionType: extensionType,
|
||||
Field: fieldID,
|
||||
Tag: fmt.Sprintf("bytes,%d", fieldID),
|
||||
}
|
||||
proto.RegisterExtension(ed)
|
||||
eds = proto.RegisteredExtensions(f.Options)
|
||||
}
|
||||
|
||||
ext, err := proto.GetExtension(f.Options, eds[fieldID])
|
||||
if err != nil {
|
||||
return ""
|
||||
}
|
||||
|
||||
str, ok := ext.(*string)
|
||||
if !ok {
|
||||
return ""
|
||||
}
|
||||
|
||||
return *str
|
||||
}
|
||||
|
||||
func boolMethodOptionsExtension(fieldID int32, f *descriptor.MethodDescriptorProto) bool {
|
||||
if f == nil {
|
||||
return false
|
||||
@@ -483,6 +599,41 @@ func boolFieldExtension(fieldID int32, f *descriptor.FieldDescriptorProto) bool
|
||||
return *b
|
||||
}
|
||||
|
||||
func boolMessageExtension(fieldID int32, f *descriptor.DescriptorProto) bool {
|
||||
if f == nil {
|
||||
return false
|
||||
}
|
||||
if f.Options == nil {
|
||||
return false
|
||||
}
|
||||
var extendedType *descriptor.MessageOptions
|
||||
var extensionType *bool
|
||||
|
||||
eds := proto.RegisteredExtensions(f.Options)
|
||||
if eds[fieldID] == nil {
|
||||
ed := &proto.ExtensionDesc{
|
||||
ExtendedType: extendedType,
|
||||
ExtensionType: extensionType,
|
||||
Field: fieldID,
|
||||
Tag: fmt.Sprintf("varint,%d", fieldID),
|
||||
}
|
||||
proto.RegisterExtension(ed)
|
||||
eds = proto.RegisteredExtensions(f.Options)
|
||||
}
|
||||
|
||||
ext, err := proto.GetExtension(f.Options, eds[fieldID])
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
|
||||
b, ok := ext.(*bool)
|
||||
if !ok {
|
||||
return false
|
||||
}
|
||||
|
||||
return *b
|
||||
}
|
||||
|
||||
func init() {
|
||||
for k, v := range sprig.TxtFuncMap() {
|
||||
ProtoHelpersFuncMap[k] = v
|
||||
@@ -1164,3 +1315,13 @@ func replaceDict(src string, dict map[string]interface{}) string {
|
||||
}
|
||||
return src
|
||||
}
|
||||
|
||||
func goPkg(f *descriptor.FileDescriptorProto) string {
|
||||
return f.Options.GetGoPackage()
|
||||
}
|
||||
|
||||
func goPkgLastElement(f *descriptor.FileDescriptorProto) string {
|
||||
pkg := goPkg(f)
|
||||
pkgSplitted := strings.Split(pkg, "/")
|
||||
return pkgSplitted[len(pkgSplitted)-1]
|
||||
}
|
||||
|
20
main.go
20
main.go
@@ -48,6 +48,7 @@ func main() {
|
||||
debug = false
|
||||
all = false
|
||||
singlePackageMode = false
|
||||
fileMode = false
|
||||
)
|
||||
if parameter := g.Request.GetParameter(); parameter != "" {
|
||||
for _, param := range strings.Split(parameter, ",") {
|
||||
@@ -85,6 +86,14 @@ func main() {
|
||||
default:
|
||||
log.Printf("Err: invalid value for debug: %q", parts[1])
|
||||
}
|
||||
case "file-mode":
|
||||
switch strings.ToLower(parts[1]) {
|
||||
case boolTrue, "t":
|
||||
fileMode = true
|
||||
case boolFalse, "f":
|
||||
default:
|
||||
log.Printf("Err: invalid value for file-mode: %q", parts[1])
|
||||
}
|
||||
default:
|
||||
log.Printf("Err: unknown parameter: %q", param)
|
||||
}
|
||||
@@ -125,6 +134,17 @@ func main() {
|
||||
continue
|
||||
}
|
||||
|
||||
if fileMode {
|
||||
if s := file.GetService(); s != nil && len(s) > 0 {
|
||||
encoder := NewGenericTemplateBasedEncoder(templateDir, file, debug, destinationDir)
|
||||
for _, tmpl := range encoder.Files() {
|
||||
concatOrAppend(tmpl)
|
||||
}
|
||||
}
|
||||
|
||||
continue
|
||||
}
|
||||
|
||||
for _, service := range file.GetService() {
|
||||
encoder := NewGenericServiceTemplateBasedEncoder(templateDir, service, file, debug, destinationDir)
|
||||
for _, tmpl := range encoder.Files() {
|
||||
|
Reference in New Issue
Block a user