Skip to content

Commit 766cbd8

Browse files
authored
Merge pull request #66 from unistack-org/wrappers
add additional wrappers support
2 parents f42994e + 847352a commit 766cbd8

File tree

5 files changed

+86
-29
lines changed

5 files changed

+86
-29
lines changed

.github/workflows/autoapprove.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
name: "autoapprove"
2+
3+
on:
4+
pull_request_target:
5+
types: [assigned, opened, synchronize, reopened]
6+
7+
permissions:
8+
pull-requests: write
9+
contents: write
10+
11+
jobs:
12+
autoapprove:
13+
runs-on: ubuntu-latest
14+
steps:
15+
- name: approve
16+
uses: hmarr/auto-approve-action@v2
17+
if: github.actor == 'vtolstov' || github.actor == 'dependabot[bot]'
18+
id: approve
19+
with:
20+
github-token: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/automerge.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
name: "automerge"
2+
3+
on:
4+
pull_request_target:
5+
types: [assigned, opened, synchronize, reopened]
6+
7+
permissions:
8+
pull-requests: write
9+
contents: write
10+
11+
jobs:
12+
automerge:
13+
runs-on: ubuntu-latest
14+
if: github.actor == 'vtolstov'
15+
steps:
16+
- name: merge
17+
id: merge
18+
run: gh pr merge --auto --merge "$PR_URL"
19+
env:
20+
PR_URL: ${{github.event.pull_request.html_url}}
21+
GITHUB_TOKEN: ${{secrets.TOKEN}}

.github/workflows/dependabot-automerge.yml

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: "prautomerge"
1+
name: "dependabot-automerge"
22

33
on:
44
pull_request_target:
@@ -9,21 +9,17 @@ permissions:
99
contents: write
1010

1111
jobs:
12-
dependabot:
12+
automerge:
1313
runs-on: ubuntu-latest
14-
if: ${{ github.actor == 'dependabot[bot]' }}
14+
if: github.actor == 'dependabot[bot]'
1515
steps:
1616
- name: metadata
1717
id: metadata
1818
uses: dependabot/fetch-metadata@v1.3.0
1919
with:
2020
github-token: "${{ secrets.TOKEN }}"
21-
- name: approve
22-
run: gh pr review --approve "$PR_URL"
23-
env:
24-
PR_URL: ${{github.event.pull_request.html_url}}
25-
GITHUB_TOKEN: ${{secrets.TOKEN}}
2621
- name: merge
22+
id: merge
2723
if: ${{contains(steps.metadata.outputs.dependency-names, 'go.unistack.org')}}
2824
run: gh pr merge --auto --merge "$PR_URL"
2925
env:

http.go

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -604,6 +604,8 @@ func (h *httpClient) Publish(ctx context.Context, p client.Message, opts ...clie
604604
}
605605

606606
func (h *httpClient) publish(ctx context.Context, ps []client.Message, opts ...client.PublishOption) error {
607+
var body []byte
608+
607609
options := client.NewPublishOptions(opts...)
608610

609611
// get proxy
@@ -622,31 +624,32 @@ func (h *httpClient) publish(ctx context.Context, ps []client.Message, opts ...c
622624
for _, p := range ps {
623625
md := metadata.Copy(omd)
624626
md[metadata.HeaderContentType] = p.ContentType()
625-
md[metadata.HeaderTopic] = p.Topic()
626-
627-
cf, err := h.newCodec(p.ContentType())
628-
if err != nil {
629-
return errors.InternalServerError("go.micro.client", err.Error())
630-
}
631-
632-
var body []byte
633627

634628
// passed in raw data
635629
if d, ok := p.Payload().(*codec.Frame); ok {
636630
body = d.Data
637631
} else {
638-
b := bytes.NewBuffer(nil)
639-
if err := cf.Write(b, &codec.Message{Type: codec.Event}, p.Payload()); err != nil {
632+
// use codec for payload
633+
cf, err := h.newCodec(p.ContentType())
634+
if err != nil {
635+
return errors.InternalServerError("go.micro.client", err.Error())
636+
}
637+
// set the body
638+
b, err := cf.Marshal(p.Payload())
639+
if err != nil {
640640
return errors.InternalServerError("go.micro.client", err.Error())
641641
}
642-
body = b.Bytes()
642+
body = b
643643
}
644644

645645
topic := p.Topic()
646646
if len(exchange) > 0 {
647647
topic = exchange
648648
}
649649

650+
for k, v := range p.Metadata() {
651+
md.Set(k, v)
652+
}
650653
md.Set(metadata.HeaderTopic, topic)
651654
msgs = append(msgs, &broker.Message{Header: md, Body: body})
652655
}

util.go

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -147,11 +147,11 @@ func newPathRequest(path string, method string, body string, msg interface{}, ta
147147
switch val.Type().Kind() {
148148
case reflect.Slice:
149149
for idx := 0; idx < val.Len(); idx++ {
150-
values.Add(t.name, fmt.Sprintf("%v", val.Index(idx).Interface()))
150+
values.Add(t.name, getParam(val.Index(idx)))
151151
}
152152
fieldsmapskip[t.name] = struct{}{}
153153
default:
154-
fieldsmap[t.name] = fmt.Sprintf("%v", val.Interface())
154+
fieldsmap[t.name] = getParam(val)
155155
}
156156
} else if (body == "*" || body == t.name) && method != http.MethodGet {
157157
if tnmsg.Field(i).CanSet() {
@@ -160,10 +160,10 @@ func newPathRequest(path string, method string, body string, msg interface{}, ta
160160
} else {
161161
if val.Type().Kind() == reflect.Slice {
162162
for idx := 0; idx < val.Len(); idx++ {
163-
values.Add(t.name, fmt.Sprintf("%v", val.Index(idx).Interface()))
163+
values.Add(t.name, getParam(val.Index(idx)))
164164
}
165165
} else {
166-
values.Add(t.name, fmt.Sprintf("%v", val.Interface()))
166+
values.Add(t.name, getParam(val))
167167
}
168168
}
169169
}
@@ -216,12 +216,6 @@ func newPathRequest(path string, method string, body string, msg interface{}, ta
216216
_, _ = b.WriteString(values.Encode())
217217
}
218218

219-
/*
220-
if err = rutil.ZeroFieldByPath(nmsg, k); err != nil {
221-
return nil, errors.BadRequest("go.micro.client", err.Error())
222-
}
223-
*/
224-
225219
if rutil.IsZero(nmsg) {
226220
return b.String(), nil, nil
227221
}
@@ -324,3 +318,26 @@ type tag struct {
324318
key string
325319
name string
326320
}
321+
322+
func getParam(val reflect.Value) string {
323+
var v string
324+
switch val.Kind() {
325+
case reflect.Ptr:
326+
switch reflect.Indirect(val).Type().String() {
327+
case
328+
"wrapperspb.BoolValue",
329+
"wrapperspb.BytesValue",
330+
"wrapperspb.DoubleValue",
331+
"wrapperspb.FloatValue",
332+
"wrapperspb.Int32Value", "wrapperspb.Int64Value",
333+
"wrapperspb.StringValue",
334+
"wrapperspb.UInt32Value", "wrapperspb.UInt64Value":
335+
if eva := reflect.Indirect(val).FieldByName("Value"); eva.IsValid() {
336+
v = getParam(eva)
337+
}
338+
}
339+
default:
340+
v = fmt.Sprintf("%v", val.Interface())
341+
}
342+
return v
343+
}

0 commit comments

Comments
 (0)