Skip to content

Commit

Permalink
http tempalte fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
mchmarny committed Nov 5, 2020
1 parent 1999115 commit e370ae3
Show file tree
Hide file tree
Showing 10 changed files with 40 additions and 32 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ my-app
my-http-app
my-grpc-app
my-cli-app
apps

# Output of the go coverage tool, specifically when used with LiteIDE
*.out
Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
APP_NAME =daprme
RELEASE_VERSION =v0.6.2
RELEASE_VERSION =v0.6.3
LINTER_VERSION =v1.31.0
DOCKER_USERNAME ?=$(DOCKER_USER)

Expand Down Expand Up @@ -35,7 +35,7 @@ run: clean tidy res ## Runs uncompiled code
.PHONY: run

demo: clean tidy res ## Runs uncompiled code with manifest
go run main.go --file test-data/demo.yaml --out ./my-app
go run main.go --file test-data/demo.yaml --out ./apps
.PHONY: demo

build: clean tidy res ## Builds binaries
Expand Down
8 changes: 4 additions & 4 deletions pkg/lang/resource.go

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion pkg/prompt/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ import (
// ForService collects service info
func ForService() *model.Service {
s := &model.Service{}
s.Name = ForString("Service name: ", "myService")
s.Name = ForString("Operation name: ", "myMethod")
return s
}
1 change: 0 additions & 1 deletion template/component/configuration.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ apiVersion: dapr.io/v1alpha1
kind: Configuration
metadata:
name: {{.Meta.Name}}-config
namespace: default
spec:
tracing:
samplingRate: "1"
4 changes: 2 additions & 2 deletions template/go/main.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
{{- if eq .Meta.Type "gRPC"}}
daprd "github.com/dapr/go-sdk/service/grpc"
{{- end}}
{{- if eq .Meta.Type "GHTTP"}}
{{- if eq .Meta.Type "HTTP"}}
daprd "github.com/dapr/go-sdk/service/http"
{{- end}}
{{- if .Meta.UsesClient}}
Expand Down Expand Up @@ -67,7 +67,7 @@ func main() {
PubsubName: pubSubName{{$i}},
Topic: topicName{{$i}},
{{- if eq $.Meta.Type "HTTP"}}
Route: fmt.Sprintf("/%s", topicName),
Route: fmt.Sprintf("/%s", topicName{{$i}}),
{{- end}}
}
if err := s.AddTopicEventHandler(sub{{$i}}, eventHandler); err != nil {
Expand Down
38 changes: 23 additions & 15 deletions template/go/make.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -17,33 +17,41 @@ test: tidy ## Tests the entire project
.PHONY: run
run: tidy ## Runs un-compiled code in Dapr
dapr run \
--app-id $(SERVICE_NAME) \
--app-port {{.Meta.Port}} \
{{- if eq .Meta.Type "HTTP"}}
--app-protocol http \
{{- else if eq .Meta.Type "GRPC"}}
--app-protocol grpc \
{{- end}}
--dapr-http-port 3500 \
--components-path ./config \
go run main.go
--app-id $(SERVICE_NAME) \
--app-port {{.Meta.Port}} \
{{- if eq .Meta.Type "HTTP"}}
--app-protocol http \
{{- else if eq .Meta.Type "GRPC"}}
--app-protocol grpc \
{{- end}}
--dapr-http-port 3500 \
--components-path ./config \
go run main.go

.PHONY: build
build: tidy ## Builds local release binary
CGO_ENABLED=0 go build -a -tags netgo -mod vendor -o bin/$(SERVICE_NAME) .

{{range $i, $v := .PubSubs}}
.PHONY: event{{$v.Name}}
event{{$v.Name}}: ## Publishes sample JSON message to Dapr pubsub API
curl -d '{ "from": "John", "to": "Lary", "message": "hi" }' \
.PHONY: event-{{$v.Name}}
event-{{$v.Name}}: ## Publishes sample JSON message to Dapr pubsub API
curl -i -d '{ "from": "John", "to": "Lary", "message": "hi" }' \
-H "Content-type: application/json" \
"http://localhost:3500/v1.0/publish/{{$v.Name}}/{{$v.Topic}}"
{{end}}

{{range $i, $v := .Services}}
.PHONY: invoke-{{$v.Name}}
invoke-{{$v.Name}}: ## Invoke app method via Dapr API
curl -i -d '{ "message": "ping" }' \
-H "Content-type: application/json" \
"http://localhost:3500/v1.0/invoke/$(SERVICE_NAME)/method/{{$v.Name}}"
{{end}}

.PHONY: image
image: tidy ## Builds and publish docker image
docker build -t "$(OWNER_NAME)/$(SERVICE_NAME):$(RELEASE_VERSION)" .
docker push "$(OWNER_NAME)/$(SERVICE_NAME):$(RELEASE_VERSION)"
docker build -t "ghcr.io/$(OWNER_NAME)/$(SERVICE_NAME):$(RELEASE_VERSION)" .
docker push "ghcr.io/$(OWNER_NAME)/$(SERVICE_NAME):$(RELEASE_VERSION)"

.PHONY: lint
lint: ## Lints the entire project
Expand Down
8 changes: 4 additions & 4 deletions test-data/demo.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
Meta:
Name: daprme-demo-app
Type: gRPC
Name: demo-app
Type: HTTP
Lang: go
Main: main.go
Port: 50505
Port: 8080
UsesClient: true
Owner: mchmarny
PubSubs:
Expand All @@ -14,7 +14,7 @@ Bindings:
- Name: cron-binding
Type: bindings.cron
Services:
- Name: myService
- Name: myMethod
Components:
- Name: localenv-secret
Type: secretstores.local.env
Expand Down
4 changes: 2 additions & 2 deletions test-data/grpc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ Bindings:
- Type: bindings.kafka
Name: kafka-binding
Services:
- Name: myService
- Name: myOtherService
- Name: myMethod
- Name: myOtherMethod
Components:
- Type: secretstores.local.env
Name: localenv-secret
Expand Down
2 changes: 1 addition & 1 deletion test-data/http.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ Bindings:
- Type: bindings.cron
Name: cron-binding
Services:
- Name: myService
- Name: myMethod

0 comments on commit e370ae3

Please sign in to comment.