feat: support go1.23 (#66)
* chore: support go1.23 * update sonic * opt: recover to print more context * opt: make more panic msg * update mod * update ci * add go1.23 ci * fix: checkptr * remove all API docs onto go.dev * update
This commit is contained in:
parent
7f139dd108
commit
1e6bfcabfa
|
@ -0,0 +1,48 @@
|
|||
name: Go Latest
|
||||
|
||||
on: push
|
||||
|
||||
jobs:
|
||||
build:
|
||||
strategy:
|
||||
matrix:
|
||||
os: [arm, X64]
|
||||
runs-on: ${{ matrix.os }}
|
||||
steps:
|
||||
- name: Clear repository
|
||||
run: sudo rm -fr $GITHUB_WORKSPACE && mkdir $GITHUB_WORKSPACE
|
||||
|
||||
- uses: actions/checkout@v2
|
||||
|
||||
- name: Set up Go
|
||||
uses: actions/setup-go@v2
|
||||
with:
|
||||
go-version: 1.22.4
|
||||
|
||||
- uses: actions/cache@v2
|
||||
with:
|
||||
path: ~/go/pkg/mod
|
||||
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
|
||||
restore-keys: |
|
||||
${{ runner.os }}-go-
|
||||
|
||||
- name: build go
|
||||
run: sh ./scripts/go_latest.sh go1.23
|
||||
continue-on-error: true
|
||||
|
||||
- name: test
|
||||
run: |
|
||||
PWD=$(pwd)
|
||||
export GOROOT=$PWD/go1.23
|
||||
export PATH=$GOROOT/bin:$PATH
|
||||
go version
|
||||
go test -race github.com/cloudwego/dynamicgo/thrift
|
||||
go test -race github.com/cloudwego/dynamicgo/thrift/annotation
|
||||
go test -race github.com/cloudwego/dynamicgo/thrift/generic
|
||||
go test -race github.com/cloudwego/dynamicgo/conv/t2j
|
||||
go test -race github.com/cloudwego/dynamicgo/http
|
||||
go test -race github.com/cloudwego/dynamicgo/internal/json
|
||||
go test -race github.com/cloudwego/dynamicgo/conv/j2p
|
||||
go test -race github.com/cloudwego/dynamicgo/conv/p2j
|
||||
go test -race github.com/cloudwego/dynamicgo/proto/generic
|
||||
|
|
@ -6,14 +6,14 @@ jobs:
|
|||
build:
|
||||
strategy:
|
||||
matrix:
|
||||
go-version: [1.17.x, 1.20.x]
|
||||
go-version: [1.17.x, 1.22.x]
|
||||
os: [ARM64, X64]
|
||||
runs-on: ${{ matrix.os }}
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
|
||||
- name: Set up Go
|
||||
uses: actions/setup-go@v2
|
||||
uses: actions/setup-go@v5
|
||||
with:
|
||||
go-version: ${{ matrix.go-version }}
|
||||
|
|
@ -7,6 +7,9 @@ Dynamic-Go for Thrift protocol: [introduction.md](introduction.md).
|
|||
Dynamic-Go for Protobuf protocol: [introduction.md](./proto/INTRODUCTION.md)
|
||||
|
||||
## Usage
|
||||
|
||||
[![GoDoc](https://godoc.org/github.com/cloudwego/dynamicgo?status.svg)](https://pkg.go.dev/github.com/cloudwego/dynamicgo?tab=doc)
|
||||
|
||||
### thrift
|
||||
Thrift IDL parser and message operators. It can parse thrift IDL in runtime and handle thrift data in generic way.
|
||||
[DOC](thrift/README.md)
|
||||
|
|
113
conv/README.md
113
conv/README.md
|
@ -1,113 +0,0 @@
|
|||
<!-- Code generated by gomarkdoc. DO NOT EDIT -->
|
||||
|
||||
# conv
|
||||
|
||||
```go
|
||||
import "github.com/cloudwego/dynamicgo/conv"
|
||||
```
|
||||
|
||||
## Index
|
||||
|
||||
- [Variables](<#variables>)
|
||||
- [func FreeBytes(b *[]byte)](<#func-freebytes>)
|
||||
- [func NewBytes() *[]byte](<#func-newbytes>)
|
||||
- [type ContextKey](<#type-contextkey>)
|
||||
- [type Options](<#type-options>)
|
||||
|
||||
|
||||
## Variables
|
||||
|
||||
```go
|
||||
var (
|
||||
// CtxKeyHTTPResponse is the key for http.ResponseSetter in context
|
||||
CtxKeyHTTPResponse = &ContextKey{}
|
||||
// CtxKeyHTTPRequest is the key for http.RequestGetter in context
|
||||
CtxKeyHTTPRequest = &ContextKey{}
|
||||
// CtxKeyThriftRespBase is the key for base.Base in context
|
||||
CtxKeyThriftRespBase = &ContextKey{}
|
||||
// CtxKeyThriftReqBase is the key for base.BaseResp in context
|
||||
CtxKeyThriftReqBase = &ContextKey{}
|
||||
// CtxKeyConvOptions is the key for Options in context
|
||||
CtxKeyConvOptions = &ContextKey{}
|
||||
)
|
||||
```
|
||||
|
||||
```go
|
||||
var (
|
||||
// DefaultBufferSize is the default buffer size for conversion
|
||||
DefaultBufferSize = 4096
|
||||
// DefaultHttpValueBufferSize is the default buffer size for copying a json value
|
||||
DefaulHttpValueBufferSizeForJSON = 1024
|
||||
// DefaultHttpValueBufferSize is the default buffer size for copying a http value
|
||||
DefaulHttpValueBufferSizeForScalar = 64
|
||||
)
|
||||
```
|
||||
|
||||
## func FreeBytes
|
||||
|
||||
```go
|
||||
func FreeBytes(b *[]byte)
|
||||
```
|
||||
|
||||
FreeBytes returns a byte slice to pool and reset it
|
||||
|
||||
## func NewBytes
|
||||
|
||||
```go
|
||||
func NewBytes() *[]byte
|
||||
```
|
||||
|
||||
NewBytes returns a new byte slice from pool
|
||||
|
||||
## type ContextKey
|
||||
|
||||
ContextKey is the key type for context arguments
|
||||
|
||||
```go
|
||||
type ContextKey struct {
|
||||
// contains filtered or unexported fields
|
||||
}
|
||||
```
|
||||
|
||||
## type Options
|
||||
|
||||
```go
|
||||
type Options struct {
|
||||
// DisallowUnknownField indicates if unknown fields should be skipped
|
||||
DisallowUnknownField bool
|
||||
// WriteDefaultField indicates if default-requireness fields should be written if
|
||||
WriteDefaultField bool
|
||||
// EnableValueMapping indicates if value mapping (api.js_conv...) should be enabled
|
||||
EnableValueMapping bool
|
||||
// EnableHttpMapping indicates if http mapping (api.query|api.header...) should be enabled
|
||||
EnableHttpMapping bool
|
||||
// HttpMappingAsExtra indicates if continuing convert the same field after http mapping
|
||||
HttpMappingAsExtra bool
|
||||
// EnableThriftBase indicates if thrift/base should be recoginized and mapping to/from context
|
||||
EnableThriftBase bool
|
||||
// UseNativeSkip indicates if use thrift.SkipNative() or thrift.SkipGo()
|
||||
UseNativeSkip bool
|
||||
// Int64AsString indicates if string value cane be read as **Int8/Int16/Int32/Int64/Float64**,
|
||||
// or in response a **Int64** value can be written as string
|
||||
String2Int64 bool
|
||||
// WriteRequireField indicates if required-requireness fields should be written empty value if
|
||||
// not found
|
||||
WriteRequireField bool
|
||||
// NoBase64Binary indicates if base64 string shoud be Encode/Decode as []byte
|
||||
NoBase64Binary bool
|
||||
// ByteAsUint8 indicates if byte should be conv as uint8 (default is int8), this only works for t2j now
|
||||
ByteAsUint8 bool
|
||||
// WriteOptionalField indicates if optional-requireness fields should be written when not given
|
||||
WriteOptionalField bool
|
||||
// TracebackRequredOrRootFields indicates if required-requireness
|
||||
// or root-level fields should be seeking on http-values when reading failed from current layer of json.
|
||||
// this option is only used in j2t now.
|
||||
TracebackRequredOrRootFields bool
|
||||
// NoCopyString indicates if string should be copied or just referenced (if possible)
|
||||
NoCopyString bool
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
|
||||
Generated by [gomarkdoc](<https://github.com/princjef/gomarkdoc>)
|
|
@ -1,122 +0,0 @@
|
|||
<!-- Code generated by gomarkdoc. DO NOT EDIT -->
|
||||
|
||||
# j2p
|
||||
|
||||
```go
|
||||
import "github.com/cloudwego/dynamicgo/conv/j2p"
|
||||
```
|
||||
|
||||
## Index
|
||||
|
||||
- [type BinaryConv](<#BinaryConv>)
|
||||
- [func NewBinaryConv(opts conv.Options) BinaryConv](<#NewBinaryConv>)
|
||||
- [func (self *BinaryConv) Do(ctx context.Context, desc *proto.TypeDescriptor, jbytes []byte) (tbytes []byte, err error)](<#BinaryConv.Do>)
|
||||
- [func (self *BinaryConv) DoInto(ctx context.Context, desc *proto.TypeDescriptor, jbytes []byte, buf *[]byte) error](<#BinaryConv.DoInto>)
|
||||
|
||||
|
||||
<a name="BinaryConv"></a>
|
||||
## type [BinaryConv](<https://github.com/khan-yin/dynamicgo/blob/main/conv/j2p/conv.go#L13-L15>)
|
||||
|
||||
BinaryConv is a converter from json to protobuf binary
|
||||
|
||||
```go
|
||||
type BinaryConv struct {
|
||||
// contains filtered or unexported fields
|
||||
}
|
||||
```
|
||||
|
||||
<a name="NewBinaryConv"></a>
|
||||
### func [NewBinaryConv](<https://github.com/khan-yin/dynamicgo/blob/main/conv/j2p/conv.go#L18>)
|
||||
|
||||
```go
|
||||
func NewBinaryConv(opts conv.Options) BinaryConv
|
||||
```
|
||||
|
||||
NewBinaryConv returns a new BinaryConv
|
||||
|
||||
<a name="BinaryConv.Do"></a>
|
||||
### func (*BinaryConv) [Do](<https://github.com/khan-yin/dynamicgo/blob/main/conv/j2p/conv.go#L26>)
|
||||
|
||||
```go
|
||||
func (self *BinaryConv) Do(ctx context.Context, desc *proto.TypeDescriptor, jbytes []byte) (tbytes []byte, err error)
|
||||
```
|
||||
|
||||
Do converts json bytes (jbytes) to protobuf binary (tbytes) desc is the protobuf type descriptor of the protobuf binary, usually it the request Message type
|
||||
|
||||
<details><summary>Example</summary>
|
||||
<p>
|
||||
|
||||
|
||||
|
||||
```go
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"reflect"
|
||||
|
||||
"github.com/cloudwego/dynamicgo/conv"
|
||||
"github.com/cloudwego/dynamicgo/testdata/kitex_gen/pb/example2"
|
||||
"google.golang.org/protobuf/encoding/protowire"
|
||||
)
|
||||
|
||||
var opts = conv.Options{}
|
||||
|
||||
func main() {
|
||||
// get descriptor and data
|
||||
desc := getExampleDesc()
|
||||
data := getExampleData()
|
||||
|
||||
// make BinaryConv
|
||||
cv := NewBinaryConv(opts)
|
||||
|
||||
// do conversion
|
||||
out, err := cv.Do(context.Background(), desc, data)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
// validate result
|
||||
exp := &example2.ExampleReq{}
|
||||
err = json.Unmarshal(data, exp)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
act := &example2.ExampleReq{}
|
||||
l := 0
|
||||
dataLen := len(out)
|
||||
// fastRead to get target struct
|
||||
for l < dataLen {
|
||||
id, wtyp, tagLen := protowire.ConsumeTag(out)
|
||||
if tagLen < 0 {
|
||||
panic("parseTag failed")
|
||||
}
|
||||
l += tagLen
|
||||
out = out[tagLen:]
|
||||
offset, err := act.FastRead(out, int8(wtyp), int32(id))
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
out = out[offset:]
|
||||
l += offset
|
||||
}
|
||||
if !reflect.DeepEqual(exp, act) {
|
||||
panic("not equal")
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
</p>
|
||||
</details>
|
||||
|
||||
<a name="BinaryConv.DoInto"></a>
|
||||
### func (*BinaryConv) [DoInto](<https://github.com/khan-yin/dynamicgo/blob/main/conv/j2p/conv.go#L55>)
|
||||
|
||||
```go
|
||||
func (self *BinaryConv) DoInto(ctx context.Context, desc *proto.TypeDescriptor, jbytes []byte, buf *[]byte) error
|
||||
```
|
||||
|
||||
DoInto behaves like Do, but it writes the result to buffer directly instead of returning a new buffer
|
||||
|
||||
Generated by [gomarkdoc](<https://github.com/princjef/gomarkdoc>)
|
|
@ -1,191 +0,0 @@
|
|||
<!-- Code generated by gomarkdoc. DO NOT EDIT -->
|
||||
|
||||
# j2t
|
||||
|
||||
```go
|
||||
import "github.com/cloudwego/dynamicgo/conv/j2t"
|
||||
```
|
||||
|
||||
## Index
|
||||
|
||||
- [type BinaryConv](<#type-binaryconv>)
|
||||
- [func NewBinaryConv(opts conv.Options) BinaryConv](<#func-newbinaryconv>)
|
||||
- [func (self *BinaryConv) Do(ctx context.Context, desc *thrift.TypeDescriptor, jbytes []byte) (tbytes []byte, err error)](<#func-binaryconv-do>)
|
||||
- [func (self *BinaryConv) DoInto(ctx context.Context, desc *thrift.TypeDescriptor, jbytes []byte, buf *[]byte) (err error)](<#func-binaryconv-dointo>)
|
||||
- [func (self *BinaryConv) SetOptions(opts conv.Options)](<#func-binaryconv-setoptions>)
|
||||
- [type HTTPConv](<#type-httpconv>)
|
||||
- [func NewHTTPConv(proto meta.Encoding, fnDesc *thrift.FunctionDescriptor) *HTTPConv](<#func-newhttpconv>)
|
||||
- [func (h HTTPConv) Do(ctx context.Context, req http.RequestGetter, opt conv.Options) (tbytes []byte, err error)](<#func-httpconv-do>)
|
||||
- [func (h HTTPConv) DoInto(ctx context.Context, req http.RequestGetter, buf *[]byte, opt conv.Options) (err error)](<#func-httpconv-dointo>)
|
||||
|
||||
|
||||
## type BinaryConv
|
||||
|
||||
BinaryConv is a converter from json to thrift binary
|
||||
|
||||
```go
|
||||
type BinaryConv struct {
|
||||
// contains filtered or unexported fields
|
||||
}
|
||||
```
|
||||
|
||||
### func NewBinaryConv
|
||||
|
||||
```go
|
||||
func NewBinaryConv(opts conv.Options) BinaryConv
|
||||
```
|
||||
|
||||
NewBinaryConv returns a new BinaryConv
|
||||
|
||||
### func \(\*BinaryConv\) Do
|
||||
|
||||
```go
|
||||
func (self *BinaryConv) Do(ctx context.Context, desc *thrift.TypeDescriptor, jbytes []byte) (tbytes []byte, err error)
|
||||
```
|
||||
|
||||
#### Do converts json bytes \(jbytes\) to thrift binary \(tbytes\)
|
||||
|
||||
desc is the thrift type descriptor of the thrift binary, usually it the request STRUCT type ctx is the context, which can be used to pass arguments as below: \- conv.CtxKeyHTTPRequest: http.RequestGetter as http request \- conv.CtxKeyThriftRespBase: thrift.Base as base metadata of thrift response
|
||||
|
||||
<details><summary>Example</summary>
|
||||
<p>
|
||||
|
||||
```go
|
||||
{
|
||||
|
||||
desc := getExampleDesc()
|
||||
data := getExampleData()
|
||||
|
||||
cv := NewBinaryConv(opts)
|
||||
|
||||
out, err := cv.Do(context.Background(), desc, data)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
exp := example3.NewExampleReq()
|
||||
err = json.Unmarshal(data, exp)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
act := example3.NewExampleReq()
|
||||
_, err = act.FastRead(out)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
if !reflect.DeepEqual(exp, act) {
|
||||
panic("not equal")
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
</p>
|
||||
</details>
|
||||
|
||||
### func \(\*BinaryConv\) DoInto
|
||||
|
||||
```go
|
||||
func (self *BinaryConv) DoInto(ctx context.Context, desc *thrift.TypeDescriptor, jbytes []byte, buf *[]byte) (err error)
|
||||
```
|
||||
|
||||
DoInto behaves like Do, but it writes the result to buffer directly instead of returning a new buffer
|
||||
|
||||
### func \(\*BinaryConv\) SetOptions
|
||||
|
||||
```go
|
||||
func (self *BinaryConv) SetOptions(opts conv.Options)
|
||||
```
|
||||
|
||||
SetOptions sets options
|
||||
|
||||
## type HTTPConv
|
||||
|
||||
HTTPConv is a converter from http request to thrift message
|
||||
|
||||
```go
|
||||
type HTTPConv struct {
|
||||
// contains filtered or unexported fields
|
||||
}
|
||||
```
|
||||
|
||||
### func NewHTTPConv
|
||||
|
||||
```go
|
||||
func NewHTTPConv(proto meta.Encoding, fnDesc *thrift.FunctionDescriptor) *HTTPConv
|
||||
```
|
||||
|
||||
NewHTTPConv returns a new HTTPConv, which contains the thrift message header and footer
|
||||
|
||||
proto is specified thrift encoding protocol \(meta.EncodingThriftBinary|meta.EncodingThriftCompact\) fnDesc is the thrift method descriptor corresponding to the http request url
|
||||
|
||||
### func \(HTTPConv\) Do
|
||||
|
||||
```go
|
||||
func (h HTTPConv) Do(ctx context.Context, req http.RequestGetter, opt conv.Options) (tbytes []byte, err error)
|
||||
```
|
||||
|
||||
Do converts http request into thrift message. req body must be one of following: \- json \(application/json\) \- url encoded form \(application/x\-www\-form\-urlencoded\) \- empty
|
||||
|
||||
### func \(HTTPConv\) DoInto
|
||||
|
||||
```go
|
||||
func (h HTTPConv) DoInto(ctx context.Context, req http.RequestGetter, buf *[]byte, opt conv.Options) (err error)
|
||||
```
|
||||
|
||||
<details><summary>Example</summary>
|
||||
<p>
|
||||
|
||||
```go
|
||||
{
|
||||
|
||||
svc, err := thrift.NewDescritorFromPath(context.Background(), exampleIDLPath)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
fn := svc.Functions()["ExampleMethod"]
|
||||
|
||||
cv := NewHTTPConv(meta.EncodingThriftBinary, fn)
|
||||
|
||||
jdata := `{"msg":"hello","InnerBase":{}}`
|
||||
stdreq, err := stdhttp.NewRequest("POST",
|
||||
"http://localhost:8080/example?query=1,2,3&inner_query=中文",
|
||||
strings.NewReader(jdata))
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
stdreq.Header.Set("Content-Type", "application/json")
|
||||
stdreq.Header.Set("heeader", "true")
|
||||
stdreq.Header.Set("inner_string", "igorned")
|
||||
|
||||
req, err := http.NewHTTPRequestFromStdReq(
|
||||
stdreq,
|
||||
http.Param{Key: "path", Value: "OK"},
|
||||
http.Param{Key: "inner_string", Value: "priority"},
|
||||
)
|
||||
|
||||
buf := make([]byte, 0, len(jdata)*2/3)
|
||||
|
||||
err = cv.DoInto(context.Background(), req, &buf, opts)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
p := thrift.NewBinaryProtocol(buf)
|
||||
method, mType, seqID, reqID, stru, err := p.UnwrapBody()
|
||||
println(method, mType, seqID, reqID)
|
||||
|
||||
act := example3.NewExampleReq()
|
||||
_, err = act.FastRead(stru)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
spew.Dump(act)
|
||||
}
|
||||
```
|
||||
|
||||
</p>
|
||||
</details>
|
||||
|
||||
|
||||
|
||||
Generated by [gomarkdoc](<https://github.com/princjef/gomarkdoc>)
|
|
@ -171,6 +171,32 @@ func TestConvJSON2Thrift(t *testing.T) {
|
|||
require.Equal(t, exp, act)
|
||||
}
|
||||
|
||||
func TestPanicRecover(t *testing.T) {
|
||||
desc := getExampleDesc()
|
||||
data := getExampleData()
|
||||
exp := example3.NewExampleReq()
|
||||
err := json.Unmarshal(data, exp)
|
||||
require.Nil(t, err)
|
||||
req := getExampleReq(exp, true, data)
|
||||
cv := NewBinaryConv(conv.Options{
|
||||
EnableHttpMapping: true,
|
||||
})
|
||||
ctx := context.Background()
|
||||
ctx = context.WithValue(ctx, conv.CtxKeyHTTPRequest, req)
|
||||
buf := make([]byte, 0, 1)
|
||||
mock := MockConv{
|
||||
panic:2,
|
||||
}
|
||||
defer func() {
|
||||
if v := recover(); v == nil {
|
||||
t.Fatal("not panic")
|
||||
} else {
|
||||
t.Log(v)
|
||||
}
|
||||
}()
|
||||
_ = mock.do(&cv, ctx, data, desc, &buf, req, true)
|
||||
}
|
||||
|
||||
func TestConvHTTP2Thrift(t *testing.T) {
|
||||
desc := getExampleDesc()
|
||||
data := getExampleData()
|
||||
|
@ -683,7 +709,6 @@ func TestError(t *testing.T) {
|
|||
sp: types.MAX_RECURSE + 1,
|
||||
reqsCache: 1,
|
||||
keyCache: 1,
|
||||
dcap: 800,
|
||||
}
|
||||
err := mock.do(&cv, ctx, src, desc, &buf, nil, true)
|
||||
require.Error(t, err)
|
||||
|
@ -724,8 +749,8 @@ type MockConv struct {
|
|||
sp int
|
||||
reqsCache int
|
||||
keyCache int
|
||||
dcap int
|
||||
fc int
|
||||
fieldCache int
|
||||
panic int
|
||||
}
|
||||
|
||||
func (mock *MockConv) Do(self *BinaryConv, ctx context.Context, desc *thrift.TypeDescriptor, jbytes []byte) (tbytes []byte, err error) {
|
||||
|
@ -759,26 +784,46 @@ func (mock *MockConv) Do(self *BinaryConv, ctx context.Context, desc *thrift.Typ
|
|||
func (mock MockConv) do(self *BinaryConv, ctx context.Context, src []byte, desc *thrift.TypeDescriptor, buf *[]byte, req http.RequestGetter, top bool) (err error) {
|
||||
flags := toFlags(self.opts)
|
||||
jp := rt.Mem2Str(src)
|
||||
tmp := make([]byte, 0, mock.dcap)
|
||||
fsm := &types.J2TStateMachine{
|
||||
SP: mock.sp,
|
||||
JT: types.JsonState{
|
||||
Dbuf: *(**byte)(unsafe.Pointer(&tmp)),
|
||||
Dcap: mock.dcap,
|
||||
},
|
||||
ReqsCache: make([]byte, 0, mock.reqsCache),
|
||||
KeyCache: make([]byte, 0, mock.keyCache),
|
||||
SM: types.StateMachine{},
|
||||
VT: [types.MAX_RECURSE]types.J2TState{},
|
||||
FieldCache: make([]int32, 0, mock.fc),
|
||||
// tmp := make([]byte, 0, mock.dcap)
|
||||
fsm := types.NewJ2TStateMachine()
|
||||
if mock.reqsCache != 0 {
|
||||
fsm.ReqsCache = make([]byte, 0, mock.reqsCache)
|
||||
}
|
||||
if mock.keyCache != 0 {
|
||||
fsm.KeyCache = make([]byte, 0, mock.keyCache)
|
||||
}
|
||||
if mock.fieldCache != 0 {
|
||||
fsm.FieldCache = make([]int32, 0, mock.fieldCache)
|
||||
}
|
||||
// fsm := &types.J2TStateMachine{
|
||||
// SP: mock.sp,
|
||||
// JT: types.JsonState{
|
||||
// Dbuf: *(**byte)(unsafe.Pointer(&tmp)),
|
||||
// Dcap: mock.dcap,
|
||||
// },
|
||||
// ReqsCache: make([]byte, 0, mock.reqsCache),
|
||||
// KeyCache: make([]byte, 0, mock.keyCache),
|
||||
// SM: types.StateMachine{},
|
||||
// VT: [types.MAX_RECURSE]types.J2TState{},
|
||||
// FieldCache: make([]int32, 0, mock.fc),
|
||||
// }
|
||||
fsm.Init(0, unsafe.Pointer(desc))
|
||||
if mock.sp != 0 {
|
||||
fsm.SP = mock.sp
|
||||
}
|
||||
var ret uint64
|
||||
defer func() {
|
||||
if msg := recover(); msg != nil {
|
||||
panic(makePanicMsg(msg, src, desc, buf, req, self.flags, fsm, ret))
|
||||
}
|
||||
}()
|
||||
|
||||
exec:
|
||||
ret := native.J2T_FSM(fsm, buf, &jp, flags)
|
||||
mock.panic -= 1
|
||||
if mock.panic == 0 {
|
||||
panic("test!")
|
||||
}
|
||||
ret = native.J2T_FSM(fsm, buf, &jp, flags)
|
||||
if ret != 0 {
|
||||
cont, e := self.handleError(ctx, fsm, buf, src, req, ret, top)
|
||||
if cont && e == nil {
|
||||
|
@ -807,7 +852,6 @@ func TestStateMachineOOM(t *testing.T) {
|
|||
sp: 0,
|
||||
reqsCache: 1,
|
||||
keyCache: 1,
|
||||
dcap: 800,
|
||||
}
|
||||
err := mock.do(&cv, ctx, src, desc, &buf, nil, true)
|
||||
require.Nil(t, err)
|
||||
|
@ -844,8 +888,7 @@ func TestStateMachineOOM(t *testing.T) {
|
|||
sp: 1,
|
||||
reqsCache: 1,
|
||||
keyCache: 1,
|
||||
dcap: 800,
|
||||
fc: 0,
|
||||
fieldCache: 0,
|
||||
}
|
||||
cv := NewBinaryConv(conv.Options{
|
||||
EnableHttpMapping: true,
|
||||
|
|
|
@ -55,7 +55,7 @@ func getJ2TExtraStruct(fsm *types.J2TStateMachine, offset int) (td *thrift.TypeD
|
|||
}
|
||||
|
||||
func (self BinaryConv) handleError(ctx context.Context, fsm *types.J2TStateMachine, buf *[]byte, src []byte, req http.RequestGetter, ret uint64, top bool) (cont bool, err error) {
|
||||
e := types.ParsingError(ret & ((1 << types.ERR_WRAP_SHIFT_CODE) - 1))
|
||||
e := getErrCode(ret)
|
||||
p := int(ret >> types.ERR_WRAP_SHIFT_CODE)
|
||||
|
||||
switch e {
|
||||
|
@ -131,12 +131,25 @@ func (self BinaryConv) handleError(ctx context.Context, fsm *types.J2TStateMachi
|
|||
}
|
||||
}
|
||||
|
||||
return false, explainNativeError(e, src, p)
|
||||
return false, explainNativeError(ret, src)
|
||||
}
|
||||
|
||||
func explainNativeError(e types.ParsingError, in []byte, v int) error {
|
||||
ip := v & ((1 << types.ERR_WRAP_SHIFT_POS) - 1)
|
||||
v = v >> types.ERR_WRAP_SHIFT_POS
|
||||
func getPos(e uint64) int {
|
||||
return int(e >> types.ERR_WRAP_SHIFT_CODE) & ((1 << types.ERR_WRAP_SHIFT_POS) - 1)
|
||||
}
|
||||
|
||||
func getErrCode(e uint64) types.ParsingError {
|
||||
return types.ParsingError(e & ((1 << types.ERR_WRAP_SHIFT_CODE) - 1))
|
||||
}
|
||||
|
||||
func getValue(e uint64) int {
|
||||
return int(e >> (types.ERR_WRAP_SHIFT_CODE + types.ERR_WRAP_SHIFT_POS))
|
||||
}
|
||||
|
||||
func explainNativeError(ret uint64, in []byte) error {
|
||||
ip := getPos(ret)
|
||||
v := getValue(ret)
|
||||
e := getErrCode(ret)
|
||||
switch e {
|
||||
case types.ERR_INVALID_CHAR:
|
||||
ch, st := v>>types.ERR_WRAP_SHIFT_CODE, v&((1<<types.ERR_WRAP_SHIFT_CODE)-1)
|
||||
|
@ -179,3 +192,22 @@ func locateInput(in []byte, ip int) string {
|
|||
}
|
||||
return je.Locate()
|
||||
}
|
||||
|
||||
func makePanicMsg(msg interface{}, src []byte, desc *thrift.TypeDescriptor, buf *[]byte, req http.RequestGetter, flags uint64, fsm *types.J2TStateMachine, ret uint64) string {
|
||||
var re string
|
||||
if rt, ok := req.(*http.HTTPRequest); ok {
|
||||
re = fmt.Sprintf("%v", rt)
|
||||
}
|
||||
return fmt.Sprintf(`%v
|
||||
Flags: %b
|
||||
JSON: %s
|
||||
Buf: %v
|
||||
<FSM>
|
||||
%s
|
||||
</FSM>
|
||||
Desc: %s
|
||||
<Request>
|
||||
%s
|
||||
</Request>
|
||||
Ret: %x`, msg, flags, string(src), *buf, fsm.String(), desc.Name(), re, ret)
|
||||
}
|
||||
|
|
|
@ -91,22 +91,29 @@ func (self *BinaryConv) do(ctx context.Context, src []byte, desc *thrift.TypeDes
|
|||
}
|
||||
|
||||
func (self *BinaryConv) doNative(ctx context.Context, src []byte, desc *thrift.TypeDescriptor, buf *[]byte, req http.RequestGetter, top bool) (err error) {
|
||||
jp := rt.Mem2Str(src)
|
||||
fsm := types.NewJ2TStateMachine()
|
||||
var ret uint64
|
||||
defer func() {
|
||||
if msg := recover(); msg != nil {
|
||||
panic(makePanicMsg(msg, src, desc, buf, req, self.flags, fsm, ret))
|
||||
}
|
||||
}()
|
||||
|
||||
jp := rt.Mem2Str(src)
|
||||
fsm.Init(0, unsafe.Pointer(desc))
|
||||
|
||||
exec:
|
||||
ret := native.J2T_FSM(fsm, buf, &jp, self.flags)
|
||||
ret = native.J2T_FSM(fsm, buf, &jp, self.flags)
|
||||
if ret != 0 {
|
||||
cont, e := self.handleError(ctx, fsm, buf, src, req, ret, top)
|
||||
if cont && e == nil {
|
||||
goto exec
|
||||
}
|
||||
err = e
|
||||
goto ret
|
||||
goto final
|
||||
}
|
||||
|
||||
ret:
|
||||
final:
|
||||
types.FreeJ2TStateMachine(fsm)
|
||||
runtime.KeepAlive(desc)
|
||||
runtime.KeepAlive(src)
|
||||
|
|
|
@ -1,139 +0,0 @@
|
|||
<!-- Code generated by gomarkdoc. DO NOT EDIT -->
|
||||
|
||||
# p2j
|
||||
|
||||
```go
|
||||
import "github.com/cloudwego/dynamicgo/conv/p2j"
|
||||
```
|
||||
|
||||
## Index
|
||||
|
||||
- [type BinaryConv](<#BinaryConv>)
|
||||
- [func NewBinaryConv(opts conv.Options) BinaryConv](<#NewBinaryConv>)
|
||||
- [func (self *BinaryConv) Do(ctx context.Context, desc *proto.TypeDescriptor, pbytes []byte) (json []byte, err error)](<#BinaryConv.Do>)
|
||||
- [func (self *BinaryConv) DoInto(ctx context.Context, desc *proto.TypeDescriptor, pbytes []byte, buf *[]byte) (err error)](<#BinaryConv.DoInto>)
|
||||
- [func (self *BinaryConv) SetOptions(opts conv.Options)](<#BinaryConv.SetOptions>)
|
||||
|
||||
|
||||
<a name="BinaryConv"></a>
|
||||
## type [BinaryConv](<https://github.com/khan-yin/dynamicgo/blob/main/conv/p2j/conv.go#L12-L14>)
|
||||
|
||||
|
||||
|
||||
```go
|
||||
type BinaryConv struct {
|
||||
// contains filtered or unexported fields
|
||||
}
|
||||
```
|
||||
|
||||
<a name="NewBinaryConv"></a>
|
||||
### func [NewBinaryConv](<https://github.com/khan-yin/dynamicgo/blob/main/conv/p2j/conv.go#L17>)
|
||||
|
||||
```go
|
||||
func NewBinaryConv(opts conv.Options) BinaryConv
|
||||
```
|
||||
|
||||
NewBinaryConv returns a new BinaryConv
|
||||
|
||||
<a name="BinaryConv.Do"></a>
|
||||
### func (*BinaryConv) [Do](<https://github.com/khan-yin/dynamicgo/blob/main/conv/p2j/conv.go#L28>)
|
||||
|
||||
```go
|
||||
func (self *BinaryConv) Do(ctx context.Context, desc *proto.TypeDescriptor, pbytes []byte) (json []byte, err error)
|
||||
```
|
||||
|
||||
Do converts protobuf binary (pbytes) to json bytes (jbytes) desc is the protobuf type descriptor of the protobuf binary, usually it is a response Message type
|
||||
|
||||
<details><summary>Example</summary>
|
||||
<p>
|
||||
|
||||
|
||||
|
||||
```go
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"reflect"
|
||||
|
||||
"github.com/cloudwego/dynamicgo/conv"
|
||||
"github.com/cloudwego/dynamicgo/internal/util_test"
|
||||
"github.com/cloudwego/dynamicgo/proto"
|
||||
"github.com/cloudwego/dynamicgo/testdata/kitex_gen/pb/example2"
|
||||
goprotowire "google.golang.org/protobuf/encoding/protowire"
|
||||
)
|
||||
|
||||
var opts = conv.Options{}
|
||||
|
||||
func main() {
|
||||
// get descriptor and data
|
||||
includeDirs := util_test.MustGitPath("testdata/idl/") // includeDirs is used to find the include files.
|
||||
desc := proto.FnRequest(proto.GetFnDescFromFile(exampleIDLPath, "ExampleMethod", proto.Options{}, includeDirs))
|
||||
|
||||
// make BinaryConv
|
||||
cv := NewBinaryConv(conv.Options{})
|
||||
in := readExampleReqProtoBufData()
|
||||
|
||||
// do conversion
|
||||
out, err := cv.Do(context.Background(), desc, in)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
exp := example2.ExampleReq{}
|
||||
|
||||
// use kitex_util to check proto data validity
|
||||
l := 0
|
||||
dataLen := len(in)
|
||||
for l < dataLen {
|
||||
id, wtyp, tagLen := goprotowire.ConsumeTag(in)
|
||||
if tagLen < 0 {
|
||||
panic("proto data error format")
|
||||
}
|
||||
l += tagLen
|
||||
in = in[tagLen:]
|
||||
offset, err := exp.FastRead(in, int8(wtyp), int32(id))
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
in = in[offset:]
|
||||
l += offset
|
||||
}
|
||||
if len(in) != 0 {
|
||||
panic("proto data error format")
|
||||
}
|
||||
|
||||
// validate result
|
||||
var act example2.ExampleReq
|
||||
err = json.Unmarshal([]byte(out), &act)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
if !reflect.DeepEqual(exp, act) {
|
||||
panic("not equal")
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
</p>
|
||||
</details>
|
||||
|
||||
<a name="BinaryConv.DoInto"></a>
|
||||
### func (*BinaryConv) [DoInto](<https://github.com/khan-yin/dynamicgo/blob/main/conv/p2j/conv.go#L57>)
|
||||
|
||||
```go
|
||||
func (self *BinaryConv) DoInto(ctx context.Context, desc *proto.TypeDescriptor, pbytes []byte, buf *[]byte) (err error)
|
||||
```
|
||||
|
||||
DoInto behaves like Do, but it writes the result to buffer directly instead of returning a new buffer
|
||||
|
||||
<a name="BinaryConv.SetOptions"></a>
|
||||
### func (*BinaryConv) [SetOptions](<https://github.com/khan-yin/dynamicgo/blob/main/conv/p2j/conv.go#L22>)
|
||||
|
||||
```go
|
||||
func (self *BinaryConv) SetOptions(opts conv.Options)
|
||||
```
|
||||
|
||||
SetOptions sets options
|
||||
|
||||
Generated by [gomarkdoc](<https://github.com/princjef/gomarkdoc>)
|
|
@ -1,178 +0,0 @@
|
|||
<!-- Code generated by gomarkdoc. DO NOT EDIT -->
|
||||
|
||||
# t2j
|
||||
|
||||
```go
|
||||
import "github.com/cloudwego/dynamicgo/conv/t2j"
|
||||
```
|
||||
|
||||
## Index
|
||||
|
||||
- [type BinaryConv](<#type-binaryconv>)
|
||||
- [func NewBinaryConv(opts conv.Options) BinaryConv](<#func-newbinaryconv>)
|
||||
- [func (self *BinaryConv) Do(ctx context.Context, desc *thrift.TypeDescriptor, tbytes []byte) (json []byte, err error)](<#func-binaryconv-do>)
|
||||
- [func (self *BinaryConv) DoInto(ctx context.Context, desc *thrift.TypeDescriptor, tbytes []byte, buf *[]byte) (err error)](<#func-binaryconv-dointo>)
|
||||
- [func (self *BinaryConv) SetOptions(opts conv.Options)](<#func-binaryconv-setoptions>)
|
||||
- [type HTTPConv](<#type-httpconv>)
|
||||
- [func NewHTTPConv(proto meta.Encoding, desc *thrift.FunctionDescriptor) *HTTPConv](<#func-newhttpconv>)
|
||||
- [func (h HTTPConv) Do(ctx context.Context, resp http.ResponseSetter, tbytes []byte, opt conv.Options) (err error)](<#func-httpconv-do>)
|
||||
- [func (h HTTPConv) DoInto(ctx context.Context, resp http.ResponseSetter, tbytes []byte, buf *[]byte, opt conv.Options) (err error)](<#func-httpconv-dointo>)
|
||||
|
||||
|
||||
## type BinaryConv
|
||||
|
||||
BinaryConv is a converter from thrift binary to json
|
||||
|
||||
```go
|
||||
type BinaryConv struct {
|
||||
// contains filtered or unexported fields
|
||||
}
|
||||
```
|
||||
|
||||
### func NewBinaryConv
|
||||
|
||||
```go
|
||||
func NewBinaryConv(opts conv.Options) BinaryConv
|
||||
```
|
||||
|
||||
NewBinaryConv returns a new BinaryConv
|
||||
|
||||
### func \(\*BinaryConv\) Do
|
||||
|
||||
```go
|
||||
func (self *BinaryConv) Do(ctx context.Context, desc *thrift.TypeDescriptor, tbytes []byte) (json []byte, err error)
|
||||
```
|
||||
|
||||
#### Do converts thrift binary \(tbytes\) to json bytes \(jbytes\)
|
||||
|
||||
desc is the thrift type descriptor of the thrift binary, usually it is a response STRUCT type ctx is the context, which can be used to pass arguments as below: \- conv.CtxKeyHTTPResponse: http.ResponseSetter as http request \- conv.CtxKeyThriftRespBase: thrift.Base as base metadata of thrift response
|
||||
|
||||
<details><summary>Example</summary>
|
||||
<p>
|
||||
|
||||
```go
|
||||
{
|
||||
|
||||
desc := thrift.FnResponse(thrift.GetFnDescFromFile("testdata/idl/example3.thrift", "ExampleMethod", thrift.Options{}))
|
||||
data := getExample3Data()
|
||||
|
||||
cv := NewBinaryConv(opts)
|
||||
|
||||
out, err := cv.Do(context.Background(), desc, data)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
// validate result
|
||||
var exp, act example3.ExampleResp
|
||||
_, err = exp.FastRead(data)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
err = json.Unmarshal(out, &act)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
if !reflect.DeepEqual(exp, act) {
|
||||
panic("not equal")
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
</p>
|
||||
</details>
|
||||
|
||||
### func \(\*BinaryConv\) DoInto
|
||||
|
||||
```go
|
||||
func (self *BinaryConv) DoInto(ctx context.Context, desc *thrift.TypeDescriptor, tbytes []byte, buf *[]byte) (err error)
|
||||
```
|
||||
|
||||
DoInto behaves like Do, but it writes the result to buffer directly instead of returning a new buffer
|
||||
|
||||
### func \(\*BinaryConv\) SetOptions
|
||||
|
||||
```go
|
||||
func (self *BinaryConv) SetOptions(opts conv.Options)
|
||||
```
|
||||
|
||||
SetOptions sets options
|
||||
|
||||
## type HTTPConv
|
||||
|
||||
HTTPConv is a converter from thrift message to http response
|
||||
|
||||
```go
|
||||
type HTTPConv struct {
|
||||
// contains filtered or unexported fields
|
||||
}
|
||||
```
|
||||
|
||||
### func NewHTTPConv
|
||||
|
||||
```go
|
||||
func NewHTTPConv(proto meta.Encoding, desc *thrift.FunctionDescriptor) *HTTPConv
|
||||
```
|
||||
|
||||
NewHTTPConv returns a new HTTPConv
|
||||
|
||||
### func \(HTTPConv\) Do
|
||||
|
||||
```go
|
||||
func (h HTTPConv) Do(ctx context.Context, resp http.ResponseSetter, tbytes []byte, opt conv.Options) (err error)
|
||||
```
|
||||
|
||||
Do converts thrift message \(tbytes\) into http response. resp body is set as json protocol if has
|
||||
|
||||
### func \(HTTPConv\) DoInto
|
||||
|
||||
```go
|
||||
func (h HTTPConv) DoInto(ctx context.Context, resp http.ResponseSetter, tbytes []byte, buf *[]byte, opt conv.Options) (err error)
|
||||
```
|
||||
|
||||
DoInto converts the thrift message \(tbytes\) to into buf in JSON protocol, as well as other http response arguments. WARN: This will set buf to resp, thus DONOT reuse the buf afterward.
|
||||
|
||||
<details><summary>Example</summary>
|
||||
<p>
|
||||
|
||||
```go
|
||||
{
|
||||
|
||||
desc := thrift.GetFnDescFromFile("testdata/idl/example3.thrift", "ExampleMethod", thrift.Options{})
|
||||
|
||||
data := getExample3Data()
|
||||
in, err := thrift.WrapBinaryBody(data, "ExampleMethod", thrift.REPLY, thrift.FieldID(0), 1)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
resp := http.NewHTTPResponse()
|
||||
resp.StatusCode = 200
|
||||
|
||||
cv := NewHTTPConv(meta.EncodingThriftBinary, desc)
|
||||
|
||||
buf := make([]byte, 0, len(data)*2)
|
||||
err = cv.DoInto(context.Background(), resp, in, &buf, opts)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
// validate result
|
||||
var act example3.ExampleResp
|
||||
err = json.Unmarshal(buf, &act)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
spew.Dump(act)
|
||||
|
||||
spew.Dump(resp)
|
||||
}
|
||||
```
|
||||
|
||||
</p>
|
||||
</details>
|
||||
|
||||
|
||||
|
||||
Generated by [gomarkdoc](<https://github.com/princjef/gomarkdoc>)
|
5
go.mod
5
go.mod
|
@ -4,8 +4,8 @@ go 1.17
|
|||
|
||||
require (
|
||||
github.com/apache/thrift v0.13.0
|
||||
github.com/bytedance/sonic v1.11.8
|
||||
github.com/bytedance/sonic/loader v0.1.1
|
||||
github.com/bytedance/sonic v1.12.0
|
||||
github.com/bytedance/sonic/loader v0.2.0
|
||||
github.com/cloudwego/base64x v0.1.4
|
||||
github.com/cloudwego/fastpb v0.0.4
|
||||
github.com/cloudwego/thriftgo v0.3.6
|
||||
|
@ -25,6 +25,7 @@ require (
|
|||
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
|
||||
golang.org/x/arch v0.0.0-20210923205945-b76863e36670 // indirect
|
||||
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f // indirect
|
||||
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect
|
||||
google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013 // indirect
|
||||
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||
)
|
||||
|
|
19
go.sum
19
go.sum
|
@ -2,10 +2,11 @@ cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMT
|
|||
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
|
||||
github.com/apache/thrift v0.13.0 h1:5hryIiq9gtn+MiLVn0wP37kb/uTeRZgN08WoCsAhIhI=
|
||||
github.com/apache/thrift v0.13.0/go.mod h1:cp2SuWMxlEZw2r+iP2GNCdIi4C1qmUzdZFSVb+bacwQ=
|
||||
github.com/bytedance/sonic v1.11.8 h1:Zw/j1KfiS+OYTi9lyB3bb0CFxPJVkM17k1wyDG32LRA=
|
||||
github.com/bytedance/sonic v1.11.8/go.mod h1:LysEHSvpvDySVdC2f87zGWf6CIKJcAvqab1ZaiQtds4=
|
||||
github.com/bytedance/sonic/loader v0.1.1 h1:c+e5Pt1k/cy5wMveRDyk2X4B9hF4g7an8N3zCYjJFNM=
|
||||
github.com/bytedance/sonic v1.12.0 h1:YGPgxF9xzaCNvd/ZKdQ28yRovhfMFZQjuk6fKBzZ3ls=
|
||||
github.com/bytedance/sonic v1.12.0/go.mod h1:B8Gt/XvtZ3Fqj+iSKMypzymZxw/FVwgIGKzMzT9r/rk=
|
||||
github.com/bytedance/sonic/loader v0.1.1/go.mod h1:ncP89zfokxS5LZrJxl5z0UJcsk4M4yY2JpfqGeCtNLU=
|
||||
github.com/bytedance/sonic/loader v0.2.0 h1:zNprn+lsIP06C/IqCHs3gPQIvnvpKbbxyXQP1iU4kWM=
|
||||
github.com/bytedance/sonic/loader v0.2.0/go.mod h1:ncP89zfokxS5LZrJxl5z0UJcsk4M4yY2JpfqGeCtNLU=
|
||||
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
|
||||
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
|
||||
github.com/cloudwego/base64x v0.1.4 h1:jwCgWpFanWmN8xoIUHa2rtzmkd5J2plF/dnLS6Xd/0Y=
|
||||
|
@ -25,6 +26,7 @@ github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.m
|
|||
github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
|
||||
github.com/fatih/structtag v1.2.0 h1:/OdNE99OxoI/PqaW/SuSK9uxxT3f/tcSZgon/ssNSx4=
|
||||
github.com/fatih/structtag v1.2.0/go.mod h1:mBJUNpUnHmRKrKlQQlmCrh5PuhftFbNv8Ys4/aAZl94=
|
||||
github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q=
|
||||
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
|
||||
github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A=
|
||||
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
|
||||
|
@ -51,6 +53,7 @@ github.com/iancoleman/strcase v0.2.0 h1:05I4QRnGpI0m37iZQRuskXh+w77mr6Z41lwQzuHL
|
|||
github.com/iancoleman/strcase v0.2.0/go.mod h1:iwCmte+B7n89clKwxIoIXy/HfoL7AsD47ZCWhYzw7ho=
|
||||
github.com/jhump/protoreflect v1.8.2 h1:k2xE7wcUomeqwY0LDCYA16y4WWfyTcMx5mKhk0d4ua0=
|
||||
github.com/jhump/protoreflect v1.8.2/go.mod h1:7GcYQDdMU/O/BBrl/cX6PNHpXh6cenjd8pneu5yW7Tg=
|
||||
github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8=
|
||||
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
|
||||
github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg=
|
||||
github.com/klauspost/cpuid/v2 v2.2.4 h1:acbojRNwl3o09bUq+yDCtZFc1aiwaAAxtcn8YkZXnvk=
|
||||
|
@ -79,6 +82,7 @@ github.com/twitchyliquid64/golang-asm v0.15.1 h1:SU5vSMR7hnwNxj24w34ZyCi/FmDZTkS
|
|||
github.com/twitchyliquid64/golang-asm v0.15.1/go.mod h1:a1lVb/DtPvCB8fslRZhAngC2+aY1QWCk3Cedj/Gdt08=
|
||||
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
|
||||
github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
|
||||
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
|
||||
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
|
||||
golang.org/x/arch v0.0.0-20210923205945-b76863e36670 h1:18EFjUmQOcUvxNYSkA6jO9VAiXCnxFY6NyDX0bHDmkU=
|
||||
golang.org/x/arch v0.0.0-20210923205945-b76863e36670/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8=
|
||||
|
@ -103,6 +107,7 @@ golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn
|
|||
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||
golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||
golang.org/x/net v0.0.0-20200625001655-4c5254603344/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA=
|
||||
golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
|
||||
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
|
||||
golang.org/x/net v0.0.0-20220722155237-a158d28d115b h1:PxfKdU9lEEDYjdIzOtC4qFWgkU2rGHdKlKowJSMN9h0=
|
||||
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
|
||||
|
@ -112,11 +117,13 @@ golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJ
|
|||
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20200625203802-6e8e738ad208/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
|
@ -138,12 +145,15 @@ golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBn
|
|||
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
||||
golang.org/x/tools v0.0.0-20191130070609-6e064ea0cf2d/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
||||
golang.org/x/tools v0.0.0-20200522201501-cb1345f3a375/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE=
|
||||
golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE=
|
||||
golang.org/x/tools v0.0.0-20200717024301-6ddee64345a6/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA=
|
||||
golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
|
||||
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
|
||||
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
|
||||
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE=
|
||||
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM=
|
||||
google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
|
||||
google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc=
|
||||
|
@ -164,6 +174,7 @@ google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2
|
|||
google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
|
||||
google.golang.org/protobuf v1.25.1-0.20200805231151-a709e31e5d12/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c=
|
||||
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
|
||||
google.golang.org/protobuf v1.28.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
|
||||
google.golang.org/protobuf v1.28.1 h1:d0NfwRgPtno5B1Wa6L2DAG+KivqkdutMf1UhdNx175w=
|
||||
google.golang.org/protobuf v1.28.1/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
|
|
352
http/README.md
352
http/README.md
|
@ -1,352 +0,0 @@
|
|||
<!-- Code generated by gomarkdoc. DO NOT EDIT -->
|
||||
|
||||
# http
|
||||
|
||||
```go
|
||||
import "github.com/cloudwego/dynamicgo/http"
|
||||
```
|
||||
|
||||
## Index
|
||||
|
||||
- [Constants](<#constants>)
|
||||
- [Variables](<#variables>)
|
||||
- [func AnnoToMethod(annoKey string) string](<#func-annotomethod>)
|
||||
- [type Endpoint](<#type-endpoint>)
|
||||
- [type HTTPRequest](<#type-httprequest>)
|
||||
- [func NewHTTPRequest() *HTTPRequest](<#func-newhttprequest>)
|
||||
- [func NewHTTPRequestFromStdReq(req *http.Request, params ...Param) (ret *HTTPRequest, err error)](<#func-newhttprequestfromstdreq>)
|
||||
- [func NewHTTPRequestFromUrl(method, url string, body io.Reader, params ...Param) (*HTTPRequest, error)](<#func-newhttprequestfromurl>)
|
||||
- [func (self HTTPRequest) Body() []byte](<#func-httprequest-body>)
|
||||
- [func (self HTTPRequest) Cookie(key string) string](<#func-httprequest-cookie>)
|
||||
- [func (self HTTPRequest) Header(key string) string](<#func-httprequest-header>)
|
||||
- [func (self HTTPRequest) Host() string](<#func-httprequest-host>)
|
||||
- [func (self *HTTPRequest) MapBody(key string) string](<#func-httprequest-mapbody>)
|
||||
- [func (self HTTPRequest) Method() string](<#func-httprequest-method>)
|
||||
- [func (self HTTPRequest) Param(key string) string](<#func-httprequest-param>)
|
||||
- [func (self HTTPRequest) Path() string](<#func-httprequest-path>)
|
||||
- [func (self HTTPRequest) PostForm(key string) string](<#func-httprequest-postform>)
|
||||
- [func (self HTTPRequest) Query(key string) string](<#func-httprequest-query>)
|
||||
- [func (self HTTPRequest) Uri() string](<#func-httprequest-uri>)
|
||||
- [type HTTPResponse](<#type-httpresponse>)
|
||||
- [func NewHTTPResponse() *HTTPResponse](<#func-newhttpresponse>)
|
||||
- [func (self HTTPResponse) SetCookie(key string, val string) error](<#func-httpresponse-setcookie>)
|
||||
- [func (self HTTPResponse) SetHeader(key string, val string) error](<#func-httpresponse-setheader>)
|
||||
- [func (self HTTPResponse) SetRawBody(body []byte) error](<#func-httpresponse-setrawbody>)
|
||||
- [func (self HTTPResponse) SetStatusCode(code int) error](<#func-httpresponse-setstatuscode>)
|
||||
- [type Param](<#type-param>)
|
||||
- [type Params](<#type-params>)
|
||||
- [func (ps *Params) ByName(name string) string](<#func-params-byname>)
|
||||
- [func (ps *Params) Recycle()](<#func-params-recycle>)
|
||||
- [func (ps *Params) Set(name string, val string) bool](<#func-params-set>)
|
||||
- [type RequestGetter](<#type-requestgetter>)
|
||||
- [type ResponseSetter](<#type-responsesetter>)
|
||||
|
||||
|
||||
## Constants
|
||||
|
||||
```go
|
||||
const (
|
||||
// HeaderContentType is the key of Content-Type header
|
||||
HeaderContentType = "Content-Type"
|
||||
// HeaderSetCookie is the key of Set-Cookie header
|
||||
HeaderSetCookie = "Set-Cookie"
|
||||
)
|
||||
```
|
||||
|
||||
## Variables
|
||||
|
||||
```go
|
||||
var (
|
||||
// DefaultJsonPairSize is the default size of json.Pair slice.
|
||||
DefaultJsonPairSize = 16
|
||||
)
|
||||
```
|
||||
|
||||
## func AnnoToMethod
|
||||
|
||||
```go
|
||||
func AnnoToMethod(annoKey string) string
|
||||
```
|
||||
|
||||
AnnoToMethod maps annotation to corresponding http method
|
||||
|
||||
## type Endpoint
|
||||
|
||||
Endpoint a http endpoint.
|
||||
|
||||
```go
|
||||
type Endpoint struct {
|
||||
Method, Path string
|
||||
}
|
||||
```
|
||||
|
||||
## type HTTPRequest
|
||||
|
||||
Request is a implementation of RequestGetter. It wraps http.Request.
|
||||
|
||||
```go
|
||||
type HTTPRequest struct {
|
||||
*http.Request
|
||||
|
||||
Params Params
|
||||
BodyMap interface{}
|
||||
// contains filtered or unexported fields
|
||||
}
|
||||
```
|
||||
|
||||
### func NewHTTPRequest
|
||||
|
||||
```go
|
||||
func NewHTTPRequest() *HTTPRequest
|
||||
```
|
||||
|
||||
NewHTTPRequest creates a new HTTPRequest.
|
||||
|
||||
### func NewHTTPRequestFromStdReq
|
||||
|
||||
```go
|
||||
func NewHTTPRequestFromStdReq(req *http.Request, params ...Param) (ret *HTTPRequest, err error)
|
||||
```
|
||||
|
||||
NewHTTPRequestFromStdReq creates a new HTTPRequest from http.Request. It will check the content\-type of the request and parse the body if the type one of following: \- application/json \- application/x\-www\-form\-urlencoded
|
||||
|
||||
### func NewHTTPRequestFromUrl
|
||||
|
||||
```go
|
||||
func NewHTTPRequestFromUrl(method, url string, body io.Reader, params ...Param) (*HTTPRequest, error)
|
||||
```
|
||||
|
||||
NewHTTPRequestFromUrl creates a new HTTPRequest from url, body and url\-path param.
|
||||
|
||||
### func \(HTTPRequest\) Body
|
||||
|
||||
```go
|
||||
func (self HTTPRequest) Body() []byte
|
||||
```
|
||||
|
||||
Body implements RequestGetter.Body.
|
||||
|
||||
### func \(HTTPRequest\) Cookie
|
||||
|
||||
```go
|
||||
func (self HTTPRequest) Cookie(key string) string
|
||||
```
|
||||
|
||||
Cookie implements RequestGetter.Cookie.
|
||||
|
||||
### func \(HTTPRequest\) Header
|
||||
|
||||
```go
|
||||
func (self HTTPRequest) Header(key string) string
|
||||
```
|
||||
|
||||
Header implements RequestGetter.Header.
|
||||
|
||||
### func \(HTTPRequest\) Host
|
||||
|
||||
```go
|
||||
func (self HTTPRequest) Host() string
|
||||
```
|
||||
|
||||
Host implements RequestGetter.Host.
|
||||
|
||||
### func \(\*HTTPRequest\) MapBody
|
||||
|
||||
```go
|
||||
func (self *HTTPRequest) MapBody(key string) string
|
||||
```
|
||||
|
||||
MapBody implements RequestGetter.MapBody.
|
||||
|
||||
### func \(HTTPRequest\) Method
|
||||
|
||||
```go
|
||||
func (self HTTPRequest) Method() string
|
||||
```
|
||||
|
||||
Method implements RequestGetter.Method.
|
||||
|
||||
### func \(HTTPRequest\) Param
|
||||
|
||||
```go
|
||||
func (self HTTPRequest) Param(key string) string
|
||||
```
|
||||
|
||||
Param implements RequestGetter.Param.
|
||||
|
||||
### func \(HTTPRequest\) Path
|
||||
|
||||
```go
|
||||
func (self HTTPRequest) Path() string
|
||||
```
|
||||
|
||||
Path implements RequestGetter.Path.
|
||||
|
||||
### func \(HTTPRequest\) PostForm
|
||||
|
||||
```go
|
||||
func (self HTTPRequest) PostForm(key string) string
|
||||
```
|
||||
|
||||
PostForm implements RequestGetter.PostForm.
|
||||
|
||||
### func \(HTTPRequest\) Query
|
||||
|
||||
```go
|
||||
func (self HTTPRequest) Query(key string) string
|
||||
```
|
||||
|
||||
Query implements RequestGetter.Query.
|
||||
|
||||
### func \(HTTPRequest\) Uri
|
||||
|
||||
```go
|
||||
func (self HTTPRequest) Uri() string
|
||||
```
|
||||
|
||||
Uri implements RequestGetter.Uri.
|
||||
|
||||
## type HTTPResponse
|
||||
|
||||
HTTPResponse is an implementation of ResponseSetter
|
||||
|
||||
```go
|
||||
type HTTPResponse struct {
|
||||
*http.Response
|
||||
}
|
||||
```
|
||||
|
||||
### func NewHTTPResponse
|
||||
|
||||
```go
|
||||
func NewHTTPResponse() *HTTPResponse
|
||||
```
|
||||
|
||||
NewHTTPResponse creates a new HTTPResponse
|
||||
|
||||
### func \(HTTPResponse\) SetCookie
|
||||
|
||||
```go
|
||||
func (self HTTPResponse) SetCookie(key string, val string) error
|
||||
```
|
||||
|
||||
SetCookie implements ResponseSetter.SetCookie
|
||||
|
||||
### func \(HTTPResponse\) SetHeader
|
||||
|
||||
```go
|
||||
func (self HTTPResponse) SetHeader(key string, val string) error
|
||||
```
|
||||
|
||||
SetHeader implements ResponseSetter.SetHeader
|
||||
|
||||
### func \(HTTPResponse\) SetRawBody
|
||||
|
||||
```go
|
||||
func (self HTTPResponse) SetRawBody(body []byte) error
|
||||
```
|
||||
|
||||
### func \(HTTPResponse\) SetStatusCode
|
||||
|
||||
```go
|
||||
func (self HTTPResponse) SetStatusCode(code int) error
|
||||
```
|
||||
|
||||
SetStatusCode implements ResponseSetter.SetStatusCode
|
||||
|
||||
## type Param
|
||||
|
||||
### Param in url path
|
||||
|
||||
e.g. /user/:id \+ /user/123 =\> Param\{Key: "id", Value: "123"\}
|
||||
|
||||
```go
|
||||
type Param struct {
|
||||
Key string
|
||||
Value string
|
||||
}
|
||||
```
|
||||
|
||||
## type Params
|
||||
|
||||
Http url\-path params
|
||||
|
||||
```go
|
||||
type Params struct {
|
||||
// contains filtered or unexported fields
|
||||
}
|
||||
```
|
||||
|
||||
### func \(\*Params\) ByName
|
||||
|
||||
```go
|
||||
func (ps *Params) ByName(name string) string
|
||||
```
|
||||
|
||||
ByName search Param by given name
|
||||
|
||||
### func \(\*Params\) Recycle
|
||||
|
||||
```go
|
||||
func (ps *Params) Recycle()
|
||||
```
|
||||
|
||||
Recycle the Params
|
||||
|
||||
### func \(\*Params\) Set
|
||||
|
||||
```go
|
||||
func (ps *Params) Set(name string, val string) bool
|
||||
```
|
||||
|
||||
Set set Param by given name and value, return true if Param exists
|
||||
|
||||
## type RequestGetter
|
||||
|
||||
RequestGetter is a interface for getting request parameters
|
||||
|
||||
```go
|
||||
type RequestGetter interface {
|
||||
// Method returns the http method.
|
||||
Method() string
|
||||
// Host returns the host.
|
||||
Host() string
|
||||
// Uri returns entire uri.
|
||||
Uri() string
|
||||
// Header returns the value of the header with the given key.
|
||||
Header(string) string
|
||||
// Cookie returns the value of the cookie with the given key.
|
||||
Cookie(string) string
|
||||
// Query returns the value of the query with the given key.
|
||||
Query(string) string
|
||||
// Param returns the value of the url-path param with the given key.
|
||||
Param(string) string
|
||||
// PostForm returns the value of the post-form body with the given key.
|
||||
PostForm(string) string
|
||||
// MapBody returns the value of body with the given key.
|
||||
MapBody(string) string
|
||||
// Body returns the raw body in bytes.
|
||||
Body() []byte
|
||||
}
|
||||
```
|
||||
|
||||
## type ResponseSetter
|
||||
|
||||
ResponseSetter is a interface for setting response parameters
|
||||
|
||||
```go
|
||||
type ResponseSetter interface {
|
||||
// SetStatusCode sets the status code of the response
|
||||
SetStatusCode(int) error
|
||||
// SetHeader sets the header of the response
|
||||
SetHeader(string, string) error
|
||||
// SetCookie sets the cookie of the response
|
||||
SetCookie(string, string) error
|
||||
// SetRawBody sets the raw body of the response
|
||||
SetRawBody([]byte) error
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
|
||||
Generated by [gomarkdoc](<https://github.com/princjef/gomarkdoc>)
|
|
@ -18,6 +18,7 @@ package http
|
|||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
|
@ -91,6 +92,13 @@ type HTTPRequest struct {
|
|||
BodyMap interface{}
|
||||
}
|
||||
|
||||
func (h *HTTPRequest) String() string {
|
||||
return fmt.Sprintf(`URL: %s
|
||||
Headers: %v
|
||||
Body: %s
|
||||
BodyMap: %v`, h.URL.String(), h.Header, string(h.rawBody), h.BodyMap)
|
||||
}
|
||||
|
||||
// NewHTTPRequest creates a new HTTPRequest.
|
||||
func NewHTTPRequest() *HTTPRequest {
|
||||
return &HTTPRequest{}
|
||||
|
|
|
@ -22,25 +22,19 @@ import (
|
|||
"strconv"
|
||||
"unicode/utf8"
|
||||
_ "unsafe"
|
||||
|
||||
"github.com/cloudwego/dynamicgo/internal/rt"
|
||||
)
|
||||
|
||||
func NoQuote(buf *[]byte, val string) {
|
||||
quoteString(buf, val)
|
||||
}
|
||||
|
||||
var (
|
||||
//go:linkname safeSet encoding/json.safeSet
|
||||
safeSet [utf8.RuneSelf]bool
|
||||
|
||||
//go:linkname hex encoding/json.hex
|
||||
hex string
|
||||
)
|
||||
|
||||
func quoteString(e *[]byte, s string) {
|
||||
start := 0
|
||||
for i := 0; i < len(s); {
|
||||
if b := s[i]; b < utf8.RuneSelf {
|
||||
if safeSet[b] {
|
||||
if rt.SafeSet[b] {
|
||||
i++
|
||||
continue
|
||||
}
|
||||
|
@ -64,8 +58,8 @@ func quoteString(e *[]byte, s string) {
|
|||
// user-controlled strings are rendered into JSON
|
||||
// and served to some browsers.
|
||||
*e = append(*e, `u00`...)
|
||||
*e = append(*e, hex[b>>4])
|
||||
*e = append(*e, hex[b&0xF])
|
||||
*e = append(*e, rt.Hex[b>>4])
|
||||
*e = append(*e, rt.Hex[b&0xF])
|
||||
}
|
||||
i++
|
||||
start = i
|
||||
|
@ -86,7 +80,7 @@ func quoteString(e *[]byte, s string) {
|
|||
*e = append(*e, s[start:i]...)
|
||||
}
|
||||
*e = append(*e, `\u202`...)
|
||||
*e = append(*e, hex[c&0xF])
|
||||
*e = append(*e, rt.Hex[c&0xF])
|
||||
i += size
|
||||
start = i
|
||||
continue
|
||||
|
|
|
@ -20,7 +20,6 @@ import (
|
|||
"fmt"
|
||||
"sync"
|
||||
"unsafe"
|
||||
|
||||
)
|
||||
|
||||
const (
|
||||
|
@ -174,6 +173,10 @@ type JsonState struct {
|
|||
Dcap int
|
||||
}
|
||||
|
||||
func (s JsonState) String() string {
|
||||
return fmt.Sprintf(`{Vt: %d, Dv: %f, Iv: %d, Ep: %d}`, s.Vt, s.Dv, s.Iv, s.Ep)
|
||||
}
|
||||
|
||||
type StateMachine struct {
|
||||
Sp int
|
||||
Vt [MAX_RECURSE]int64
|
||||
|
@ -204,6 +207,27 @@ type J2TState struct {
|
|||
Extra J2TExtra
|
||||
}
|
||||
|
||||
//go:nocheckptr
|
||||
func (s J2TState) String() string {
|
||||
name := ""
|
||||
typ := 0
|
||||
if s.TypeDesc != 0 {
|
||||
desc := (*tTypeDesc)(unsafe.Pointer(s.TypeDesc))
|
||||
name = desc.name
|
||||
typ = int(desc.ttype)
|
||||
}
|
||||
return fmt.Sprintf("{State: %x, JsonPos: %d, TypeDesc: %s(%d), Extra:%v}", s.State, s.JsonPos, name, typ, s.Extra)
|
||||
}
|
||||
|
||||
type tTypeDesc struct
|
||||
{
|
||||
ttype uint8;
|
||||
name string;
|
||||
key *tTypeDesc;
|
||||
elem *tTypeDesc;
|
||||
st unsafe.Pointer;
|
||||
};
|
||||
|
||||
func (self *J2TState) TdPointer() uintptr {
|
||||
return uintptr(self.TypeDesc)
|
||||
}
|
||||
|
@ -255,6 +279,31 @@ type J2TStateMachine struct {
|
|||
FieldValueCache FieldValue
|
||||
}
|
||||
|
||||
func (fsm *J2TStateMachine) String() string {
|
||||
var vt1 *J2TState
|
||||
if fsm.SP > 0 {
|
||||
vt1 = &fsm.VT[fsm.SP-1]
|
||||
}
|
||||
var vt2 *J2TState
|
||||
if fsm.SP > 1 {
|
||||
vt2 = &fsm.VT[fsm.SP-2]
|
||||
}
|
||||
var svt int64
|
||||
if fsm.SM.Sp > 0 {
|
||||
svt = fsm.SM.Vt[fsm.SM.Sp-1]
|
||||
}
|
||||
return fmt.Sprintf(`SP: %d
|
||||
JsonState: %v
|
||||
VT[SP-1]: %v
|
||||
VT[SP-2]: %v
|
||||
SM.SP: %d
|
||||
SM.VT[SP-1]: %x
|
||||
ReqsCache: %v
|
||||
KeyCache: %s
|
||||
FieldCache: %v
|
||||
FieldValue: %#v`, fsm.SP, fsm.JT, vt1, vt2, fsm.SM.Sp, svt, fsm.ReqsCache, fsm.KeyCache, fsm.FieldCache, fsm.FieldValueCache)
|
||||
}
|
||||
|
||||
type FieldValue struct {
|
||||
FieldID int32
|
||||
ValBegin uint32
|
||||
|
|
|
@ -0,0 +1,118 @@
|
|||
// Copyright 2024 CloudWeGo Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package rt
|
||||
|
||||
import "unicode/utf8"
|
||||
|
||||
var SafeSet = [utf8.RuneSelf]bool{
|
||||
' ': true,
|
||||
'!': true,
|
||||
'"': false,
|
||||
'#': true,
|
||||
'$': true,
|
||||
'%': true,
|
||||
'&': true,
|
||||
'\'': true,
|
||||
'(': true,
|
||||
')': true,
|
||||
'*': true,
|
||||
'+': true,
|
||||
',': true,
|
||||
'-': true,
|
||||
'.': true,
|
||||
'/': true,
|
||||
'0': true,
|
||||
'1': true,
|
||||
'2': true,
|
||||
'3': true,
|
||||
'4': true,
|
||||
'5': true,
|
||||
'6': true,
|
||||
'7': true,
|
||||
'8': true,
|
||||
'9': true,
|
||||
':': true,
|
||||
';': true,
|
||||
'<': true,
|
||||
'=': true,
|
||||
'>': true,
|
||||
'?': true,
|
||||
'@': true,
|
||||
'A': true,
|
||||
'B': true,
|
||||
'C': true,
|
||||
'D': true,
|
||||
'E': true,
|
||||
'F': true,
|
||||
'G': true,
|
||||
'H': true,
|
||||
'I': true,
|
||||
'J': true,
|
||||
'K': true,
|
||||
'L': true,
|
||||
'M': true,
|
||||
'N': true,
|
||||
'O': true,
|
||||
'P': true,
|
||||
'Q': true,
|
||||
'R': true,
|
||||
'S': true,
|
||||
'T': true,
|
||||
'U': true,
|
||||
'V': true,
|
||||
'W': true,
|
||||
'X': true,
|
||||
'Y': true,
|
||||
'Z': true,
|
||||
'[': true,
|
||||
'\\': false,
|
||||
']': true,
|
||||
'^': true,
|
||||
'_': true,
|
||||
'`': true,
|
||||
'a': true,
|
||||
'b': true,
|
||||
'c': true,
|
||||
'd': true,
|
||||
'e': true,
|
||||
'f': true,
|
||||
'g': true,
|
||||
'h': true,
|
||||
'i': true,
|
||||
'j': true,
|
||||
'k': true,
|
||||
'l': true,
|
||||
'm': true,
|
||||
'n': true,
|
||||
'o': true,
|
||||
'p': true,
|
||||
'q': true,
|
||||
'r': true,
|
||||
's': true,
|
||||
't': true,
|
||||
'u': true,
|
||||
'v': true,
|
||||
'w': true,
|
||||
'x': true,
|
||||
'y': true,
|
||||
'z': true,
|
||||
'{': true,
|
||||
'|': true,
|
||||
'}': true,
|
||||
'~': true,
|
||||
'\u007f': true,
|
||||
}
|
||||
|
||||
var Hex = "0123456789abcdef"
|
893
proto/README.md
893
proto/README.md
|
@ -1,893 +0,0 @@
|
|||
<!-- Code generated by gomarkdoc. DO NOT EDIT -->
|
||||
|
||||
# proto
|
||||
|
||||
```go
|
||||
import "github.com/cloudwego/dynamicgo/proto"
|
||||
```
|
||||
|
||||
## Index
|
||||
|
||||
- [proto](#proto)
|
||||
- [Index](#index)
|
||||
- [Variables](#variables)
|
||||
- [type EnumNumber](#type-enumnumber)
|
||||
- [type FieldDescriptor](#type-fielddescriptor)
|
||||
- [func (\*FieldDescriptor) IsList](#func-fielddescriptor-islist)
|
||||
- [func (\*FieldDescriptor) IsMap](#func-fielddescriptor-ismap)
|
||||
- [func (\*FieldDescriptor) JSONName](#func-fielddescriptor-jsonname)
|
||||
- [func (\*FieldDescriptor) Kind](#func-fielddescriptor-kind)
|
||||
- [func (\*FieldDescriptor) MapKey](#func-fielddescriptor-mapkey)
|
||||
- [func (\*FieldDescriptor) MapValue](#func-fielddescriptor-mapvalue)
|
||||
- [func (\*FieldDescriptor) Message](#func-fielddescriptor-message)
|
||||
- [func (\*FieldDescriptor) Name](#func-fielddescriptor-name)
|
||||
- [func (\*FieldDescriptor) Number](#func-fielddescriptor-number)
|
||||
- [func (\*FieldDescriptor) Type](#func-fielddescriptor-type)
|
||||
- [type FieldNameMap](#type-fieldnamemap)
|
||||
- [func (FieldNameMap) All](#func-fieldnamemap-all)
|
||||
- [func (\*FieldNameMap) Build](#func-fieldnamemap-build)
|
||||
- [func (FieldNameMap) Get](#func-fieldnamemap-get)
|
||||
- [func (\*FieldNameMap) Set](#func-fieldnamemap-set)
|
||||
- [func (FieldNameMap) Size](#func-fieldnamemap-size)
|
||||
- [type FieldNumber](#type-fieldnumber)
|
||||
- [type FieldNumberMap](#type-fieldnumbermap)
|
||||
- [func (FieldNumberMap) All](#func-fieldnumbermap-all)
|
||||
- [func (FieldNumberMap) Get](#func-fieldnumbermap-get)
|
||||
- [func (\*FieldNumberMap) Set](#func-fieldnumbermap-set)
|
||||
- [func (FieldNumberMap) Size](#func-fieldnumbermap-size)
|
||||
- [type MessageDescriptor](#type-messagedescriptor)
|
||||
- [func (\*MessageDescriptor) ByJSONName](#func-messagedescriptor-byjsonname)
|
||||
- [func (\*MessageDescriptor) ByName](#func-messagedescriptor-byname)
|
||||
- [func (\*MessageDescriptor) ByNumber](#func-messagedescriptor-bynumber)
|
||||
- [func (\*MessageDescriptor) FieldsCount](#func-messagedescriptor-fieldscount)
|
||||
- [func (\*MessageDescriptor) Name](#func-messagedescriptor-name)
|
||||
- [type MethodDescriptor](#type-methoddescriptor)
|
||||
- [func GetFnDescFromFile](#func-getfndescfromfile)
|
||||
- [func (\*MethodDescriptor) Input](#func-methoddescriptor-input)
|
||||
- [func (\*MethodDescriptor) Name](#func-methoddescriptor-name)
|
||||
- [func (\*MethodDescriptor) Output](#func-methoddescriptor-output)
|
||||
- [type Number](#type-number)
|
||||
- [type Options](#type-options)
|
||||
- [func NewDefaultOptions](#func-newdefaultoptions)
|
||||
- [func (Options) NewDesccriptorFromContent](#func-options-newdesccriptorfromcontent)
|
||||
- [func (Options) NewDescriptorFromPath](#func-options-newdescriptorfrompath)
|
||||
- [type ParseTarget](#type-parsetarget)
|
||||
- [type ProtoKind](#type-protokind)
|
||||
- [type ServiceDescriptor](#type-servicedescriptor)
|
||||
- [func NewDescritorFromContent](#func-newdescritorfromcontent)
|
||||
- [func NewDescritorFromPath](#func-newdescritorfrompath)
|
||||
- [func (\*ServiceDescriptor) LookupMethodByName](#func-servicedescriptor-lookupmethodbyname)
|
||||
- [func (\*ServiceDescriptor) Methods](#func-servicedescriptor-methods)
|
||||
- [func (\*ServiceDescriptor) Name](#func-servicedescriptor-name)
|
||||
- [type Type](#type-type)
|
||||
- [func FromProtoKindToType](#func-fromprotokindtotype)
|
||||
- [func (Type) IsComplex](#func-type-iscomplex)
|
||||
- [func (Type) IsInt](#func-type-isint)
|
||||
- [func (Type) IsPacked](#func-type-ispacked)
|
||||
- [func (Type) IsUint](#func-type-isuint)
|
||||
- [func (Type) NeedVarint](#func-type-needvarint)
|
||||
- [func (Type) String](#func-type-string)
|
||||
- [func (Type) TypeToKind](#func-type-typetokind)
|
||||
- [func (Type) Valid](#func-type-valid)
|
||||
- [type TypeDescriptor](#type-typedescriptor)
|
||||
- [func FnRequest](#func-fnrequest)
|
||||
- [func FnResponse](#func-fnresponse)
|
||||
- [func (\*TypeDescriptor) BaseId](#func-typedescriptor-baseid)
|
||||
- [func (\*TypeDescriptor) Elem](#func-typedescriptor-elem)
|
||||
- [func (\*TypeDescriptor) IsList](#func-typedescriptor-islist)
|
||||
- [func (\*TypeDescriptor) IsMap](#func-typedescriptor-ismap)
|
||||
- [func (\*TypeDescriptor) IsPacked](#func-typedescriptor-ispacked)
|
||||
- [func (\*TypeDescriptor) Key](#func-typedescriptor-key)
|
||||
- [func (\*TypeDescriptor) Message](#func-typedescriptor-message)
|
||||
- [func (\*TypeDescriptor) Name](#func-typedescriptor-name)
|
||||
- [func (\*TypeDescriptor) Type](#func-typedescriptor-type)
|
||||
- [func (\*TypeDescriptor) WireType](#func-typedescriptor-wiretype)
|
||||
- [type WireType](#type-wiretype)
|
||||
- [func (WireType) String](#func-wiretype-string)
|
||||
|
||||
|
||||
## Variables
|
||||
|
||||
<a name="Kind2Wire"></a>map from proto.ProtoKind to proto.WireType
|
||||
|
||||
```go
|
||||
var Kind2Wire = map[ProtoKind]WireType{
|
||||
BoolKind: VarintType,
|
||||
EnumKind: VarintType,
|
||||
Int32Kind: VarintType,
|
||||
Sint32Kind: VarintType,
|
||||
Uint32Kind: VarintType,
|
||||
Int64Kind: VarintType,
|
||||
Sint64Kind: VarintType,
|
||||
Uint64Kind: VarintType,
|
||||
Sfixed32Kind: Fixed32Type,
|
||||
Fixed32Kind: Fixed32Type,
|
||||
FloatKind: Fixed32Type,
|
||||
Sfixed64Kind: Fixed64Type,
|
||||
Fixed64Kind: Fixed64Type,
|
||||
DoubleKind: Fixed64Type,
|
||||
StringKind: BytesType,
|
||||
BytesKind: BytesType,
|
||||
MessageKind: BytesType,
|
||||
GroupKind: StartGroupType,
|
||||
}
|
||||
```
|
||||
|
||||
<a name="EnumNumber"></a>
|
||||
## type [EnumNumber](<https://github.com/khan-yin/dynamicgo/blob/main/proto/type.go#L225>)
|
||||
|
||||
|
||||
|
||||
```go
|
||||
type EnumNumber int32
|
||||
```
|
||||
|
||||
<a name="FieldDescriptor"></a>
|
||||
## type [FieldDescriptor](<https://github.com/khan-yin/dynamicgo/blob/main/proto/descriptor.go#L56-L62>)
|
||||
|
||||
|
||||
|
||||
```go
|
||||
type FieldDescriptor struct {
|
||||
// contains filtered or unexported fields
|
||||
}
|
||||
```
|
||||
|
||||
<a name="FieldDescriptor.IsList"></a>
|
||||
### func (*FieldDescriptor) [IsList](<https://github.com/khan-yin/dynamicgo/blob/main/proto/descriptor.go#L109>)
|
||||
|
||||
```go
|
||||
func (f *FieldDescriptor) IsList() bool
|
||||
```
|
||||
|
||||
|
||||
|
||||
<a name="FieldDescriptor.IsMap"></a>
|
||||
### func (*FieldDescriptor) [IsMap](<https://github.com/khan-yin/dynamicgo/blob/main/proto/descriptor.go#L105>)
|
||||
|
||||
```go
|
||||
func (f *FieldDescriptor) IsMap() bool
|
||||
```
|
||||
|
||||
|
||||
|
||||
<a name="FieldDescriptor.JSONName"></a>
|
||||
### func (*FieldDescriptor) [JSONName](<https://github.com/khan-yin/dynamicgo/blob/main/proto/descriptor.go#L76>)
|
||||
|
||||
```go
|
||||
func (f *FieldDescriptor) JSONName() string
|
||||
```
|
||||
|
||||
|
||||
|
||||
<a name="FieldDescriptor.Kind"></a>
|
||||
### func (*FieldDescriptor) [Kind](<https://github.com/khan-yin/dynamicgo/blob/main/proto/descriptor.go#L68>)
|
||||
|
||||
```go
|
||||
func (f *FieldDescriptor) Kind() ProtoKind
|
||||
```
|
||||
|
||||
|
||||
|
||||
<a name="FieldDescriptor.MapKey"></a>
|
||||
### func (*FieldDescriptor) [MapKey](<https://github.com/khan-yin/dynamicgo/blob/main/proto/descriptor.go#L91>)
|
||||
|
||||
```go
|
||||
func (f *FieldDescriptor) MapKey() *TypeDescriptor
|
||||
```
|
||||
|
||||
|
||||
|
||||
<a name="FieldDescriptor.MapValue"></a>
|
||||
### func (*FieldDescriptor) [MapValue](<https://github.com/khan-yin/dynamicgo/blob/main/proto/descriptor.go#L98>)
|
||||
|
||||
```go
|
||||
func (f *FieldDescriptor) MapValue() *TypeDescriptor
|
||||
```
|
||||
|
||||
|
||||
|
||||
<a name="FieldDescriptor.Message"></a>
|
||||
### func (*FieldDescriptor) [Message](<https://github.com/khan-yin/dynamicgo/blob/main/proto/descriptor.go#L87>)
|
||||
|
||||
```go
|
||||
func (f *FieldDescriptor) Message() *MessageDescriptor
|
||||
```
|
||||
|
||||
when List+Message it can get message element descriptor when Map it can get map key-value entry massage descriptor when Message it can get sub message descriptor
|
||||
|
||||
<a name="FieldDescriptor.Name"></a>
|
||||
### func (*FieldDescriptor) [Name](<https://github.com/khan-yin/dynamicgo/blob/main/proto/descriptor.go#L72>)
|
||||
|
||||
```go
|
||||
func (f *FieldDescriptor) Name() string
|
||||
```
|
||||
|
||||
|
||||
|
||||
<a name="FieldDescriptor.Number"></a>
|
||||
### func (*FieldDescriptor) [Number](<https://github.com/khan-yin/dynamicgo/blob/main/proto/descriptor.go#L64>)
|
||||
|
||||
```go
|
||||
func (f *FieldDescriptor) Number() FieldNumber
|
||||
```
|
||||
|
||||
|
||||
|
||||
<a name="FieldDescriptor.Type"></a>
|
||||
### func (*FieldDescriptor) [Type](<https://github.com/khan-yin/dynamicgo/blob/main/proto/descriptor.go#L80>)
|
||||
|
||||
```go
|
||||
func (f *FieldDescriptor) Type() *TypeDescriptor
|
||||
```
|
||||
|
||||
|
||||
|
||||
<a name="FieldNameMap"></a>
|
||||
## type [FieldNameMap](<https://github.com/khan-yin/dynamicgo/blob/main/proto/utils.go#L18-L23>)
|
||||
|
||||
FieldNameMap is a map for field name and field descriptor
|
||||
|
||||
```go
|
||||
type FieldNameMap struct {
|
||||
// contains filtered or unexported fields
|
||||
}
|
||||
```
|
||||
|
||||
<a name="FieldNameMap.All"></a>
|
||||
### func (FieldNameMap) [All](<https://github.com/khan-yin/dynamicgo/blob/main/proto/utils.go#L52>)
|
||||
|
||||
```go
|
||||
func (ft FieldNameMap) All() []*FieldDescriptor
|
||||
```
|
||||
|
||||
All returns all field descriptors
|
||||
|
||||
<a name="FieldNameMap.Build"></a>
|
||||
### func (*FieldNameMap) [Build](<https://github.com/khan-yin/dynamicgo/blob/main/proto/utils.go#L67>)
|
||||
|
||||
```go
|
||||
func (ft *FieldNameMap) Build()
|
||||
```
|
||||
|
||||
Build builds the map. It will try to build a trie tree if the dispersion of keys is higher enough (min).
|
||||
|
||||
<a name="FieldNameMap.Get"></a>
|
||||
### func (FieldNameMap) [Get](<https://github.com/khan-yin/dynamicgo/blob/main/proto/utils.go#L42>)
|
||||
|
||||
```go
|
||||
func (ft FieldNameMap) Get(k string) *FieldDescriptor
|
||||
```
|
||||
|
||||
Get gets the field descriptor for the given key
|
||||
|
||||
<a name="FieldNameMap.Set"></a>
|
||||
### func (*FieldNameMap) [Set](<https://github.com/khan-yin/dynamicgo/blob/main/proto/utils.go#L26>)
|
||||
|
||||
```go
|
||||
func (ft *FieldNameMap) Set(key string, field *FieldDescriptor) (exist bool)
|
||||
```
|
||||
|
||||
Set sets the field descriptor for the given key
|
||||
|
||||
<a name="FieldNameMap.Size"></a>
|
||||
### func (FieldNameMap) [Size](<https://github.com/khan-yin/dynamicgo/blob/main/proto/utils.go#L57>)
|
||||
|
||||
```go
|
||||
func (ft FieldNameMap) Size() int
|
||||
```
|
||||
|
||||
Size returns the size of the map
|
||||
|
||||
<a name="FieldNumber"></a>
|
||||
## type [FieldNumber](<https://github.com/khan-yin/dynamicgo/blob/main/proto/type.go#L224>)
|
||||
|
||||
|
||||
|
||||
```go
|
||||
type FieldNumber int32
|
||||
```
|
||||
|
||||
<a name="MinValidNumber"></a>reserved field number min-max ranges in a proto message
|
||||
|
||||
```go
|
||||
const (
|
||||
MinValidNumber FieldNumber = 1
|
||||
FirstReservedNumber FieldNumber = 19000
|
||||
LastReservedNumber FieldNumber = 19999
|
||||
MaxValidNumber FieldNumber = 1<<29 - 1
|
||||
DefaultRecursionLimit = 10000
|
||||
)
|
||||
```
|
||||
|
||||
<a name="FieldNumberMap"></a>
|
||||
## type [FieldNumberMap](<https://github.com/khan-yin/dynamicgo/blob/main/proto/utils.go#L149-L152>)
|
||||
|
||||
FieldIDMap is a map from field id to field descriptor
|
||||
|
||||
```go
|
||||
type FieldNumberMap struct {
|
||||
// contains filtered or unexported fields
|
||||
}
|
||||
```
|
||||
|
||||
<a name="FieldNumberMap.All"></a>
|
||||
### func (FieldNumberMap) [All](<https://github.com/khan-yin/dynamicgo/blob/main/proto/utils.go#L155>)
|
||||
|
||||
```go
|
||||
func (fd FieldNumberMap) All() (ret []*FieldDescriptor)
|
||||
```
|
||||
|
||||
All returns all field descriptors
|
||||
|
||||
<a name="FieldNumberMap.Get"></a>
|
||||
### func (FieldNumberMap) [Get](<https://github.com/khan-yin/dynamicgo/blob/main/proto/utils.go#L165>)
|
||||
|
||||
```go
|
||||
func (fd FieldNumberMap) Get(id FieldNumber) *FieldDescriptor
|
||||
```
|
||||
|
||||
Get gets the field descriptor for the given id
|
||||
|
||||
<a name="FieldNumberMap.Set"></a>
|
||||
### func (*FieldNumberMap) [Set](<https://github.com/khan-yin/dynamicgo/blob/main/proto/utils.go#L173>)
|
||||
|
||||
```go
|
||||
func (fd *FieldNumberMap) Set(id FieldNumber, f *FieldDescriptor)
|
||||
```
|
||||
|
||||
Set sets the field descriptor for the given id
|
||||
|
||||
<a name="FieldNumberMap.Size"></a>
|
||||
### func (FieldNumberMap) [Size](<https://github.com/khan-yin/dynamicgo/blob/main/proto/utils.go#L160>)
|
||||
|
||||
```go
|
||||
func (fd FieldNumberMap) Size() int
|
||||
```
|
||||
|
||||
Size returns the size of the map
|
||||
|
||||
<a name="MessageDescriptor"></a>
|
||||
## type [MessageDescriptor](<https://github.com/khan-yin/dynamicgo/blob/main/proto/descriptor.go#L113-L121>)
|
||||
|
||||
|
||||
|
||||
```go
|
||||
type MessageDescriptor struct {
|
||||
// contains filtered or unexported fields
|
||||
}
|
||||
```
|
||||
|
||||
<a name="MessageDescriptor.ByJSONName"></a>
|
||||
### func (*MessageDescriptor) [ByJSONName](<https://github.com/khan-yin/dynamicgo/blob/main/proto/descriptor.go#L127>)
|
||||
|
||||
```go
|
||||
func (m *MessageDescriptor) ByJSONName(name string) *FieldDescriptor
|
||||
```
|
||||
|
||||
|
||||
|
||||
<a name="MessageDescriptor.ByName"></a>
|
||||
### func (*MessageDescriptor) [ByName](<https://github.com/khan-yin/dynamicgo/blob/main/proto/descriptor.go#L131>)
|
||||
|
||||
```go
|
||||
func (m *MessageDescriptor) ByName(name string) *FieldDescriptor
|
||||
```
|
||||
|
||||
|
||||
|
||||
<a name="MessageDescriptor.ByNumber"></a>
|
||||
### func (*MessageDescriptor) [ByNumber](<https://github.com/khan-yin/dynamicgo/blob/main/proto/descriptor.go#L135>)
|
||||
|
||||
```go
|
||||
func (m *MessageDescriptor) ByNumber(id FieldNumber) *FieldDescriptor
|
||||
```
|
||||
|
||||
|
||||
|
||||
<a name="MessageDescriptor.FieldsCount"></a>
|
||||
### func (*MessageDescriptor) [FieldsCount](<https://github.com/khan-yin/dynamicgo/blob/main/proto/descriptor.go#L139>)
|
||||
|
||||
```go
|
||||
func (m *MessageDescriptor) FieldsCount() int
|
||||
```
|
||||
|
||||
|
||||
|
||||
<a name="MessageDescriptor.Name"></a>
|
||||
### func (*MessageDescriptor) [Name](<https://github.com/khan-yin/dynamicgo/blob/main/proto/descriptor.go#L123>)
|
||||
|
||||
```go
|
||||
func (m *MessageDescriptor) Name() string
|
||||
```
|
||||
|
||||
|
||||
|
||||
<a name="MethodDescriptor"></a>
|
||||
## type [MethodDescriptor](<https://github.com/khan-yin/dynamicgo/blob/main/proto/descriptor.go#L143-L147>)
|
||||
|
||||
|
||||
|
||||
```go
|
||||
type MethodDescriptor struct {
|
||||
// contains filtered or unexported fields
|
||||
}
|
||||
```
|
||||
|
||||
<a name="GetFnDescFromFile"></a>
|
||||
### func [GetFnDescFromFile](<https://github.com/khan-yin/dynamicgo/blob/main/proto/test_util.go#L12>)
|
||||
|
||||
```go
|
||||
func GetFnDescFromFile(filePath, fnName string, opts Options, includeDirs ...string) *MethodDescriptor
|
||||
```
|
||||
|
||||
GetFnDescFromFile get a fucntion descriptor from idl path (relative to your git root) and the function name
|
||||
|
||||
<a name="MethodDescriptor.Input"></a>
|
||||
### func (*MethodDescriptor) [Input](<https://github.com/khan-yin/dynamicgo/blob/main/proto/descriptor.go#L153>)
|
||||
|
||||
```go
|
||||
func (m *MethodDescriptor) Input() *TypeDescriptor
|
||||
```
|
||||
|
||||
|
||||
|
||||
<a name="MethodDescriptor.Name"></a>
|
||||
### func (*MethodDescriptor) [Name](<https://github.com/khan-yin/dynamicgo/blob/main/proto/descriptor.go#L149>)
|
||||
|
||||
```go
|
||||
func (m *MethodDescriptor) Name() string
|
||||
```
|
||||
|
||||
|
||||
|
||||
<a name="MethodDescriptor.Output"></a>
|
||||
### func (*MethodDescriptor) [Output](<https://github.com/khan-yin/dynamicgo/blob/main/proto/descriptor.go#L157>)
|
||||
|
||||
```go
|
||||
func (m *MethodDescriptor) Output() *TypeDescriptor
|
||||
```
|
||||
|
||||
|
||||
|
||||
<a name="Number"></a>
|
||||
## type [Number](<https://github.com/khan-yin/dynamicgo/blob/main/proto/type.go#L222>)
|
||||
|
||||
define Number = protowire.Number (int32)
|
||||
|
||||
```go
|
||||
type Number = protowire.Number
|
||||
```
|
||||
|
||||
<a name="Options"></a>
|
||||
## type [Options](<https://github.com/khan-yin/dynamicgo/blob/main/proto/idl.go#L31-L48>)
|
||||
|
||||
Options is options for parsing thrift IDL.
|
||||
|
||||
```go
|
||||
type Options struct {
|
||||
// ParseServiceMode indicates how to parse service.
|
||||
ParseServiceMode meta.ParseServiceMode
|
||||
|
||||
MapFieldWay meta.MapFieldWay // not implemented.
|
||||
|
||||
ParseFieldRandomRate float64 // not implemented.
|
||||
|
||||
ParseEnumAsInt64 bool // not implemented.
|
||||
|
||||
SetOptionalBitmap bool // not implemented.
|
||||
|
||||
UseDefaultValue bool // not implemented.
|
||||
|
||||
ParseFunctionMode meta.ParseFunctionMode // not implemented.
|
||||
|
||||
EnableProtoBase bool // not implemented.
|
||||
}
|
||||
```
|
||||
|
||||
<a name="NewDefaultOptions"></a>
|
||||
### func [NewDefaultOptions](<https://github.com/khan-yin/dynamicgo/blob/main/proto/idl.go#L51>)
|
||||
|
||||
```go
|
||||
func NewDefaultOptions() Options
|
||||
```
|
||||
|
||||
NewDefaultOptions creates a default Options.
|
||||
|
||||
<a name="Options.NewDesccriptorFromContent"></a>
|
||||
### func (Options) [NewDesccriptorFromContent](<https://github.com/khan-yin/dynamicgo/blob/main/proto/idl.go#L85>)
|
||||
|
||||
```go
|
||||
func (opts Options) NewDesccriptorFromContent(ctx context.Context, path, content string, includes map[string]string, importDirs ...string) (*ServiceDescriptor, error)
|
||||
```
|
||||
|
||||
|
||||
|
||||
<a name="Options.NewDescriptorFromPath"></a>
|
||||
### func (Options) [NewDescriptorFromPath](<https://github.com/khan-yin/dynamicgo/blob/main/proto/idl.go#L62>)
|
||||
|
||||
```go
|
||||
func (opts Options) NewDescriptorFromPath(ctx context.Context, path string, importDirs ...string) (*ServiceDescriptor, error)
|
||||
```
|
||||
|
||||
NewDescritorFromContent creates a ServiceDescriptor from a proto path and its imports, which uses the given options. The importDirs is used to find the include files.
|
||||
|
||||
<a name="ParseTarget"></a>
|
||||
## type [ParseTarget](<https://github.com/khan-yin/dynamicgo/blob/main/proto/idl.go#L28>)
|
||||
|
||||
ParseTarget indicates the target to parse
|
||||
|
||||
```go
|
||||
type ParseTarget uint8
|
||||
```
|
||||
|
||||
<a name="Request"></a>
|
||||
|
||||
```go
|
||||
const (
|
||||
Request ParseTarget = iota
|
||||
Response
|
||||
Exception
|
||||
)
|
||||
```
|
||||
|
||||
<a name="ProtoKind"></a>
|
||||
## type [ProtoKind](<https://github.com/khan-yin/dynamicgo/blob/main/proto/type.go#L41>)
|
||||
|
||||
define ProtoKind = protoreflect.Kind (int8)
|
||||
|
||||
```go
|
||||
type ProtoKind = protoreflect.Kind
|
||||
```
|
||||
|
||||
<a name="DoubleKind"></a>
|
||||
|
||||
```go
|
||||
const (
|
||||
DoubleKind ProtoKind = iota + 1
|
||||
FloatKind
|
||||
Int64Kind
|
||||
Uint64Kind
|
||||
Int32Kind
|
||||
Fixed64Kind
|
||||
Fixed32Kind
|
||||
BoolKind
|
||||
StringKind
|
||||
GroupKind
|
||||
MessageKind
|
||||
BytesKind
|
||||
Uint32Kind
|
||||
EnumKind
|
||||
Sfixed32Kind
|
||||
Sfixed64Kind
|
||||
Sint32Kind
|
||||
Sint64Kind
|
||||
)
|
||||
```
|
||||
|
||||
<a name="ServiceDescriptor"></a>
|
||||
## type [ServiceDescriptor](<https://github.com/khan-yin/dynamicgo/blob/main/proto/descriptor.go#L161-L164>)
|
||||
|
||||
|
||||
|
||||
```go
|
||||
type ServiceDescriptor struct {
|
||||
// contains filtered or unexported fields
|
||||
}
|
||||
```
|
||||
|
||||
<a name="NewDescritorFromContent"></a>
|
||||
### func [NewDescritorFromContent](<https://github.com/khan-yin/dynamicgo/blob/main/proto/idl.go#L81>)
|
||||
|
||||
```go
|
||||
func NewDescritorFromContent(ctx context.Context, path, content string, includes map[string]string, importDirs ...string) (*ServiceDescriptor, error)
|
||||
```
|
||||
|
||||
NewDescritorFromContent behaviors like NewDescritorFromPath, besides it uses DefaultOptions.
|
||||
|
||||
<a name="NewDescritorFromPath"></a>
|
||||
### func [NewDescritorFromPath](<https://github.com/khan-yin/dynamicgo/blob/main/proto/idl.go#L56>)
|
||||
|
||||
```go
|
||||
func NewDescritorFromPath(ctx context.Context, path string, importDirs ...string) (*ServiceDescriptor, error)
|
||||
```
|
||||
|
||||
NewDescritorFromPath behaviors like NewDescritorFromPath, besides it uses DefaultOptions.
|
||||
|
||||
<a name="ServiceDescriptor.LookupMethodByName"></a>
|
||||
### func (*ServiceDescriptor) [LookupMethodByName](<https://github.com/khan-yin/dynamicgo/blob/main/proto/descriptor.go#L174>)
|
||||
|
||||
```go
|
||||
func (s *ServiceDescriptor) LookupMethodByName(name string) *MethodDescriptor
|
||||
```
|
||||
|
||||
|
||||
|
||||
<a name="ServiceDescriptor.Methods"></a>
|
||||
### func (*ServiceDescriptor) [Methods](<https://github.com/khan-yin/dynamicgo/blob/main/proto/descriptor.go#L170>)
|
||||
|
||||
```go
|
||||
func (s *ServiceDescriptor) Methods() map[string]*MethodDescriptor
|
||||
```
|
||||
|
||||
|
||||
|
||||
<a name="ServiceDescriptor.Name"></a>
|
||||
### func (*ServiceDescriptor) [Name](<https://github.com/khan-yin/dynamicgo/blob/main/proto/descriptor.go#L166>)
|
||||
|
||||
```go
|
||||
func (s *ServiceDescriptor) Name() string
|
||||
```
|
||||
|
||||
|
||||
|
||||
<a name="Type"></a>
|
||||
## type [Type](<https://github.com/khan-yin/dynamicgo/blob/main/proto/type.go#L87>)
|
||||
|
||||
Node type (uint8) mapping ProtoKind the same value, except for UNKNOWN, LIST, MAP, ERROR
|
||||
|
||||
```go
|
||||
type Type uint8
|
||||
```
|
||||
|
||||
<a name="UNKNOWN"></a>
|
||||
|
||||
```go
|
||||
const (
|
||||
UNKNOWN Type = 0 // unknown field type
|
||||
DOUBLE Type = 1
|
||||
FLOAT Type = 2
|
||||
INT64 Type = 3
|
||||
UINT64 Type = 4
|
||||
INT32 Type = 5
|
||||
FIX64 Type = 6
|
||||
FIX32 Type = 7
|
||||
BOOL Type = 8
|
||||
STRING Type = 9
|
||||
GROUP Type = 10 // deprecated
|
||||
MESSAGE Type = 11
|
||||
BYTE Type = 12
|
||||
UINT32 Type = 13
|
||||
ENUM Type = 14
|
||||
SFIX32 Type = 15
|
||||
SFIX64 Type = 16
|
||||
SINT32 Type = 17
|
||||
SINT64 Type = 18
|
||||
LIST Type = 19
|
||||
MAP Type = 20
|
||||
ERROR Type = 255
|
||||
)
|
||||
```
|
||||
|
||||
<a name="FromProtoKindToType"></a>
|
||||
### func [FromProtoKindToType](<https://github.com/khan-yin/dynamicgo/blob/main/proto/type.go#L137>)
|
||||
|
||||
```go
|
||||
func FromProtoKindToType(kind ProtoKind, isList bool, isMap bool) Type
|
||||
```
|
||||
|
||||
FromProtoKindTType converts ProtoKind to Type
|
||||
|
||||
<a name="Type.IsComplex"></a>
|
||||
### func (Type) [IsComplex](<https://github.com/khan-yin/dynamicgo/blob/main/proto/type.go#L169>)
|
||||
|
||||
```go
|
||||
func (p Type) IsComplex() bool
|
||||
```
|
||||
|
||||
IsComplex tells if the type is one of STRUCT, MAP, SET, LIST
|
||||
|
||||
<a name="Type.IsInt"></a>
|
||||
### func (Type) [IsInt](<https://github.com/khan-yin/dynamicgo/blob/main/proto/type.go#L160>)
|
||||
|
||||
```go
|
||||
func (p Type) IsInt() bool
|
||||
```
|
||||
|
||||
IsInt containing isUint
|
||||
|
||||
<a name="Type.IsPacked"></a>
|
||||
### func (Type) [IsPacked](<https://github.com/khan-yin/dynamicgo/blob/main/proto/type.go#L152>)
|
||||
|
||||
```go
|
||||
func (p Type) IsPacked() bool
|
||||
```
|
||||
|
||||
|
||||
|
||||
<a name="Type.IsUint"></a>
|
||||
### func (Type) [IsUint](<https://github.com/khan-yin/dynamicgo/blob/main/proto/type.go#L164>)
|
||||
|
||||
```go
|
||||
func (p Type) IsUint() bool
|
||||
```
|
||||
|
||||
|
||||
|
||||
<a name="Type.NeedVarint"></a>
|
||||
### func (Type) [NeedVarint](<https://github.com/khan-yin/dynamicgo/blob/main/proto/type.go#L148>)
|
||||
|
||||
```go
|
||||
func (p Type) NeedVarint() bool
|
||||
```
|
||||
|
||||
check if the type need Varint encoding
|
||||
|
||||
<a name="Type.String"></a>
|
||||
### func (Type) [String](<https://github.com/khan-yin/dynamicgo/blob/main/proto/type.go#L174>)
|
||||
|
||||
```go
|
||||
func (p Type) String() string
|
||||
```
|
||||
|
||||
String for format and print
|
||||
|
||||
<a name="Type.TypeToKind"></a>
|
||||
### func (Type) [TypeToKind](<https://github.com/khan-yin/dynamicgo/blob/main/proto/type.go#L124>)
|
||||
|
||||
```go
|
||||
func (p Type) TypeToKind() ProtoKind
|
||||
```
|
||||
|
||||
|
||||
|
||||
<a name="Type.Valid"></a>
|
||||
### func (Type) [Valid](<https://github.com/khan-yin/dynamicgo/blob/main/proto/type.go#L114>)
|
||||
|
||||
```go
|
||||
func (p Type) Valid() bool
|
||||
```
|
||||
|
||||
|
||||
|
||||
<a name="TypeDescriptor"></a>
|
||||
## type [TypeDescriptor](<https://github.com/khan-yin/dynamicgo/blob/main/proto/descriptor.go#L3-L10>)
|
||||
|
||||
|
||||
|
||||
```go
|
||||
type TypeDescriptor struct {
|
||||
// contains filtered or unexported fields
|
||||
}
|
||||
```
|
||||
|
||||
<a name="FnRequest"></a>
|
||||
### func [FnRequest](<https://github.com/khan-yin/dynamicgo/blob/main/proto/test_util.go#L25>)
|
||||
|
||||
```go
|
||||
func FnRequest(fn *MethodDescriptor) *TypeDescriptor
|
||||
```
|
||||
|
||||
FnRequest get the normal requestDescriptor
|
||||
|
||||
<a name="FnResponse"></a>
|
||||
### func [FnResponse](<https://github.com/khan-yin/dynamicgo/blob/main/proto/test_util.go#L34>)
|
||||
|
||||
```go
|
||||
func FnResponse(fn *MethodDescriptor) *TypeDescriptor
|
||||
```
|
||||
|
||||
FnResponse get hte normal responseDescriptor
|
||||
|
||||
<a name="TypeDescriptor.BaseId"></a>
|
||||
### func (*TypeDescriptor) [BaseId](<https://github.com/khan-yin/dynamicgo/blob/main/proto/descriptor.go#L28>)
|
||||
|
||||
```go
|
||||
func (t *TypeDescriptor) BaseId() FieldNumber
|
||||
```
|
||||
|
||||
|
||||
|
||||
<a name="TypeDescriptor.Elem"></a>
|
||||
### func (*TypeDescriptor) [Elem](<https://github.com/khan-yin/dynamicgo/blob/main/proto/descriptor.go#L20>)
|
||||
|
||||
```go
|
||||
func (t *TypeDescriptor) Elem() *TypeDescriptor
|
||||
```
|
||||
|
||||
|
||||
|
||||
<a name="TypeDescriptor.IsList"></a>
|
||||
### func (*TypeDescriptor) [IsList](<https://github.com/khan-yin/dynamicgo/blob/main/proto/descriptor.go#L43>)
|
||||
|
||||
```go
|
||||
func (f *TypeDescriptor) IsList() bool
|
||||
```
|
||||
|
||||
|
||||
|
||||
<a name="TypeDescriptor.IsMap"></a>
|
||||
### func (*TypeDescriptor) [IsMap](<https://github.com/khan-yin/dynamicgo/blob/main/proto/descriptor.go#L39>)
|
||||
|
||||
```go
|
||||
func (f *TypeDescriptor) IsMap() bool
|
||||
```
|
||||
|
||||
|
||||
|
||||
<a name="TypeDescriptor.IsPacked"></a>
|
||||
### func (*TypeDescriptor) [IsPacked](<https://github.com/khan-yin/dynamicgo/blob/main/proto/descriptor.go#L32>)
|
||||
|
||||
```go
|
||||
func (t *TypeDescriptor) IsPacked() bool
|
||||
```
|
||||
|
||||
|
||||
|
||||
<a name="TypeDescriptor.Key"></a>
|
||||
### func (*TypeDescriptor) [Key](<https://github.com/khan-yin/dynamicgo/blob/main/proto/descriptor.go#L16>)
|
||||
|
||||
```go
|
||||
func (t *TypeDescriptor) Key() *TypeDescriptor
|
||||
```
|
||||
|
||||
|
||||
|
||||
<a name="TypeDescriptor.Message"></a>
|
||||
### func (*TypeDescriptor) [Message](<https://github.com/khan-yin/dynamicgo/blob/main/proto/descriptor.go#L24>)
|
||||
|
||||
```go
|
||||
func (t *TypeDescriptor) Message() *MessageDescriptor
|
||||
```
|
||||
|
||||
|
||||
|
||||
<a name="TypeDescriptor.Name"></a>
|
||||
### func (*TypeDescriptor) [Name](<https://github.com/khan-yin/dynamicgo/blob/main/proto/descriptor.go#L52>)
|
||||
|
||||
```go
|
||||
func (f *TypeDescriptor) Name() string
|
||||
```
|
||||
|
||||
|
||||
|
||||
<a name="TypeDescriptor.Type"></a>
|
||||
### func (*TypeDescriptor) [Type](<https://github.com/khan-yin/dynamicgo/blob/main/proto/descriptor.go#L12>)
|
||||
|
||||
```go
|
||||
func (t *TypeDescriptor) Type() Type
|
||||
```
|
||||
|
||||
|
||||
|
||||
<a name="TypeDescriptor.WireType"></a>
|
||||
### func (*TypeDescriptor) [WireType](<https://github.com/khan-yin/dynamicgo/blob/main/proto/descriptor.go#L47>)
|
||||
|
||||
```go
|
||||
func (f *TypeDescriptor) WireType() WireType
|
||||
```
|
||||
|
||||
|
||||
|
||||
<a name="WireType"></a>
|
||||
## type [WireType](<https://github.com/khan-yin/dynamicgo/blob/main/proto/type.go#L10>)
|
||||
|
||||
protobuf encoding wire type
|
||||
|
||||
```go
|
||||
type WireType int8
|
||||
```
|
||||
|
||||
<a name="VarintType"></a>
|
||||
|
||||
```go
|
||||
const (
|
||||
VarintType WireType = 0
|
||||
Fixed32Type WireType = 5
|
||||
Fixed64Type WireType = 1
|
||||
BytesType WireType = 2
|
||||
StartGroupType WireType = 3 // deprecated
|
||||
EndGroupType WireType = 4 // deprecated
|
||||
)
|
||||
```
|
||||
|
||||
<a name="WireType.String"></a>
|
||||
### func (WireType) [String](<https://github.com/khan-yin/dynamicgo/blob/main/proto/type.go#L21>)
|
||||
|
||||
```go
|
||||
func (p WireType) String() string
|
||||
```
|
||||
|
||||
|
||||
|
||||
Generated by [gomarkdoc](<https://github.com/princjef/gomarkdoc>)
|
|
@ -0,0 +1,11 @@
|
|||
#!/bin/bash
|
||||
TAG=$1
|
||||
|
||||
git clone -b release-branch.$TAG https://github.com/golang/go.git $TAG
|
||||
|
||||
cd $TAG/src
|
||||
|
||||
./all.bash
|
||||
|
||||
|
||||
|
|
@ -4,7 +4,7 @@ go 1.19
|
|||
|
||||
require (
|
||||
github.com/apache/thrift v0.20.0
|
||||
github.com/bytedance/sonic v1.11.8
|
||||
github.com/bytedance/sonic v1.12.0
|
||||
github.com/cloudwego/dynamicgo v0.2.6
|
||||
github.com/cloudwego/kitex v0.9.3-rc2
|
||||
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc
|
||||
|
@ -16,7 +16,7 @@ require (
|
|||
|
||||
require (
|
||||
github.com/bytedance/gopkg v0.0.0-20230728082804-614d0af6619b // indirect
|
||||
github.com/bytedance/sonic/loader v0.1.1 // indirect
|
||||
github.com/bytedance/sonic/loader v0.2.0 // indirect
|
||||
github.com/choleraehyq/pid v0.0.18 // indirect
|
||||
github.com/cloudwego/base64x v0.1.4 // indirect
|
||||
github.com/cloudwego/configmanager v0.2.2 // indirect
|
||||
|
|
|
@ -18,10 +18,11 @@ github.com/bytedance/gopkg v0.0.0-20230728082804-614d0af6619b/go.mod h1:FtQG3YbQ
|
|||
github.com/bytedance/mockey v1.2.7 h1:8j4yCqS5OmMe2dQCxPit4FVkwTK9nrykIgbOZN3s28o=
|
||||
github.com/bytedance/mockey v1.2.7/go.mod h1:bNrUnI1u7+pAc0TYDgPATM+wF2yzHxmNH+iDXg4AOCU=
|
||||
github.com/bytedance/sonic v1.11.6/go.mod h1:LysEHSvpvDySVdC2f87zGWf6CIKJcAvqab1ZaiQtds4=
|
||||
github.com/bytedance/sonic v1.11.8 h1:Zw/j1KfiS+OYTi9lyB3bb0CFxPJVkM17k1wyDG32LRA=
|
||||
github.com/bytedance/sonic v1.11.8/go.mod h1:LysEHSvpvDySVdC2f87zGWf6CIKJcAvqab1ZaiQtds4=
|
||||
github.com/bytedance/sonic/loader v0.1.1 h1:c+e5Pt1k/cy5wMveRDyk2X4B9hF4g7an8N3zCYjJFNM=
|
||||
github.com/bytedance/sonic v1.12.0 h1:YGPgxF9xzaCNvd/ZKdQ28yRovhfMFZQjuk6fKBzZ3ls=
|
||||
github.com/bytedance/sonic v1.12.0/go.mod h1:B8Gt/XvtZ3Fqj+iSKMypzymZxw/FVwgIGKzMzT9r/rk=
|
||||
github.com/bytedance/sonic/loader v0.1.1/go.mod h1:ncP89zfokxS5LZrJxl5z0UJcsk4M4yY2JpfqGeCtNLU=
|
||||
github.com/bytedance/sonic/loader v0.2.0 h1:zNprn+lsIP06C/IqCHs3gPQIvnvpKbbxyXQP1iU4kWM=
|
||||
github.com/bytedance/sonic/loader v0.2.0/go.mod h1:ncP89zfokxS5LZrJxl5z0UJcsk4M4yY2JpfqGeCtNLU=
|
||||
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
|
||||
github.com/choleraehyq/pid v0.0.18 h1:O7LLxPoOyt3YtonlCC8BmNrF9P6Hc8B509UOqlPSVhw=
|
||||
github.com/choleraehyq/pid v0.0.18/go.mod h1:uhzeFgxJZWQsZulelVQZwdASxQ9TIPZYL4TPkQMtL/U=
|
||||
|
|
2092
thrift/README.md
2092
thrift/README.md
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue