Merge pull request #95 from Tommy-42/master
Add arithmetics helpers - fix #94
This commit is contained in:
commit
283713bd93
1
Makefile
1
Makefile
@ -20,6 +20,7 @@ test: install
|
|||||||
cd examples/go-generate && make
|
cd examples/go-generate && make
|
||||||
cd examples/single-package-mode && make
|
cd examples/single-package-mode && make
|
||||||
cd examples/helpers && make
|
cd examples/helpers && make
|
||||||
|
cd examples/arithmetics && make
|
||||||
# cd examples/go-kit && make
|
# cd examples/go-kit && make
|
||||||
|
|
||||||
.PHONY: docker.build
|
.PHONY: docker.build
|
||||||
|
29
README.md
29
README.md
@ -73,34 +73,59 @@ See [examples](./examples).
|
|||||||
|
|
||||||
This project uses [Masterminds/sprig](https://github.com/Masterminds/sprig) library and additional functions to extend the builtin [text/template](https://golang.org/pkg/text/template) helpers.
|
This project uses [Masterminds/sprig](https://github.com/Masterminds/sprig) library and additional functions to extend the builtin [text/template](https://golang.org/pkg/text/template) helpers.
|
||||||
|
|
||||||
Non-exhaustive list of new helpers:s
|
Non-exhaustive list of new helpers:
|
||||||
|
|
||||||
* **all the functions from [sprig](https://github.com/Masterminds/sprig)**
|
* **all the functions from [sprig](https://github.com/Masterminds/sprig)**
|
||||||
|
* `string`
|
||||||
* `json`
|
* `json`
|
||||||
* `prettyjson`
|
* `prettyjson`
|
||||||
|
* `splitArray`
|
||||||
* `first`
|
* `first`
|
||||||
* `last`
|
* `last`
|
||||||
* `splitArray`
|
|
||||||
* `upperFirst`
|
* `upperFirst`
|
||||||
* `lowerFirst`
|
* `lowerFirst`
|
||||||
* `camelCase`
|
* `camelCase`
|
||||||
* `lowerCamelCase`
|
* `lowerCamelCase`
|
||||||
* `kebabCase`
|
* `kebabCase`
|
||||||
|
* `contains`
|
||||||
|
* `trimstr`
|
||||||
|
* `index`
|
||||||
* `snakeCase`
|
* `snakeCase`
|
||||||
* `getProtoFile`
|
* `getProtoFile`
|
||||||
* `getMessageType`
|
* `getMessageType`
|
||||||
* `getEnumValue`
|
* `getEnumValue`
|
||||||
* `isFieldMessage`
|
* `isFieldMessage`
|
||||||
|
* `isFieldMessageTimeStamp`
|
||||||
* `isFieldRepeated`
|
* `isFieldRepeated`
|
||||||
|
* `haskellType`
|
||||||
* `goType`
|
* `goType`
|
||||||
|
* `goZeroValue`
|
||||||
* `goTypeWithPackage`
|
* `goTypeWithPackage`
|
||||||
* `jsType`
|
* `jsType`
|
||||||
* `jsSuffixReserved`
|
* `jsSuffixReserved`
|
||||||
* `namespacedFlowType`
|
* `namespacedFlowType`
|
||||||
* `httpVerb`
|
* `httpVerb`
|
||||||
* `httpPath`
|
* `httpPath`
|
||||||
|
* `httpPathsAdditionalBindings`
|
||||||
|
* `httpBody`
|
||||||
* `shortType`
|
* `shortType`
|
||||||
* `urlHasVarsFromMessage`
|
* `urlHasVarsFromMessage`
|
||||||
|
* `lowerGoNormalize`
|
||||||
|
* `goNormalize`
|
||||||
|
* `leadingComment`
|
||||||
|
* `trailingComment`
|
||||||
|
* `leadingDetachedComments`
|
||||||
|
* `stringFieldExtension`
|
||||||
|
* `stringMethodOptionsExtension`
|
||||||
|
* `boolFieldExtension`
|
||||||
|
* `isFieldMap`
|
||||||
|
* `fieldMapKeyType`
|
||||||
|
* `fieldMapValueType`
|
||||||
|
* `replaceDict`
|
||||||
|
* `add`
|
||||||
|
* `subtract`
|
||||||
|
* `multiply`
|
||||||
|
* `divide`
|
||||||
|
|
||||||
See the project helpers for the complete list.
|
See the project helpers for the complete list.
|
||||||
|
|
||||||
|
13
examples/arithmetics/Makefile
Normal file
13
examples/arithmetics/Makefile
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
.PHONY: build
|
||||||
|
build:
|
||||||
|
mkdir -p output
|
||||||
|
protoc -I. --gotemplate_out=template_dir=templates,debug=true,all=true:output proto/*.proto
|
||||||
|
|
||||||
|
|
||||||
|
.PHONY: re
|
||||||
|
re: clean build
|
||||||
|
|
||||||
|
|
||||||
|
.PHONY: clean
|
||||||
|
clean:
|
||||||
|
rm -rf output
|
5
examples/arithmetics/output/arithmetics
Normal file
5
examples/arithmetics/output/arithmetics
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
|
||||||
|
add(1,2) = 3
|
||||||
|
subtract(1,2) = -1
|
||||||
|
multiply(1,2) = 2
|
||||||
|
divide(2,1) = 2
|
2
examples/arithmetics/proto/arithmetics.proto
Normal file
2
examples/arithmetics/proto/arithmetics.proto
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
syntax = "proto3";
|
||||||
|
package Arithmetics;
|
6
examples/arithmetics/templates/arithmetics.tmpl
Normal file
6
examples/arithmetics/templates/arithmetics.tmpl
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
{{with $a := 1}}{{with $b := 2}}
|
||||||
|
add(1,2) = {{add $a $b}}
|
||||||
|
subtract(1,2) = {{subtract $a $b}}
|
||||||
|
multiply(1,2) = {{multiply $a $b}}
|
||||||
|
divide(2,1) = {{divide $b $a}}
|
||||||
|
{{end}}{{end}}
|
@ -133,6 +133,21 @@ var ProtoHelpersFuncMap = template.FuncMap{
|
|||||||
"fieldMapKeyType": fieldMapKeyType,
|
"fieldMapKeyType": fieldMapKeyType,
|
||||||
"fieldMapValueType": fieldMapValueType,
|
"fieldMapValueType": fieldMapValueType,
|
||||||
"replaceDict": replaceDict,
|
"replaceDict": replaceDict,
|
||||||
|
"add": func(a int, b int) int {
|
||||||
|
return a + b
|
||||||
|
},
|
||||||
|
"subtract": func(a int, b int) int {
|
||||||
|
return a - b
|
||||||
|
},
|
||||||
|
"multiply": func(a int, b int) int {
|
||||||
|
return a * b
|
||||||
|
},
|
||||||
|
"divide": func(a int, b int) int {
|
||||||
|
if b == 0 {
|
||||||
|
panic("psssst ... little help here ... you cannot divide by 0")
|
||||||
|
}
|
||||||
|
return a / b
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
var pathMap map[interface{}]*descriptor.SourceCodeInfo_Location
|
var pathMap map[interface{}]*descriptor.SourceCodeInfo_Location
|
||||||
|
Loading…
Reference in New Issue
Block a user