Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prep for TinyGo's v0.28 encoding/json Support #9

Merged
merged 8 commits into from
Oct 8, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 7 additions & 15 deletions extism_pdk.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ package pdk

import (
"encoding/binary"
"encoding/json"
"github.com/extism/go-pdk/internal/models"
"strings"

"github.com/valyala/fastjson"
)

/*
Expand Down Expand Up @@ -233,21 +233,13 @@ func (r *HTTPRequest) SetBody(body []byte) *HTTPRequest {
}

func (r *HTTPRequest) Send() HTTPResponse {
arena := &fastjson.Arena{}
json := arena.NewObject()
headers := arena.NewObject()
if r.header != nil {
for k, v := range r.header {
headers.Set(k, arena.NewString(v))
}

json.Set("header", headers)
meta := models.MetaData{
Url: r.url,
Method: r.method,
Headers: r.header,
}
json.Set("url", arena.NewString(r.url))
json.Set("method", arena.NewString(r.method))

var buf []byte
enc := json.MarshalTo(buf)
enc, _ := json.Marshal(meta)

req := AllocateBytes(enc)
defer req.Free()
Expand Down
2 changes: 0 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
module github.com/extism/go-pdk

go 1.19

require github.com/valyala/fastjson v1.6.3
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,2 +0,0 @@
github.com/valyala/fastjson v1.6.3 h1:tAKFnnwmeMGPbwJ7IwxcTPCNr3uIzoIj3/Fh90ra4xc=
github.com/valyala/fastjson v1.6.3/go.mod h1:CLCAqky6SMuOcxStkYQvblddUtoRxhYMGLrsQns1aXY=
7 changes: 7 additions & 0 deletions internal/models/req_meta_data.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package models
wikiwong marked this conversation as resolved.
Show resolved Hide resolved

type MetaData struct {
Url string `json:"url"`
Method string `json:"method"`
Headers map[string]string `json:"header"`
}