mirror of
https://github.com/zeromicro/go-zero.git
synced 2026-05-17 19:58:19 +08:00
Compare commits
86 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9d528dddd6 | ||
|
|
543d590710 | ||
|
|
f1d70eb6b2 | ||
|
|
d828c3f37e | ||
|
|
038491b7bc | ||
|
|
cf683411ee | ||
|
|
de5ed6a677 | ||
|
|
3dda557410 | ||
|
|
c800f6f723 | ||
|
|
0395ba1816 | ||
|
|
86f9f63b46 | ||
|
|
a7a6753118 | ||
|
|
2e80d12d6a | ||
|
|
417a96cbf2 | ||
|
|
2d4c29ea7c | ||
|
|
67db40ed4f | ||
|
|
11c485a5ed | ||
|
|
b0573af9a9 | ||
|
|
09eb53f308 | ||
|
|
11f85d1b80 | ||
|
|
0cb86c6990 | ||
|
|
57d2f22c24 | ||
|
|
fa0c364982 | ||
|
|
a6c8113419 | ||
|
|
4f5c30e083 | ||
|
|
9d0b51fa26 | ||
|
|
ba5f8045a2 | ||
|
|
3a510a9138 | ||
|
|
d3bfa16813 | ||
|
|
28409791fa | ||
|
|
c1abe87953 | ||
|
|
f8367856e8 | ||
|
|
a72b0a689b | ||
|
|
69a4d213a3 | ||
|
|
c28e01fed3 | ||
|
|
e8efcef108 | ||
|
|
d011316997 | ||
|
|
4d22b0c497 | ||
|
|
539215d7df | ||
|
|
3ede597a15 | ||
|
|
01786c5e63 | ||
|
|
6aba5f74fc | ||
|
|
3c894a3fb7 | ||
|
|
1ece3a498f | ||
|
|
b76c7ae55d | ||
|
|
91b10bd3b9 | ||
|
|
7e3fe77e7b | ||
|
|
ba43214dae | ||
|
|
ebc90720ea | ||
|
|
785d100be9 | ||
|
|
f13e6f1149 | ||
|
|
8be0f77d96 | ||
|
|
429f85a9de | ||
|
|
b4d1c6da2c | ||
|
|
3c1cfd4c1e | ||
|
|
a71a210704 | ||
|
|
769d06c8ab | ||
|
|
cd1f8da13f | ||
|
|
8230474667 | ||
|
|
27f553bf84 | ||
|
|
d48bff8c8b | ||
|
|
59b9687f31 | ||
|
|
c1a8ccda11 | ||
|
|
9df6786b09 | ||
|
|
bef5bd4e4f | ||
|
|
68acfb1891 | ||
|
|
9fd3f752d1 | ||
|
|
9c48e9ceab | ||
|
|
bd26783b33 | ||
|
|
eda8230521 | ||
|
|
462ddbb145 | ||
|
|
496a2f341e | ||
|
|
7109d6d635 | ||
|
|
ca72241fa3 | ||
|
|
a6bdffd225 | ||
|
|
5636bf4955 | ||
|
|
a944a7fd7e | ||
|
|
a40fa405e4 | ||
|
|
eab77e21dd | ||
|
|
d41163f5c1 | ||
|
|
265b1f2459 | ||
|
|
c92ea59228 | ||
|
|
afddfea093 | ||
|
|
fa4dc151ca | ||
|
|
44202acb18 | ||
|
|
cf00786209 |
12
.github/FUNDING.yml
vendored
Normal file
12
.github/FUNDING.yml
vendored
Normal file
@@ -0,0 +1,12 @@
|
||||
# These are supported funding model platforms
|
||||
|
||||
github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
|
||||
patreon: # Replace with a single Patreon username
|
||||
open_collective: # Replace with a single Open Collective username
|
||||
ko_fi: # Replace with a single Ko-fi username
|
||||
tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
|
||||
community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
|
||||
liberapay: # Replace with a single Liberapay username
|
||||
issuehunt: # Replace with a single IssueHunt username
|
||||
otechie: # Replace with a single Otechie username
|
||||
custom: # https://gitee.com/kevwan/static/raw/master/images/sponsor.jpg
|
||||
3
.gitignore
vendored
3
.gitignore
vendored
@@ -15,6 +15,9 @@
|
||||
**/.DS_Store
|
||||
**/logs
|
||||
|
||||
# for test purpose
|
||||
adhoc
|
||||
|
||||
# gitlab ci
|
||||
.cache
|
||||
|
||||
|
||||
10
ROADMAP.md
10
ROADMAP.md
@@ -10,13 +10,17 @@ We hope that the items listed below will inspire further engagement from the com
|
||||
|
||||
## 2021 Q3
|
||||
- [x] Support `goctl model pg` to support PostgreSQL code generation
|
||||
- [ ] Support `goctl mock` command to start a mocking server with given `.api` file
|
||||
- [ ] Adapt builtin tracing mechanism to opentracing solutions
|
||||
- [x] Adapt builtin tracing mechanism to opentracing solutions
|
||||
|
||||
## 2021 Q4
|
||||
- [x] Support `username/password` authentication in ETCD
|
||||
- [x] Support `SSL/TLS` in `zRPC`
|
||||
- [x] Support `TLS` in redis connections
|
||||
|
||||
## 2022
|
||||
- [ ] Support `goctl mock` command to start a mocking server with given `.api` file
|
||||
- [ ] Add `httpx.Client` with governance, like circuit breaker etc.
|
||||
- [ ] Support `goctl doctor` command to report potential issues for given service
|
||||
- [ ] Support `context` in redis related methods for timeout and tracing
|
||||
- [ ] Support `context` in sql related methods for timeout and tracing
|
||||
- [ ] Support `context` in mongodb related methods for timeout and tracing
|
||||
- [ ] Support TLS in redis connections
|
||||
|
||||
7
core/discov/accountregistry.go
Normal file
7
core/discov/accountregistry.go
Normal file
@@ -0,0 +1,7 @@
|
||||
package discov
|
||||
|
||||
import "github.com/tal-tech/go-zero/core/discov/internal"
|
||||
|
||||
func RegisterAccount(endpoints []string, user, pass string) {
|
||||
internal.AddAccount(endpoints, user, pass)
|
||||
}
|
||||
21
core/discov/accountregistry_test.go
Normal file
21
core/discov/accountregistry_test.go
Normal file
@@ -0,0 +1,21 @@
|
||||
package discov
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/tal-tech/go-zero/core/discov/internal"
|
||||
"github.com/tal-tech/go-zero/core/stringx"
|
||||
)
|
||||
|
||||
func TestRegisterAccount(t *testing.T) {
|
||||
endpoints := []string{
|
||||
"localhost:2379",
|
||||
}
|
||||
user := "foo" + stringx.Rand()
|
||||
RegisterAccount(endpoints, user, "bar")
|
||||
account, ok := internal.GetAccount(endpoints)
|
||||
assert.True(t, ok)
|
||||
assert.Equal(t, user, account.User)
|
||||
assert.Equal(t, "bar", account.Pass)
|
||||
}
|
||||
@@ -6,6 +6,13 @@ import "errors"
|
||||
type EtcdConf struct {
|
||||
Hosts []string
|
||||
Key string
|
||||
User string `json:",optional"`
|
||||
Pass string `json:",optional"`
|
||||
}
|
||||
|
||||
// HasAccount returns if account provided.
|
||||
func (c EtcdConf) HasAccount() bool {
|
||||
return len(c.User) > 0 && len(c.Pass) > 0
|
||||
}
|
||||
|
||||
// Validate validates c.
|
||||
|
||||
@@ -44,3 +44,39 @@ func TestConfig(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestEtcdConf_HasAccount(t *testing.T) {
|
||||
tests := []struct {
|
||||
EtcdConf
|
||||
hasAccount bool
|
||||
}{
|
||||
{
|
||||
EtcdConf: EtcdConf{
|
||||
Hosts: []string{"any"},
|
||||
Key: "key",
|
||||
},
|
||||
hasAccount: false,
|
||||
},
|
||||
{
|
||||
EtcdConf: EtcdConf{
|
||||
Hosts: []string{"any"},
|
||||
Key: "key",
|
||||
User: "foo",
|
||||
},
|
||||
hasAccount: false,
|
||||
},
|
||||
{
|
||||
EtcdConf: EtcdConf{
|
||||
Hosts: []string{"any"},
|
||||
Key: "key",
|
||||
User: "foo",
|
||||
Pass: "bar",
|
||||
},
|
||||
hasAccount: true,
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
assert.Equal(t, test.hasAccount, test.EtcdConf.HasAccount())
|
||||
}
|
||||
}
|
||||
|
||||
31
core/discov/internal/accountmanager.go
Normal file
31
core/discov/internal/accountmanager.go
Normal file
@@ -0,0 +1,31 @@
|
||||
package internal
|
||||
|
||||
import "sync"
|
||||
|
||||
type Account struct {
|
||||
User string
|
||||
Pass string
|
||||
}
|
||||
|
||||
var (
|
||||
accounts = make(map[string]Account)
|
||||
lock sync.RWMutex
|
||||
)
|
||||
|
||||
func AddAccount(endpoints []string, user, pass string) {
|
||||
lock.Lock()
|
||||
defer lock.Unlock()
|
||||
|
||||
accounts[getClusterKey(endpoints)] = Account{
|
||||
User: user,
|
||||
Pass: pass,
|
||||
}
|
||||
}
|
||||
|
||||
func GetAccount(endpoints []string) (Account, bool) {
|
||||
lock.RLock()
|
||||
defer lock.RUnlock()
|
||||
|
||||
account, ok := accounts[getClusterKey(endpoints)]
|
||||
return account, ok
|
||||
}
|
||||
34
core/discov/internal/accountmanager_test.go
Normal file
34
core/discov/internal/accountmanager_test.go
Normal file
@@ -0,0 +1,34 @@
|
||||
package internal
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/tal-tech/go-zero/core/stringx"
|
||||
)
|
||||
|
||||
func TestAccount(t *testing.T) {
|
||||
endpoints := []string{
|
||||
"192.168.0.2:2379",
|
||||
"192.168.0.3:2379",
|
||||
"192.168.0.4:2379",
|
||||
}
|
||||
username := "foo" + stringx.Rand()
|
||||
password := "bar"
|
||||
anotherPassword := "any"
|
||||
|
||||
_, ok := GetAccount(endpoints)
|
||||
assert.False(t, ok)
|
||||
|
||||
AddAccount(endpoints, username, password)
|
||||
account, ok := GetAccount(endpoints)
|
||||
assert.True(t, ok)
|
||||
assert.Equal(t, username, account.User)
|
||||
assert.Equal(t, password, account.Pass)
|
||||
|
||||
AddAccount(endpoints, username, anotherPassword)
|
||||
account, ok = GetAccount(endpoints)
|
||||
assert.True(t, ok)
|
||||
assert.Equal(t, username, account.User)
|
||||
assert.Equal(t, anotherPassword, account.Pass)
|
||||
}
|
||||
@@ -37,25 +37,35 @@ func GetRegistry() *Registry {
|
||||
|
||||
// GetConn returns an etcd client connection associated with given endpoints.
|
||||
func (r *Registry) GetConn(endpoints []string) (EtcdClient, error) {
|
||||
return r.getCluster(endpoints).getClient()
|
||||
c, _ := r.getCluster(endpoints)
|
||||
return c.getClient()
|
||||
}
|
||||
|
||||
// Monitor monitors the key on given etcd endpoints, notify with the given UpdateListener.
|
||||
func (r *Registry) Monitor(endpoints []string, key string, l UpdateListener) error {
|
||||
return r.getCluster(endpoints).monitor(key, l)
|
||||
c, exists := r.getCluster(endpoints)
|
||||
// if exists, the existing values should be updated to the listener.
|
||||
if exists {
|
||||
kvs := c.getCurrent(key)
|
||||
for _, kv := range kvs {
|
||||
l.OnAdd(kv)
|
||||
}
|
||||
}
|
||||
|
||||
return c.monitor(key, l)
|
||||
}
|
||||
|
||||
func (r *Registry) getCluster(endpoints []string) *cluster {
|
||||
func (r *Registry) getCluster(endpoints []string) (c *cluster, exists bool) {
|
||||
clusterKey := getClusterKey(endpoints)
|
||||
r.lock.Lock()
|
||||
defer r.lock.Unlock()
|
||||
c, ok := r.clusters[clusterKey]
|
||||
if !ok {
|
||||
c, exists = r.clusters[clusterKey]
|
||||
if !exists {
|
||||
c = newCluster(endpoints)
|
||||
r.clusters[clusterKey] = c
|
||||
}
|
||||
|
||||
return c
|
||||
return
|
||||
}
|
||||
|
||||
type cluster struct {
|
||||
@@ -94,6 +104,21 @@ func (c *cluster) getClient() (EtcdClient, error) {
|
||||
return val.(EtcdClient), nil
|
||||
}
|
||||
|
||||
func (c *cluster) getCurrent(key string) []KV {
|
||||
c.lock.Lock()
|
||||
defer c.lock.Unlock()
|
||||
|
||||
var kvs []KV
|
||||
for k, v := range c.values[key] {
|
||||
kvs = append(kvs, KV{
|
||||
Key: k,
|
||||
Val: v,
|
||||
})
|
||||
}
|
||||
|
||||
return kvs
|
||||
}
|
||||
|
||||
func (c *cluster) handleChanges(key string, kvs []KV) {
|
||||
var add []KV
|
||||
var remove []KV
|
||||
@@ -197,14 +222,12 @@ func (c *cluster) load(cli EtcdClient, key string) {
|
||||
}
|
||||
|
||||
var kvs []KV
|
||||
c.lock.Lock()
|
||||
for _, ev := range resp.Kvs {
|
||||
kvs = append(kvs, KV{
|
||||
Key: string(ev.Key),
|
||||
Val: string(ev.Value),
|
||||
})
|
||||
}
|
||||
c.lock.Unlock()
|
||||
|
||||
c.handleChanges(key, kvs)
|
||||
}
|
||||
@@ -302,14 +325,20 @@ func (c *cluster) watchConnState(cli EtcdClient) {
|
||||
|
||||
// DialClient dials an etcd cluster with given endpoints.
|
||||
func DialClient(endpoints []string) (EtcdClient, error) {
|
||||
return clientv3.New(clientv3.Config{
|
||||
cfg := clientv3.Config{
|
||||
Endpoints: endpoints,
|
||||
AutoSyncInterval: autoSyncInterval,
|
||||
DialTimeout: DialTimeout,
|
||||
DialKeepAliveTime: dialKeepAliveTime,
|
||||
DialKeepAliveTimeout: DialTimeout,
|
||||
RejectOldCluster: true,
|
||||
})
|
||||
}
|
||||
if account, ok := GetAccount(endpoints); ok {
|
||||
cfg.Username = account.User
|
||||
cfg.Password = account.Pass
|
||||
}
|
||||
|
||||
return clientv3.New(cfg)
|
||||
}
|
||||
|
||||
func getClusterKey(endpoints []string) string {
|
||||
|
||||
@@ -33,9 +33,10 @@ func setMockClient(cli EtcdClient) func() {
|
||||
}
|
||||
|
||||
func TestGetCluster(t *testing.T) {
|
||||
c1 := GetRegistry().getCluster([]string{"first"})
|
||||
c2 := GetRegistry().getCluster([]string{"second"})
|
||||
c3 := GetRegistry().getCluster([]string{"first"})
|
||||
AddAccount([]string{"first"}, "foo", "bar")
|
||||
c1, _ := GetRegistry().getCluster([]string{"first"})
|
||||
c2, _ := GetRegistry().getCluster([]string{"second"})
|
||||
c3, _ := GetRegistry().getCluster([]string{"first"})
|
||||
assert.Equal(t, c1, c3)
|
||||
assert.NotEqual(t, c1, c2)
|
||||
}
|
||||
|
||||
@@ -11,8 +11,8 @@ import (
|
||||
)
|
||||
|
||||
type (
|
||||
// PublisherOption defines the method to customize a Publisher.
|
||||
PublisherOption func(client *Publisher)
|
||||
// PubOption defines the method to customize a Publisher.
|
||||
PubOption func(client *Publisher)
|
||||
|
||||
// A Publisher can be used to publish the value to an etcd cluster on the given key.
|
||||
Publisher struct {
|
||||
@@ -32,7 +32,7 @@ type (
|
||||
// endpoints is the hosts of the etcd cluster.
|
||||
// key:value are a pair to be published.
|
||||
// opts are used to customize the Publisher.
|
||||
func NewPublisher(endpoints []string, key, value string, opts ...PublisherOption) *Publisher {
|
||||
func NewPublisher(endpoints []string, key, value string, opts ...PubOption) *Publisher {
|
||||
publisher := &Publisher{
|
||||
endpoints: endpoints,
|
||||
key: key,
|
||||
@@ -145,8 +145,15 @@ func (p *Publisher) revoke(cli internal.EtcdClient) {
|
||||
}
|
||||
}
|
||||
|
||||
// WithPubEtcdAccount provides the etcd username/password.
|
||||
func WithPubEtcdAccount(user, pass string) PubOption {
|
||||
return func(pub *Publisher) {
|
||||
internal.AddAccount(pub.endpoints, user, pass)
|
||||
}
|
||||
}
|
||||
|
||||
// WithId customizes a Publisher with the id.
|
||||
func WithId(id int64) PublisherOption {
|
||||
func WithId(id int64) PubOption {
|
||||
return func(publisher *Publisher) {
|
||||
publisher.id = id
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@ import (
|
||||
"github.com/tal-tech/go-zero/core/discov/internal"
|
||||
"github.com/tal-tech/go-zero/core/lang"
|
||||
"github.com/tal-tech/go-zero/core/logx"
|
||||
"github.com/tal-tech/go-zero/core/stringx"
|
||||
clientv3 "go.etcd.io/etcd/client/v3"
|
||||
)
|
||||
|
||||
@@ -30,7 +31,8 @@ func TestPublisher_register(t *testing.T) {
|
||||
ID: id,
|
||||
}, nil)
|
||||
cli.EXPECT().Put(gomock.Any(), makeEtcdKey("thekey", id), "thevalue", gomock.Any())
|
||||
pub := NewPublisher(nil, "thekey", "thevalue")
|
||||
pub := NewPublisher(nil, "thekey", "thevalue",
|
||||
WithPubEtcdAccount(stringx.Rand(), "bar"))
|
||||
_, err := pub.register(cli)
|
||||
assert.Nil(t, err)
|
||||
}
|
||||
|
||||
@@ -9,16 +9,14 @@ import (
|
||||
)
|
||||
|
||||
type (
|
||||
subOptions struct {
|
||||
exclusive bool
|
||||
}
|
||||
|
||||
// SubOption defines the method to customize a Subscriber.
|
||||
SubOption func(opts *subOptions)
|
||||
SubOption func(sub *Subscriber)
|
||||
|
||||
// A Subscriber is used to subscribe the given key on a etcd cluster.
|
||||
Subscriber struct {
|
||||
items *container
|
||||
endpoints []string
|
||||
exclusive bool
|
||||
items *container
|
||||
}
|
||||
)
|
||||
|
||||
@@ -27,14 +25,14 @@ type (
|
||||
// key is the key to subscribe.
|
||||
// opts are used to customize the Subscriber.
|
||||
func NewSubscriber(endpoints []string, key string, opts ...SubOption) (*Subscriber, error) {
|
||||
var subOpts subOptions
|
||||
for _, opt := range opts {
|
||||
opt(&subOpts)
|
||||
}
|
||||
|
||||
sub := &Subscriber{
|
||||
items: newContainer(subOpts.exclusive),
|
||||
endpoints: endpoints,
|
||||
}
|
||||
for _, opt := range opts {
|
||||
opt(sub)
|
||||
}
|
||||
sub.items = newContainer(sub.exclusive)
|
||||
|
||||
if err := internal.GetRegistry().Monitor(endpoints, key, sub.items); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -55,8 +53,14 @@ func (s *Subscriber) Values() []string {
|
||||
// Exclusive means that key value can only be 1:1,
|
||||
// which means later added value will remove the keys associated with the same value previously.
|
||||
func Exclusive() SubOption {
|
||||
return func(opts *subOptions) {
|
||||
opts.exclusive = true
|
||||
return func(sub *Subscriber) {
|
||||
sub.exclusive = true
|
||||
}
|
||||
}
|
||||
|
||||
func WithSubEtcdAccount(user, pass string) SubOption {
|
||||
return func(sub *Subscriber) {
|
||||
internal.AddAccount(sub.endpoints, user, pass)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/tal-tech/go-zero/core/discov/internal"
|
||||
"github.com/tal-tech/go-zero/core/stringx"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -201,11 +202,9 @@ func TestContainer(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestSubscriber(t *testing.T) {
|
||||
var opt subOptions
|
||||
Exclusive()(&opt)
|
||||
|
||||
sub := new(Subscriber)
|
||||
sub.items = newContainer(opt.exclusive)
|
||||
Exclusive()(sub)
|
||||
sub.items = newContainer(sub.exclusive)
|
||||
var count int32
|
||||
sub.AddListener(func() {
|
||||
atomic.AddInt32(&count, 1)
|
||||
@@ -214,3 +213,15 @@ func TestSubscriber(t *testing.T) {
|
||||
assert.Empty(t, sub.Values())
|
||||
assert.Equal(t, int32(1), atomic.LoadInt32(&count))
|
||||
}
|
||||
|
||||
func TestWithSubEtcdAccount(t *testing.T) {
|
||||
endpoints := []string{"localhost:2379"}
|
||||
user := stringx.Rand()
|
||||
WithSubEtcdAccount(user, "bar")(&Subscriber{
|
||||
endpoints: endpoints,
|
||||
})
|
||||
account, ok := internal.GetAccount(endpoints)
|
||||
assert.True(t, ok)
|
||||
assert.Equal(t, user, account.User)
|
||||
assert.Equal(t, "bar", account.Pass)
|
||||
}
|
||||
|
||||
@@ -74,12 +74,12 @@ func TestConsistentHashIncrementalTransfer(t *testing.T) {
|
||||
laterCh := create()
|
||||
laterCh.AddWithWeight(node, 10*(i+1))
|
||||
|
||||
for i := 0; i < requestSize; i++ {
|
||||
key, ok := laterCh.Get(requestSize + i)
|
||||
for j := 0; j < requestSize; j++ {
|
||||
key, ok := laterCh.Get(requestSize + j)
|
||||
assert.True(t, ok)
|
||||
assert.NotNil(t, key)
|
||||
value := key.(string)
|
||||
assert.True(t, value == keys[i] || value == node)
|
||||
assert.True(t, value == keys[j] || value == node)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/globalsign/mgo/bson"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
@@ -106,3 +107,20 @@ func TestMilliTime_UnmarshalJSON(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestUnmarshalWithError(t *testing.T) {
|
||||
var mt MilliTime
|
||||
assert.NotNil(t, mt.UnmarshalJSON([]byte("hello")))
|
||||
}
|
||||
|
||||
func TestSetBSON(t *testing.T) {
|
||||
data, err := bson.Marshal(time.Now())
|
||||
assert.Nil(t, err)
|
||||
|
||||
var raw bson.Raw
|
||||
assert.Nil(t, bson.Unmarshal(data, &raw))
|
||||
|
||||
var mt MilliTime
|
||||
assert.Nil(t, mt.SetBSON(raw))
|
||||
assert.NotNil(t, mt.SetBSON(bson.Raw{}))
|
||||
}
|
||||
|
||||
62
core/logx/limitedexecutor_test.go
Normal file
62
core/logx/limitedexecutor_test.go
Normal file
@@ -0,0 +1,62 @@
|
||||
package logx
|
||||
|
||||
import (
|
||||
"sync/atomic"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/tal-tech/go-zero/core/timex"
|
||||
)
|
||||
|
||||
func TestLimitedExecutor_logOrDiscard(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
threshold time.Duration
|
||||
lastTime time.Duration
|
||||
discarded uint32
|
||||
executed bool
|
||||
}{
|
||||
{
|
||||
name: "nil executor",
|
||||
executed: true,
|
||||
},
|
||||
{
|
||||
name: "regular",
|
||||
threshold: time.Hour,
|
||||
lastTime: timex.Now(),
|
||||
discarded: 10,
|
||||
executed: false,
|
||||
},
|
||||
{
|
||||
name: "slow",
|
||||
threshold: time.Duration(1),
|
||||
lastTime: -1000,
|
||||
discarded: 10,
|
||||
executed: true,
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
test := test
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
executor := newLimitedExecutor(0)
|
||||
executor.threshold = test.threshold
|
||||
executor.discarded = test.discarded
|
||||
executor.lastTime.Set(test.lastTime)
|
||||
|
||||
var run int32
|
||||
executor.logOrDiscard(func() {
|
||||
atomic.AddInt32(&run, 1)
|
||||
})
|
||||
if test.executed {
|
||||
assert.Equal(t, int32(1), atomic.LoadInt32(&run))
|
||||
} else {
|
||||
assert.Equal(t, int32(0), atomic.LoadInt32(&run))
|
||||
assert.Equal(t, test.discarded+1, atomic.LoadUint32(&executor.discarded))
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -217,7 +217,7 @@ func ErrorCaller(callDepth int, v ...interface{}) {
|
||||
|
||||
// ErrorCallerf writes v with context in format into error log.
|
||||
func ErrorCallerf(callDepth int, format string, v ...interface{}) {
|
||||
errorTextSync(fmt.Sprintf(format, v...), callDepth+callerInnerDepth)
|
||||
errorTextSync(fmt.Errorf(format, v...).Error(), callDepth+callerInnerDepth)
|
||||
}
|
||||
|
||||
// Errorf writes v with format into error log.
|
||||
|
||||
@@ -2,6 +2,7 @@ package logx
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
@@ -242,6 +243,16 @@ func TestSetLevelWithDuration(t *testing.T) {
|
||||
assert.Equal(t, 0, writer.builder.Len())
|
||||
}
|
||||
|
||||
func TestErrorfWithWrappedError(t *testing.T) {
|
||||
SetLevel(ErrorLevel)
|
||||
const message = "there"
|
||||
writer := new(mockWriter)
|
||||
errorLog = writer
|
||||
atomic.StoreUint32(&initialized, 1)
|
||||
Errorf("hello %w", errors.New(message))
|
||||
assert.True(t, strings.Contains(writer.builder.String(), "hello there"))
|
||||
}
|
||||
|
||||
func TestMustNil(t *testing.T) {
|
||||
Must(nil)
|
||||
}
|
||||
|
||||
@@ -207,6 +207,8 @@ func (u *Unmarshaler) processFieldNotFromString(field reflect.StructField, value
|
||||
switch {
|
||||
case valueKind == reflect.Map && typeKind == reflect.Struct:
|
||||
return u.processFieldStruct(field, value, mapValue, fullName)
|
||||
case valueKind == reflect.Map && typeKind == reflect.Map:
|
||||
return u.fillMap(field, value, mapValue)
|
||||
case valueKind == reflect.String && typeKind == reflect.Slice:
|
||||
return u.fillSliceFromString(fieldType, value, mapValue)
|
||||
case valueKind == reflect.String && derefedFieldType == durationType:
|
||||
@@ -584,6 +586,8 @@ func (u *Unmarshaler) generateMap(keyType, elemType reflect.Type, mapValue inter
|
||||
targetValue.SetMapIndex(key, innerValue)
|
||||
default:
|
||||
switch v := keythData.(type) {
|
||||
case bool:
|
||||
targetValue.SetMapIndex(key, reflect.ValueOf(v))
|
||||
case string:
|
||||
targetValue.SetMapIndex(key, reflect.ValueOf(v))
|
||||
case json.Number:
|
||||
|
||||
@@ -209,6 +209,12 @@ func TestRepr(t *testing.T) {
|
||||
newMockPtr(),
|
||||
"mockptr",
|
||||
},
|
||||
{
|
||||
&mockOpacity{
|
||||
val: 1,
|
||||
},
|
||||
"{1}",
|
||||
},
|
||||
{
|
||||
true,
|
||||
"true",
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"k8s.io/utils/io"
|
||||
)
|
||||
|
||||
func TestUnmarshalYamlBytes(t *testing.T) {
|
||||
@@ -18,6 +19,22 @@ func TestUnmarshalYamlBytes(t *testing.T) {
|
||||
assert.Equal(t, "liao", c.Name)
|
||||
}
|
||||
|
||||
func TestUnmarshalYamlBytesErrorInput(t *testing.T) {
|
||||
var c struct {
|
||||
Name string
|
||||
}
|
||||
content := []byte(`liao`)
|
||||
assert.NotNil(t, UnmarshalYamlBytes(content, &c))
|
||||
}
|
||||
|
||||
func TestUnmarshalYamlBytesEmptyInput(t *testing.T) {
|
||||
var c struct {
|
||||
Name string
|
||||
}
|
||||
content := []byte(``)
|
||||
assert.NotNil(t, UnmarshalYamlBytes(content, &c))
|
||||
}
|
||||
|
||||
func TestUnmarshalYamlBytesOptional(t *testing.T) {
|
||||
var c struct {
|
||||
Name string
|
||||
@@ -918,3 +935,82 @@ func TestUnmarshalYamlReaderError(t *testing.T) {
|
||||
err := UnmarshalYamlReader(reader, &v)
|
||||
assert.NotNil(t, err)
|
||||
}
|
||||
|
||||
func TestUnmarshalYamlBadReader(t *testing.T) {
|
||||
var v struct {
|
||||
Any string
|
||||
}
|
||||
|
||||
err := UnmarshalYamlReader(new(badReader), &v)
|
||||
assert.NotNil(t, err)
|
||||
}
|
||||
|
||||
func TestUnmarshalYamlMapBool(t *testing.T) {
|
||||
text := `machine:
|
||||
node1: true
|
||||
node2: true
|
||||
node3: true
|
||||
`
|
||||
var v struct {
|
||||
Machine map[string]bool `json:"machine,optional"`
|
||||
}
|
||||
reader := strings.NewReader(text)
|
||||
assert.Nil(t, UnmarshalYamlReader(reader, &v))
|
||||
assert.True(t, v.Machine["node1"])
|
||||
assert.True(t, v.Machine["node2"])
|
||||
assert.True(t, v.Machine["node3"])
|
||||
}
|
||||
|
||||
func TestUnmarshalYamlMapInt(t *testing.T) {
|
||||
text := `machine:
|
||||
node1: 1
|
||||
node2: 2
|
||||
node3: 3
|
||||
`
|
||||
var v struct {
|
||||
Machine map[string]int `json:"machine,optional"`
|
||||
}
|
||||
reader := strings.NewReader(text)
|
||||
assert.Nil(t, UnmarshalYamlReader(reader, &v))
|
||||
assert.Equal(t, 1, v.Machine["node1"])
|
||||
assert.Equal(t, 2, v.Machine["node2"])
|
||||
assert.Equal(t, 3, v.Machine["node3"])
|
||||
}
|
||||
|
||||
func TestUnmarshalYamlMapByte(t *testing.T) {
|
||||
text := `machine:
|
||||
node1: 1
|
||||
node2: 2
|
||||
node3: 3
|
||||
`
|
||||
var v struct {
|
||||
Machine map[string]byte `json:"machine,optional"`
|
||||
}
|
||||
reader := strings.NewReader(text)
|
||||
assert.Nil(t, UnmarshalYamlReader(reader, &v))
|
||||
assert.Equal(t, byte(1), v.Machine["node1"])
|
||||
assert.Equal(t, byte(2), v.Machine["node2"])
|
||||
assert.Equal(t, byte(3), v.Machine["node3"])
|
||||
}
|
||||
|
||||
func TestUnmarshalYamlMapRune(t *testing.T) {
|
||||
text := `machine:
|
||||
node1: 1
|
||||
node2: 2
|
||||
node3: 3
|
||||
`
|
||||
var v struct {
|
||||
Machine map[string]rune `json:"machine,optional"`
|
||||
}
|
||||
reader := strings.NewReader(text)
|
||||
assert.Nil(t, UnmarshalYamlReader(reader, &v))
|
||||
assert.Equal(t, rune(1), v.Machine["node1"])
|
||||
assert.Equal(t, rune(2), v.Machine["node2"])
|
||||
assert.Equal(t, rune(3), v.Machine["node3"])
|
||||
}
|
||||
|
||||
type badReader struct{}
|
||||
|
||||
func (b *badReader) Read(p []byte) (n int, err error) {
|
||||
return 0, io.ErrLimitReached
|
||||
}
|
||||
|
||||
@@ -23,11 +23,11 @@ func Enabled() bool {
|
||||
|
||||
// StartAgent starts a prometheus agent.
|
||||
func StartAgent(c Config) {
|
||||
once.Do(func() {
|
||||
if len(c.Host) == 0 {
|
||||
return
|
||||
}
|
||||
if len(c.Host) == 0 {
|
||||
return
|
||||
}
|
||||
|
||||
once.Do(func() {
|
||||
enabled.Set(true)
|
||||
threading.GoSafe(func() {
|
||||
http.Handle(c.Path, promhttp.Handler())
|
||||
|
||||
@@ -26,6 +26,7 @@ type (
|
||||
}
|
||||
|
||||
// A ServiceGroup is a group of services.
|
||||
// Attention: the starting order of the added services is not guaranteed.
|
||||
ServiceGroup struct {
|
||||
services []Service
|
||||
stopOnce func()
|
||||
@@ -41,7 +42,8 @@ func NewServiceGroup() *ServiceGroup {
|
||||
|
||||
// Add adds service into sg.
|
||||
func (sg *ServiceGroup) Add(service Service) {
|
||||
sg.services = append(sg.services, service)
|
||||
// push front, stop with reverse order.
|
||||
sg.services = append([]Service{service}, sg.services...)
|
||||
}
|
||||
|
||||
// Start starts the ServiceGroup.
|
||||
|
||||
63
core/stores/builder/builder.go
Normal file
63
core/stores/builder/builder.go
Normal file
@@ -0,0 +1,63 @@
|
||||
package builder
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"reflect"
|
||||
"strings"
|
||||
)
|
||||
|
||||
const dbTag = "db"
|
||||
|
||||
// RawFieldNames converts golang struct field into slice string.
|
||||
func RawFieldNames(in interface{}, postgresSql ...bool) []string {
|
||||
out := make([]string, 0)
|
||||
v := reflect.ValueOf(in)
|
||||
if v.Kind() == reflect.Ptr {
|
||||
v = v.Elem()
|
||||
}
|
||||
|
||||
var pg bool
|
||||
if len(postgresSql) > 0 {
|
||||
pg = postgresSql[0]
|
||||
}
|
||||
|
||||
// we only accept structs
|
||||
if v.Kind() != reflect.Struct {
|
||||
panic(fmt.Errorf("ToMap only accepts structs; got %T", v))
|
||||
}
|
||||
|
||||
typ := v.Type()
|
||||
for i := 0; i < v.NumField(); i++ {
|
||||
// gets us a StructField
|
||||
fi := typ.Field(i)
|
||||
if tagv := fi.Tag.Get(dbTag); tagv != "" {
|
||||
if pg {
|
||||
out = append(out, tagv)
|
||||
} else {
|
||||
out = append(out, fmt.Sprintf("`%s`", tagv))
|
||||
}
|
||||
} else {
|
||||
if pg {
|
||||
out = append(out, fi.Name)
|
||||
} else {
|
||||
out = append(out, fmt.Sprintf("`%s`", fi.Name))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return out
|
||||
}
|
||||
|
||||
// PostgreSqlJoin concatenates the given elements into a string.
|
||||
func PostgreSqlJoin(elems []string) string {
|
||||
b := new(strings.Builder)
|
||||
for index, e := range elems {
|
||||
b.WriteString(fmt.Sprintf("%s = $%d, ", e, index+2))
|
||||
}
|
||||
|
||||
if b.Len() == 0 {
|
||||
return b.String()
|
||||
}
|
||||
|
||||
return b.String()[0 : b.Len()-2]
|
||||
}
|
||||
24
core/stores/builder/builder_test.go
Normal file
24
core/stores/builder/builder_test.go
Normal file
@@ -0,0 +1,24 @@
|
||||
package builder
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
type mockedUser struct {
|
||||
ID string `db:"id" json:"id,omitempty"`
|
||||
UserName string `db:"user_name" json:"userName,omitempty"`
|
||||
Sex int `db:"sex" json:"sex,omitempty"`
|
||||
UUID string `db:"uuid" uuid:"uuid,omitempty"`
|
||||
Age int `db:"age" json:"age"`
|
||||
}
|
||||
|
||||
func TestFieldNames(t *testing.T) {
|
||||
t.Run("new", func(t *testing.T) {
|
||||
var u mockedUser
|
||||
out := RawFieldNames(&u)
|
||||
expected := []string{"`id`", "`user_name`", "`sex`", "`uuid`", "`age`"}
|
||||
assert.Equal(t, expected, out)
|
||||
})
|
||||
}
|
||||
@@ -667,10 +667,12 @@ func TestRedis_HyperLogLog(t *testing.T) {
|
||||
assert.NotNil(t, err)
|
||||
|
||||
runOnCluster(t, func(cluster Store) {
|
||||
_, err := cluster.Pfadd("key")
|
||||
assert.NotNil(t, err)
|
||||
_, err = cluster.Pfcount("key")
|
||||
assert.NotNil(t, err)
|
||||
ok, err := cluster.Pfadd("key", "value")
|
||||
assert.Nil(t, err)
|
||||
assert.True(t, ok)
|
||||
val, err := cluster.Pfcount("key")
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, int64(1), val)
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ import (
|
||||
"github.com/tal-tech/go-zero/core/timex"
|
||||
)
|
||||
|
||||
const slowThreshold = time.Millisecond * 500
|
||||
const defaultSlowThreshold = time.Millisecond * 500
|
||||
|
||||
// ErrNotFound is an alias of mgo.ErrNotFound.
|
||||
var ErrNotFound = mgo.ErrNotFound
|
||||
@@ -203,7 +203,7 @@ func (c *decoratedCollection) logDuration(method string, duration time.Duration,
|
||||
if e != nil {
|
||||
logx.Error(err)
|
||||
} else if err != nil {
|
||||
if duration > slowThreshold {
|
||||
if duration > slowThreshold.Load() {
|
||||
logx.WithDuration(duration).Slowf("[MONGO] mongo(%s) - slowcall - %s - fail(%s) - %s",
|
||||
c.name, method, err.Error(), string(content))
|
||||
} else {
|
||||
@@ -211,7 +211,7 @@ func (c *decoratedCollection) logDuration(method string, duration time.Duration,
|
||||
c.name, method, err.Error(), string(content))
|
||||
}
|
||||
} else {
|
||||
if duration > slowThreshold {
|
||||
if duration > slowThreshold.Load() {
|
||||
logx.WithDuration(duration).Slowf("[MONGO] mongo(%s) - slowcall - %s - ok - %s",
|
||||
c.name, method, string(content))
|
||||
} else {
|
||||
|
||||
@@ -8,23 +8,14 @@ import (
|
||||
"github.com/tal-tech/go-zero/core/breaker"
|
||||
)
|
||||
|
||||
type (
|
||||
options struct {
|
||||
timeout time.Duration
|
||||
}
|
||||
|
||||
// Option defines the method to customize a mongo model.
|
||||
Option func(opts *options)
|
||||
|
||||
// A Model is a mongo model.
|
||||
Model struct {
|
||||
session *concurrentSession
|
||||
db *mgo.Database
|
||||
collection string
|
||||
brk breaker.Breaker
|
||||
opts []Option
|
||||
}
|
||||
)
|
||||
// A Model is a mongo model.
|
||||
type Model struct {
|
||||
session *concurrentSession
|
||||
db *mgo.Database
|
||||
collection string
|
||||
brk breaker.Breaker
|
||||
opts []Option
|
||||
}
|
||||
|
||||
// MustNewModel returns a Model, exits on errors.
|
||||
func MustNewModel(url, collection string, opts ...Option) *Model {
|
||||
|
||||
14
core/stores/mongo/model_test.go
Normal file
14
core/stores/mongo/model_test.go
Normal file
@@ -0,0 +1,14 @@
|
||||
package mongo
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestWithTimeout(t *testing.T) {
|
||||
o := defaultOptions()
|
||||
WithTimeout(time.Second)(o)
|
||||
assert.Equal(t, time.Second, o.timeout)
|
||||
}
|
||||
29
core/stores/mongo/options.go
Normal file
29
core/stores/mongo/options.go
Normal file
@@ -0,0 +1,29 @@
|
||||
package mongo
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/tal-tech/go-zero/core/syncx"
|
||||
)
|
||||
|
||||
var slowThreshold = syncx.ForAtomicDuration(defaultSlowThreshold)
|
||||
|
||||
type (
|
||||
options struct {
|
||||
timeout time.Duration
|
||||
}
|
||||
|
||||
// Option defines the method to customize a mongo model.
|
||||
Option func(opts *options)
|
||||
)
|
||||
|
||||
// SetSlowThreshold sets the slow threshold.
|
||||
func SetSlowThreshold(threshold time.Duration) {
|
||||
slowThreshold.Set(threshold)
|
||||
}
|
||||
|
||||
func defaultOptions() *options {
|
||||
return &options{
|
||||
timeout: defaultTimeout,
|
||||
}
|
||||
}
|
||||
14
core/stores/mongo/options_test.go
Normal file
14
core/stores/mongo/options_test.go
Normal file
@@ -0,0 +1,14 @@
|
||||
package mongo
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestSetSlowThreshold(t *testing.T) {
|
||||
assert.Equal(t, defaultSlowThreshold, slowThreshold.Load())
|
||||
SetSlowThreshold(time.Second)
|
||||
assert.Equal(t, time.Second, slowThreshold.Load())
|
||||
}
|
||||
@@ -57,9 +57,7 @@ func (cs *concurrentSession) putSession(session *mgo.Session) {
|
||||
}
|
||||
|
||||
func (cs *concurrentSession) takeSession(opts ...Option) (*mgo.Session, error) {
|
||||
o := &options{
|
||||
timeout: defaultTimeout,
|
||||
}
|
||||
o := defaultOptions()
|
||||
for _, opt := range opts {
|
||||
opt(o)
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ type (
|
||||
Host string
|
||||
Type string `json:",default=node,options=node|cluster"`
|
||||
Pass string `json:",optional"`
|
||||
Tls bool `json:",default=false,options=true|false"`
|
||||
Tls bool `json:",optional"`
|
||||
}
|
||||
|
||||
// A RedisKeyConf is a redis config with key.
|
||||
|
||||
@@ -9,13 +9,13 @@ import (
|
||||
"github.com/tal-tech/go-zero/core/timex"
|
||||
)
|
||||
|
||||
func process(proc func(red.Cmder) error) func(red.Cmder) error {
|
||||
func checkDuration(proc func(red.Cmder) error) func(red.Cmder) error {
|
||||
return func(cmd red.Cmder) error {
|
||||
start := timex.Now()
|
||||
|
||||
defer func() {
|
||||
duration := timex.Since(start)
|
||||
if duration > slowThreshold {
|
||||
if duration > slowThreshold.Load() {
|
||||
var buf strings.Builder
|
||||
for i, arg := range cmd.Args() {
|
||||
if i > 0 {
|
||||
|
||||
@@ -9,6 +9,7 @@ import (
|
||||
red "github.com/go-redis/redis"
|
||||
"github.com/tal-tech/go-zero/core/breaker"
|
||||
"github.com/tal-tech/go-zero/core/mapping"
|
||||
"github.com/tal-tech/go-zero/core/syncx"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -21,12 +22,14 @@ const (
|
||||
|
||||
blockingQueryTimeout = 5 * time.Second
|
||||
readWriteTimeout = 2 * time.Second
|
||||
|
||||
slowThreshold = time.Millisecond * 100
|
||||
defaultSlowThreshold = time.Millisecond * 100
|
||||
)
|
||||
|
||||
// ErrNilNode is an error that indicates a nil redis node.
|
||||
var ErrNilNode = errors.New("nil redis node")
|
||||
var (
|
||||
// ErrNilNode is an error that indicates a nil redis node.
|
||||
ErrNilNode = errors.New("nil redis node")
|
||||
slowThreshold = syncx.ForAtomicDuration(defaultSlowThreshold)
|
||||
)
|
||||
|
||||
type (
|
||||
// Option defines the method to customize a Redis.
|
||||
@@ -1758,6 +1761,11 @@ func Cluster() Option {
|
||||
}
|
||||
}
|
||||
|
||||
// SetSlowThreshold sets the slow threshold.
|
||||
func SetSlowThreshold(threshold time.Duration) {
|
||||
slowThreshold.Set(threshold)
|
||||
}
|
||||
|
||||
// WithPass customizes the given Redis with given password.
|
||||
func WithPass(pass string) Option {
|
||||
return func(r *Redis) {
|
||||
|
||||
@@ -11,6 +11,7 @@ import (
|
||||
"github.com/alicebob/miniredis/v2"
|
||||
red "github.com/go-redis/redis"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/tal-tech/go-zero/core/stringx"
|
||||
)
|
||||
|
||||
func TestRedis_Exists(t *testing.T) {
|
||||
@@ -186,7 +187,7 @@ func TestRedis_Hscan(t *testing.T) {
|
||||
key := "hash:test"
|
||||
fieldsAndValues := make(map[string]string)
|
||||
for i := 0; i < 1550; i++ {
|
||||
fieldsAndValues["filed_"+strconv.Itoa(i)] = randomStr(i)
|
||||
fieldsAndValues["filed_"+strconv.Itoa(i)] = stringx.Randn(i)
|
||||
}
|
||||
err := client.Hmset(key, fieldsAndValues)
|
||||
assert.Nil(t, err)
|
||||
@@ -256,13 +257,24 @@ func TestRedis_Keys(t *testing.T) {
|
||||
func TestRedis_HyperLogLog(t *testing.T) {
|
||||
runOnRedis(t, func(client *Redis) {
|
||||
client.Ping()
|
||||
r := New(client.Addr, badType())
|
||||
_, err := r.Pfadd("key1")
|
||||
assert.NotNil(t, err)
|
||||
_, err = r.Pfcount("*")
|
||||
assert.NotNil(t, err)
|
||||
err = r.Pfmerge("*")
|
||||
assert.NotNil(t, err)
|
||||
r := New(client.Addr)
|
||||
ok, err := r.Pfadd("key1", "val1")
|
||||
assert.Nil(t, err)
|
||||
assert.True(t, ok)
|
||||
val, err := r.Pfcount("key1")
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, int64(1), val)
|
||||
ok, err = r.Pfadd("key2", "val2")
|
||||
assert.Nil(t, err)
|
||||
assert.True(t, ok)
|
||||
val, err = r.Pfcount("key2")
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, int64(1), val)
|
||||
err = r.Pfmerge("key1", "key2")
|
||||
assert.Nil(t, err)
|
||||
val, err = r.Pfcount("key1")
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, int64(2), val)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -539,7 +551,7 @@ func TestRedis_Sscan(t *testing.T) {
|
||||
key := "list"
|
||||
var list []string
|
||||
for i := 0; i < 1550; i++ {
|
||||
list = append(list, randomStr(i))
|
||||
list = append(list, stringx.Randn(i))
|
||||
}
|
||||
lens, err := client.Sadd(key, list)
|
||||
assert.Nil(t, err)
|
||||
@@ -1073,6 +1085,12 @@ func TestRedisGeo(t *testing.T) {
|
||||
})
|
||||
}
|
||||
|
||||
func TestSetSlowThreshold(t *testing.T) {
|
||||
assert.Equal(t, defaultSlowThreshold, slowThreshold.Load())
|
||||
SetSlowThreshold(time.Second)
|
||||
assert.Equal(t, time.Second, slowThreshold.Load())
|
||||
}
|
||||
|
||||
func TestRedis_WithPass(t *testing.T) {
|
||||
runOnRedis(t, func(client *Redis) {
|
||||
err := New(client.Addr, WithPass("any")).Ping()
|
||||
|
||||
@@ -32,7 +32,7 @@ func getClient(r *Redis) (*red.Client, error) {
|
||||
MinIdleConns: idleConns,
|
||||
TLSConfig: tlsConfig,
|
||||
})
|
||||
store.WrapProcess(process)
|
||||
store.WrapProcess(checkDuration)
|
||||
return store, nil
|
||||
})
|
||||
if err != nil {
|
||||
|
||||
@@ -25,7 +25,7 @@ func getCluster(r *Redis) (*red.ClusterClient, error) {
|
||||
MinIdleConns: idleConns,
|
||||
TLSConfig: tlsConfig,
|
||||
})
|
||||
store.WrapProcess(process)
|
||||
store.WrapProcess(checkDuration)
|
||||
|
||||
return store, nil
|
||||
})
|
||||
|
||||
@@ -8,10 +8,10 @@ import (
|
||||
|
||||
red "github.com/go-redis/redis"
|
||||
"github.com/tal-tech/go-zero/core/logx"
|
||||
"github.com/tal-tech/go-zero/core/stringx"
|
||||
)
|
||||
|
||||
const (
|
||||
letters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
||||
lockCommand = `if redis.call("GET", KEYS[1]) == ARGV[1] then
|
||||
redis.call("SET", KEYS[1], ARGV[1], "PX", ARGV[2])
|
||||
return "OK"
|
||||
@@ -45,7 +45,7 @@ func NewRedisLock(store *Redis, key string) *RedisLock {
|
||||
return &RedisLock{
|
||||
store: store,
|
||||
key: key,
|
||||
id: randomStr(randomLen),
|
||||
id: stringx.Randn(randomLen),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -92,11 +92,3 @@ func (rl *RedisLock) Release() (bool, error) {
|
||||
func (rl *RedisLock) SetExpire(seconds int) {
|
||||
atomic.StoreUint32(&rl.seconds, uint32(seconds))
|
||||
}
|
||||
|
||||
func randomStr(n int) string {
|
||||
b := make([]byte, n)
|
||||
for i := range b {
|
||||
b[i] = letters[rand.Intn(len(letters))]
|
||||
}
|
||||
return string(b)
|
||||
}
|
||||
|
||||
@@ -5,10 +5,18 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/tal-tech/go-zero/core/logx"
|
||||
"github.com/tal-tech/go-zero/core/syncx"
|
||||
"github.com/tal-tech/go-zero/core/timex"
|
||||
)
|
||||
|
||||
const slowThreshold = time.Millisecond * 500
|
||||
const defaultSlowThreshold = time.Millisecond * 500
|
||||
|
||||
var slowThreshold = syncx.ForAtomicDuration(defaultSlowThreshold)
|
||||
|
||||
// SetSlowThreshold sets the slow threshold.
|
||||
func SetSlowThreshold(threshold time.Duration) {
|
||||
slowThreshold.Set(threshold)
|
||||
}
|
||||
|
||||
func exec(conn sessionConn, q string, args ...interface{}) (sql.Result, error) {
|
||||
stmt, err := format(q, args...)
|
||||
@@ -19,7 +27,7 @@ func exec(conn sessionConn, q string, args ...interface{}) (sql.Result, error) {
|
||||
startTime := timex.Now()
|
||||
result, err := conn.Exec(q, args...)
|
||||
duration := timex.Since(startTime)
|
||||
if duration > slowThreshold {
|
||||
if duration > slowThreshold.Load() {
|
||||
logx.WithDuration(duration).Slowf("[SQL] exec: slowcall - %s", stmt)
|
||||
} else {
|
||||
logx.WithDuration(duration).Infof("sql exec: %s", stmt)
|
||||
@@ -40,7 +48,7 @@ func execStmt(conn stmtConn, q string, args ...interface{}) (sql.Result, error)
|
||||
startTime := timex.Now()
|
||||
result, err := conn.Exec(args...)
|
||||
duration := timex.Since(startTime)
|
||||
if duration > slowThreshold {
|
||||
if duration > slowThreshold.Load() {
|
||||
logx.WithDuration(duration).Slowf("[SQL] execStmt: slowcall - %s", stmt)
|
||||
} else {
|
||||
logx.WithDuration(duration).Infof("sql execStmt: %s", stmt)
|
||||
@@ -61,7 +69,7 @@ func query(conn sessionConn, scanner func(*sql.Rows) error, q string, args ...in
|
||||
startTime := timex.Now()
|
||||
rows, err := conn.Query(q, args...)
|
||||
duration := timex.Since(startTime)
|
||||
if duration > slowThreshold {
|
||||
if duration > slowThreshold.Load() {
|
||||
logx.WithDuration(duration).Slowf("[SQL] query: slowcall - %s", stmt)
|
||||
} else {
|
||||
logx.WithDuration(duration).Infof("sql query: %s", stmt)
|
||||
@@ -84,7 +92,7 @@ func queryStmt(conn stmtConn, scanner func(*sql.Rows) error, q string, args ...i
|
||||
startTime := timex.Now()
|
||||
rows, err := conn.Query(args...)
|
||||
duration := timex.Since(startTime)
|
||||
if duration > slowThreshold {
|
||||
if duration > slowThreshold.Load() {
|
||||
logx.WithDuration(duration).Slowf("[SQL] queryStmt: slowcall - %s", stmt)
|
||||
} else {
|
||||
logx.WithDuration(duration).Infof("sql queryStmt: %s", stmt)
|
||||
|
||||
@@ -171,6 +171,12 @@ func TestStmt_query(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestSetSlowThreshold(t *testing.T) {
|
||||
assert.Equal(t, defaultSlowThreshold, slowThreshold.Load())
|
||||
SetSlowThreshold(time.Second)
|
||||
assert.Equal(t, time.Second, slowThreshold.Load())
|
||||
}
|
||||
|
||||
type mockedSessionConn struct {
|
||||
lastInsertId int64
|
||||
rowsAffected int64
|
||||
@@ -180,7 +186,7 @@ type mockedSessionConn struct {
|
||||
|
||||
func (m *mockedSessionConn) Exec(query string, args ...interface{}) (sql.Result, error) {
|
||||
if m.delay {
|
||||
time.Sleep(slowThreshold + time.Millisecond)
|
||||
time.Sleep(defaultSlowThreshold + time.Millisecond)
|
||||
}
|
||||
return mockedResult{
|
||||
lastInsertId: m.lastInsertId,
|
||||
@@ -190,7 +196,7 @@ func (m *mockedSessionConn) Exec(query string, args ...interface{}) (sql.Result,
|
||||
|
||||
func (m *mockedSessionConn) Query(query string, args ...interface{}) (*sql.Rows, error) {
|
||||
if m.delay {
|
||||
time.Sleep(slowThreshold + time.Millisecond)
|
||||
time.Sleep(defaultSlowThreshold + time.Millisecond)
|
||||
}
|
||||
|
||||
err := errMockedPlaceholder
|
||||
@@ -209,7 +215,7 @@ type mockedStmtConn struct {
|
||||
|
||||
func (m *mockedStmtConn) Exec(args ...interface{}) (sql.Result, error) {
|
||||
if m.delay {
|
||||
time.Sleep(slowThreshold + time.Millisecond)
|
||||
time.Sleep(defaultSlowThreshold + time.Millisecond)
|
||||
}
|
||||
return mockedResult{
|
||||
lastInsertId: m.lastInsertId,
|
||||
@@ -219,7 +225,7 @@ func (m *mockedStmtConn) Exec(args ...interface{}) (sql.Result, error) {
|
||||
|
||||
func (m *mockedStmtConn) Query(args ...interface{}) (*sql.Rows, error) {
|
||||
if m.delay {
|
||||
time.Sleep(slowThreshold + time.Millisecond)
|
||||
time.Sleep(defaultSlowThreshold + time.Millisecond)
|
||||
}
|
||||
|
||||
err := errMockedPlaceholder
|
||||
|
||||
@@ -19,6 +19,12 @@ type (
|
||||
}
|
||||
)
|
||||
|
||||
// NewSessionFromTx returns a Session with the given sql.Tx.
|
||||
// Use it with caution, it's provided for other ORM to interact with.
|
||||
func NewSessionFromTx(tx *sql.Tx) Session {
|
||||
return txSession{Tx: tx}
|
||||
}
|
||||
|
||||
func (t txSession) Exec(q string, args ...interface{}) (sql.Result, error) {
|
||||
return exec(t.Tx, q, args...)
|
||||
}
|
||||
|
||||
@@ -41,3 +41,10 @@ func TestFakeTicker(t *testing.T) {
|
||||
assert.Nil(t, ticker.Wait(time.Second))
|
||||
assert.Equal(t, int32(total), atomic.LoadInt32(&count))
|
||||
}
|
||||
|
||||
func TestFakeTickerTimeout(t *testing.T) {
|
||||
ticker := NewFakeTicker()
|
||||
defer ticker.Stop()
|
||||
|
||||
assert.NotNil(t, ticker.Wait(time.Millisecond))
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"fmt"
|
||||
"sync"
|
||||
|
||||
"github.com/tal-tech/go-zero/core/lang"
|
||||
"github.com/tal-tech/go-zero/core/logx"
|
||||
"go.opentelemetry.io/otel"
|
||||
"go.opentelemetry.io/otel/exporters/jaeger"
|
||||
@@ -19,17 +20,31 @@ const (
|
||||
kindZipkin = "zipkin"
|
||||
)
|
||||
|
||||
var once sync.Once
|
||||
var (
|
||||
agents = make(map[string]lang.PlaceholderType)
|
||||
lock sync.Mutex
|
||||
)
|
||||
|
||||
// StartAgent starts a opentelemetry agent.
|
||||
func StartAgent(c Config) {
|
||||
once.Do(func() {
|
||||
startAgent(c)
|
||||
})
|
||||
lock.Lock()
|
||||
defer lock.Unlock()
|
||||
|
||||
_, ok := agents[c.Endpoint]
|
||||
if ok {
|
||||
return
|
||||
}
|
||||
|
||||
// if error happens, let later calls run.
|
||||
if err := startAgent(c); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
agents[c.Endpoint] = lang.Placeholder
|
||||
}
|
||||
|
||||
func createExporter(c Config) (sdktrace.SpanExporter, error) {
|
||||
// Just support jaeger now, more for later
|
||||
// Just support jaeger and zipkin now, more for later
|
||||
switch c.Batcher {
|
||||
case kindJaeger:
|
||||
return jaeger.New(jaeger.WithCollectorEndpoint(jaeger.WithEndpoint(c.Endpoint)))
|
||||
@@ -40,7 +55,7 @@ func createExporter(c Config) (sdktrace.SpanExporter, error) {
|
||||
}
|
||||
}
|
||||
|
||||
func startAgent(c Config) {
|
||||
func startAgent(c Config) error {
|
||||
opts := []sdktrace.TracerProviderOption{
|
||||
// Set the sampling rate based on the parent span to 100%
|
||||
sdktrace.WithSampler(sdktrace.ParentBased(sdktrace.TraceIDRatioBased(c.Sampler))),
|
||||
@@ -52,7 +67,7 @@ func startAgent(c Config) {
|
||||
exp, err := createExporter(c)
|
||||
if err != nil {
|
||||
logx.Error(err)
|
||||
return
|
||||
return err
|
||||
}
|
||||
|
||||
// Always be sure to batch in production.
|
||||
@@ -66,4 +81,6 @@ func startAgent(c Config) {
|
||||
otel.SetErrorHandler(otel.ErrorHandlerFunc(func(err error) {
|
||||
logx.Errorf("[otel] error: %v", err)
|
||||
}))
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
54
core/trace/agent_test.go
Normal file
54
core/trace/agent_test.go
Normal file
@@ -0,0 +1,54 @@
|
||||
package trace
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/tal-tech/go-zero/core/logx"
|
||||
)
|
||||
|
||||
func TestStartAgent(t *testing.T) {
|
||||
logx.Disable()
|
||||
|
||||
const (
|
||||
endpoint1 = "localhost:1234"
|
||||
endpoint2 = "remotehost:1234"
|
||||
endpoint3 = "localhost:1235"
|
||||
)
|
||||
c1 := Config{
|
||||
Name: "foo",
|
||||
}
|
||||
c2 := Config{
|
||||
Name: "bar",
|
||||
Endpoint: endpoint1,
|
||||
Batcher: kindJaeger,
|
||||
}
|
||||
c3 := Config{
|
||||
Name: "any",
|
||||
Endpoint: endpoint2,
|
||||
Batcher: kindZipkin,
|
||||
}
|
||||
c4 := Config{
|
||||
Name: "bla",
|
||||
Endpoint: endpoint3,
|
||||
Batcher: "otlp",
|
||||
}
|
||||
|
||||
StartAgent(c1)
|
||||
StartAgent(c1)
|
||||
StartAgent(c2)
|
||||
StartAgent(c3)
|
||||
StartAgent(c4)
|
||||
|
||||
lock.Lock()
|
||||
defer lock.Unlock()
|
||||
|
||||
// because remotehost cannot be resolved
|
||||
assert.Equal(t, 2, len(agents))
|
||||
_, ok := agents[""]
|
||||
assert.True(t, ok)
|
||||
_, ok = agents[endpoint1]
|
||||
assert.True(t, ok)
|
||||
_, ok = agents[endpoint2]
|
||||
assert.False(t, ok)
|
||||
}
|
||||
@@ -34,7 +34,7 @@ var (
|
||||
RPCMessageTypeReceived = RPCMessageTypeKey.String("RECEIVED")
|
||||
)
|
||||
|
||||
// StatusCodeAttr returns a attribute.KeyValue that represents the give c.
|
||||
// StatusCodeAttr returns an attribute.KeyValue that represents the give c.
|
||||
func StatusCodeAttr(c gcodes.Code) attribute.KeyValue {
|
||||
return GRPCStatusCodeKey.Int64(int64(c))
|
||||
}
|
||||
|
||||
12
core/trace/attributes_test.go
Normal file
12
core/trace/attributes_test.go
Normal file
@@ -0,0 +1,12 @@
|
||||
package trace
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
gcodes "google.golang.org/grpc/codes"
|
||||
)
|
||||
|
||||
func TestStatusCodeAttr(t *testing.T) {
|
||||
assert.Equal(t, GRPCStatusCodeKey.Int(int(gcodes.DataLoss)), StatusCodeAttr(gcodes.DataLoss))
|
||||
}
|
||||
@@ -157,7 +157,8 @@ func TestExtractValidTraceContext(t *testing.T) {
|
||||
}),
|
||||
},
|
||||
}
|
||||
otel.SetTextMapPropagator(propagation.NewCompositeTextMapPropagator(propagation.TraceContext{}, propagation.Baggage{}))
|
||||
otel.SetTextMapPropagator(propagation.NewCompositeTextMapPropagator(
|
||||
propagation.TraceContext{}, propagation.Baggage{}))
|
||||
propagator := otel.GetTextMapPropagator()
|
||||
|
||||
for _, tt := range tests {
|
||||
@@ -242,7 +243,8 @@ func TestExtractInvalidTraceContext(t *testing.T) {
|
||||
header: "00-4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-",
|
||||
},
|
||||
}
|
||||
otel.SetTextMapPropagator(propagation.NewCompositeTextMapPropagator(propagation.TraceContext{}, propagation.Baggage{}))
|
||||
otel.SetTextMapPropagator(propagation.NewCompositeTextMapPropagator(
|
||||
propagation.TraceContext{}, propagation.Baggage{}))
|
||||
propagator := otel.GetTextMapPropagator()
|
||||
|
||||
for _, tt := range tests {
|
||||
@@ -308,7 +310,8 @@ func TestInjectValidTraceContext(t *testing.T) {
|
||||
}),
|
||||
},
|
||||
}
|
||||
otel.SetTextMapPropagator(propagation.NewCompositeTextMapPropagator(propagation.TraceContext{}, propagation.Baggage{}))
|
||||
otel.SetTextMapPropagator(propagation.NewCompositeTextMapPropagator(
|
||||
propagation.TraceContext{}, propagation.Baggage{}))
|
||||
propagator := otel.GetTextMapPropagator()
|
||||
|
||||
for _, tt := range tests {
|
||||
@@ -325,6 +328,11 @@ func TestInjectValidTraceContext(t *testing.T) {
|
||||
md := metadata.MD{}
|
||||
Inject(ctx, propagator, &md)
|
||||
assert.Equal(t, want, md)
|
||||
|
||||
mm := &metadataSupplier{
|
||||
metadata: &md,
|
||||
}
|
||||
assert.NotEmpty(t, mm.Keys())
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -334,7 +342,8 @@ func TestInvalidSpanContextDropped(t *testing.T) {
|
||||
require.False(t, invalidSC.IsValid())
|
||||
ctx := trace.ContextWithRemoteSpanContext(context.Background(), invalidSC)
|
||||
|
||||
otel.SetTextMapPropagator(propagation.NewCompositeTextMapPropagator(propagation.TraceContext{}, propagation.Baggage{}))
|
||||
otel.SetTextMapPropagator(propagation.NewCompositeTextMapPropagator(
|
||||
propagation.TraceContext{}, propagation.Baggage{}))
|
||||
propagator := otel.GetTextMapPropagator()
|
||||
|
||||
md := metadata.MD{}
|
||||
@@ -342,5 +351,6 @@ func TestInvalidSpanContextDropped(t *testing.T) {
|
||||
mm := &metadataSupplier{
|
||||
metadata: &md,
|
||||
}
|
||||
assert.Empty(t, mm.Keys())
|
||||
assert.Equal(t, "", mm.Get("traceparent"), "injected invalid SpanContext")
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ const localhost = "127.0.0.1"
|
||||
// PeerFromCtx returns the peer from ctx.
|
||||
func PeerFromCtx(ctx context.Context) string {
|
||||
p, ok := peer.FromContext(ctx)
|
||||
if !ok {
|
||||
if !ok || p == nil {
|
||||
return ""
|
||||
}
|
||||
|
||||
@@ -55,7 +55,7 @@ func ParseFullMethod(fullMethod string) (string, []attribute.KeyValue) {
|
||||
func PeerAttr(addr string) []attribute.KeyValue {
|
||||
host, port, err := net.SplitHostPort(addr)
|
||||
if err != nil {
|
||||
return []attribute.KeyValue(nil)
|
||||
return nil
|
||||
}
|
||||
|
||||
if len(host) == 0 {
|
||||
|
||||
@@ -1,13 +1,53 @@
|
||||
package trace
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"go.opentelemetry.io/otel/attribute"
|
||||
semconv "go.opentelemetry.io/otel/semconv/v1.4.0"
|
||||
"google.golang.org/grpc/peer"
|
||||
)
|
||||
|
||||
func TestPeerFromContext(t *testing.T) {
|
||||
addrs, err := net.InterfaceAddrs()
|
||||
assert.Nil(t, err)
|
||||
assert.NotEmpty(t, addrs)
|
||||
tests := []struct {
|
||||
name string
|
||||
ctx context.Context
|
||||
empty bool
|
||||
}{
|
||||
{
|
||||
name: "empty",
|
||||
ctx: context.Background(),
|
||||
empty: true,
|
||||
},
|
||||
{
|
||||
name: "nil",
|
||||
ctx: peer.NewContext(context.Background(), nil),
|
||||
empty: true,
|
||||
},
|
||||
{
|
||||
name: "with value",
|
||||
ctx: peer.NewContext(context.Background(), &peer.Peer{
|
||||
Addr: addrs[0],
|
||||
}),
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
test := test
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
addr := PeerFromCtx(test.ctx)
|
||||
assert.Equal(t, test.empty, len(addr) == 0)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseFullMethod(t *testing.T) {
|
||||
tests := []struct {
|
||||
fullMethod string
|
||||
@@ -68,3 +108,46 @@ func TestParseFullMethod(t *testing.T) {
|
||||
assert.Equal(t, test.attr, a)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSpanInfo(t *testing.T) {
|
||||
val, kvs := SpanInfo("/fullMethod", "remote")
|
||||
assert.Equal(t, "fullMethod", val)
|
||||
assert.NotEmpty(t, kvs)
|
||||
}
|
||||
|
||||
func TestPeerAttr(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
addr string
|
||||
expect []attribute.KeyValue
|
||||
}{
|
||||
{
|
||||
name: "empty",
|
||||
},
|
||||
{
|
||||
name: "port only",
|
||||
addr: ":8080",
|
||||
expect: []attribute.KeyValue{
|
||||
semconv.NetPeerIPKey.String(localhost),
|
||||
semconv.NetPeerPortKey.String("8080"),
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "port only",
|
||||
addr: "192.168.0.2:8080",
|
||||
expect: []attribute.KeyValue{
|
||||
semconv.NetPeerIPKey.String("192.168.0.2"),
|
||||
semconv.NetPeerPortKey.String("8080"),
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
test := test
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
kvs := PeerAttr(test.addr)
|
||||
assert.EqualValues(t, test.expect, kvs)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
58
go.mod
58
go.mod
@@ -3,55 +3,51 @@ module github.com/tal-tech/go-zero
|
||||
go 1.14
|
||||
|
||||
require (
|
||||
github.com/ClickHouse/clickhouse-go v1.4.3
|
||||
github.com/DATA-DOG/go-sqlmock v1.4.1
|
||||
github.com/alicebob/miniredis/v2 v2.14.1
|
||||
github.com/cpuguy83/go-md2man/v2 v2.0.0 // indirect
|
||||
github.com/emicklei/proto v1.9.0
|
||||
github.com/ClickHouse/clickhouse-go v1.5.1
|
||||
github.com/DATA-DOG/go-sqlmock v1.5.0
|
||||
github.com/alicebob/miniredis/v2 v2.16.0
|
||||
github.com/cpuguy83/go-md2man/v2 v2.0.1 // indirect
|
||||
github.com/emicklei/proto v1.9.1
|
||||
github.com/fatih/color v1.9.0 // indirect
|
||||
github.com/fatih/structtag v1.2.0
|
||||
github.com/frankban/quicktest v1.7.2 // indirect
|
||||
github.com/globalsign/mgo v0.0.0-20181015135952-eeefdecb41b8
|
||||
github.com/go-redis/redis v6.15.7+incompatible
|
||||
github.com/go-sql-driver/mysql v1.5.0
|
||||
github.com/go-xorm/builder v0.3.4
|
||||
github.com/go-redis/redis v6.15.9+incompatible
|
||||
github.com/go-sql-driver/mysql v1.6.0
|
||||
github.com/golang-jwt/jwt v3.2.1+incompatible
|
||||
github.com/golang/mock v1.4.3
|
||||
github.com/google/uuid v1.1.2
|
||||
github.com/iancoleman/strcase v0.1.2
|
||||
github.com/golang/mock v1.6.0
|
||||
github.com/google/uuid v1.3.0
|
||||
github.com/iancoleman/strcase v0.2.0
|
||||
github.com/justinas/alice v1.2.0
|
||||
github.com/lib/pq v1.3.0
|
||||
github.com/lib/pq v1.10.3
|
||||
github.com/logrusorgru/aurora v2.0.3+incompatible
|
||||
github.com/mattn/go-colorable v0.1.6 // indirect
|
||||
github.com/olekukonko/tablewriter v0.0.5
|
||||
github.com/pierrec/lz4 v2.5.1+incompatible // indirect
|
||||
github.com/openzipkin/zipkin-go v0.3.0 // indirect
|
||||
github.com/prometheus/client_golang v1.11.0
|
||||
github.com/russross/blackfriday/v2 v2.1.0 // indirect
|
||||
github.com/spaolacci/murmur3 v1.1.0
|
||||
github.com/stretchr/testify v1.7.0
|
||||
github.com/urfave/cli v1.22.5
|
||||
github.com/zeromicro/antlr v0.0.1
|
||||
github.com/zeromicro/ddl-parser v0.0.0-20210712021150-63520aca7348
|
||||
github.com/zeromicro/protobuf v0.0.0-20210921042113-636cd51f0c35
|
||||
go.etcd.io/etcd/api/v3 v3.5.0
|
||||
go.etcd.io/etcd/client/v3 v3.5.0
|
||||
go.opentelemetry.io/otel v1.0.1
|
||||
go.opentelemetry.io/otel/exporters/jaeger v1.0.1
|
||||
go.opentelemetry.io/otel/exporters/zipkin v1.0.1
|
||||
go.opentelemetry.io/otel/sdk v1.0.1
|
||||
go.opentelemetry.io/otel/trace v1.0.1
|
||||
go.uber.org/automaxprocs v1.3.0
|
||||
go.etcd.io/etcd/api/v3 v3.5.1
|
||||
go.etcd.io/etcd/client/v3 v3.5.1
|
||||
go.opentelemetry.io/otel v1.1.0
|
||||
go.opentelemetry.io/otel/exporters/jaeger v1.1.0
|
||||
go.opentelemetry.io/otel/exporters/zipkin v1.1.0
|
||||
go.opentelemetry.io/otel/sdk v1.1.0
|
||||
go.opentelemetry.io/otel/trace v1.1.0
|
||||
go.uber.org/automaxprocs v1.4.0
|
||||
golang.org/x/net v0.0.0-20210928044308-7d9f5e0b762b // indirect
|
||||
golang.org/x/sys v0.0.0-20211002104244-808efd93c36d // indirect
|
||||
golang.org/x/text v0.3.7 // indirect
|
||||
golang.org/x/sys v0.0.0-20211106132015-ebca88c72f68 // indirect
|
||||
golang.org/x/time v0.0.0-20210723032227-1f47c861a9ac
|
||||
google.golang.org/genproto v0.0.0-20210928142010-c7af6a1a74c9 // indirect
|
||||
google.golang.org/grpc v1.41.0
|
||||
google.golang.org/grpc v1.42.0
|
||||
google.golang.org/protobuf v1.27.1
|
||||
gopkg.in/cheggaaa/pb.v1 v1.0.28
|
||||
gopkg.in/h2non/gock.v1 v1.0.15
|
||||
gopkg.in/h2non/gock.v1 v1.1.2
|
||||
gopkg.in/yaml.v2 v2.4.0
|
||||
k8s.io/api v0.20.10
|
||||
k8s.io/apimachinery v0.20.10
|
||||
k8s.io/client-go v0.20.10
|
||||
k8s.io/api v0.20.12
|
||||
k8s.io/apimachinery v0.20.12
|
||||
k8s.io/client-go v0.20.12
|
||||
k8s.io/utils v0.0.0-20201110183641-67b214c5f920
|
||||
)
|
||||
|
||||
191
go.sum
191
go.sum
@@ -32,16 +32,18 @@ github.com/Azure/go-autorest/logger v0.2.0/go.mod h1:T9E3cAhj2VqvPOtCYAvby9aBXkZ
|
||||
github.com/Azure/go-autorest/tracing v0.6.0/go.mod h1:+vhtPC754Xsa23ID7GlGsrdKBpUA79WCAKPPZVC2DeU=
|
||||
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
|
||||
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
|
||||
github.com/ClickHouse/clickhouse-go v1.4.3 h1:iAFMa2UrQdR5bHJ2/yaSLffZkxpcOYQMCUuKeNXGdqc=
|
||||
github.com/ClickHouse/clickhouse-go v1.4.3/go.mod h1:EaI/sW7Azgz9UATzd5ZdZHRUhHgv5+JMS9NSr2smCJI=
|
||||
github.com/DATA-DOG/go-sqlmock v1.4.1 h1:ThlnYciV1iM/V0OSF/dtkqWb6xo5qITT1TJBG1MRDJM=
|
||||
github.com/DATA-DOG/go-sqlmock v1.4.1/go.mod h1:f/Ixk793poVmq4qj/V1dPUg2JEAKC73Q5eFN3EC/SaM=
|
||||
github.com/ClickHouse/clickhouse-go v1.5.1 h1:I8zVFZTz80crCs0FFEBJooIxsPcV0xfthzK1YrkpJTc=
|
||||
github.com/ClickHouse/clickhouse-go v1.5.1/go.mod h1:EaI/sW7Azgz9UATzd5ZdZHRUhHgv5+JMS9NSr2smCJI=
|
||||
github.com/DATA-DOG/go-sqlmock v1.5.0 h1:Shsta01QNfFxHCfpW6YH2STWB0MudeXXEWMr20OEh60=
|
||||
github.com/DATA-DOG/go-sqlmock v1.5.0/go.mod h1:f/Ixk793poVmq4qj/V1dPUg2JEAKC73Q5eFN3EC/SaM=
|
||||
github.com/NYTimes/gziphandler v0.0.0-20170623195520-56545f4a5d46/go.mod h1:3wb06e3pkSAbeQ52E9H9iFoQsEEwGN64994WTCIhntQ=
|
||||
github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU=
|
||||
github.com/PuerkitoBio/purell v1.1.1/go.mod h1:c11w/QuzBsJSee3cPx9rAFu61PvFxuPbtSwDGJws/X0=
|
||||
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578/go.mod h1:uGdkoq3SwY9Y+13GIhn11/XLaGBb4BfwItxLd5jeuXE=
|
||||
github.com/Shopify/sarama v1.19.0/go.mod h1:FVkBWblsNy7DGZRfXLU0O9RCGt5g3g3yEuWXgklEdEo=
|
||||
github.com/Shopify/sarama v1.30.0/go.mod h1:zujlQQx1kzHsh4jfV1USnptCQrHAEZ2Hk8fTKCulPVs=
|
||||
github.com/Shopify/toxiproxy v2.1.4+incompatible/go.mod h1:OXgGpZ6Cli1/URJOF1DMxUHB2q5Ap20/P/eIdh4G0pI=
|
||||
github.com/Shopify/toxiproxy/v2 v2.1.6-0.20210914104332-15ea381dcdae/go.mod h1:/cvHQkZ1fst0EmZnA5dFtiQdWCNCFYzb+uE2vqVgvx0=
|
||||
github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
|
||||
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
|
||||
github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=
|
||||
@@ -49,8 +51,8 @@ github.com/alecthomas/units v0.0.0-20190717042225-c3de453c63f4/go.mod h1:ybxpYRF
|
||||
github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d/go.mod h1:rBZYJk541a8SKzHPHnH3zbiI+7dagKZ0cgpgrD7Fyho=
|
||||
github.com/alicebob/gopher-json v0.0.0-20200520072559-a9ecdc9d1d3a h1:HbKu58rmZpUGpz5+4FfNmIU+FmZg2P3Xaj2v2bfNWmk=
|
||||
github.com/alicebob/gopher-json v0.0.0-20200520072559-a9ecdc9d1d3a/go.mod h1:SGnFV6hVsYE877CKEZ6tDNTjaSXYUk6QqoIK6PrAtcc=
|
||||
github.com/alicebob/miniredis/v2 v2.14.1 h1:GjlbSeoJ24bzdLRs13HoMEeaRZx9kg5nHoRW7QV/nCs=
|
||||
github.com/alicebob/miniredis/v2 v2.14.1/go.mod h1:uS970Sw5Gs9/iK3yBg0l9Uj9s25wXxSpQUE9EaJ/Blg=
|
||||
github.com/alicebob/miniredis/v2 v2.16.0 h1:ALkyFg7bSTEd1Mkrb4ppq4fnwjklA59dVtIehXCUZkU=
|
||||
github.com/alicebob/miniredis/v2 v2.16.0/go.mod h1:gquAfGbzn92jvtrSC69+6zZnwSODVXVpYDRaGhWaL6I=
|
||||
github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kdvxnR2qWY=
|
||||
github.com/antlr/antlr4/runtime/Go/antlr v0.0.0-20210521184019-c5ad59b459ec h1:EEyRvzmpEUZ+I8WmD5cw/vY8EqhambkOqy5iFr0908A=
|
||||
github.com/antlr/antlr4/runtime/Go/antlr v0.0.0-20210521184019-c5ad59b459ec/go.mod h1:F7bn7fEU90QkQ3tnmaTx3LTKLEDqnwWODIYppRQ5hnY=
|
||||
@@ -74,15 +76,19 @@ github.com/cloudflare/golz4 v0.0.0-20150217214814-ef862a3cdc58 h1:F1EaeKL/ta07PY
|
||||
github.com/cloudflare/golz4 v0.0.0-20150217214814-ef862a3cdc58/go.mod h1:EOBUe0h4xcZ5GoxqC5SDxFQ8gwyZPKQoEzownBlhI80=
|
||||
github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc=
|
||||
github.com/cncf/udpa/go v0.0.0-20201120205902-5459f2c99403/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk=
|
||||
github.com/cncf/udpa/go v0.0.0-20210930031921-04548b0d99d4/go.mod h1:6pvJx4me5XPnfI9Z40ddWsdw2W/uZgQLFXToKeRcDiI=
|
||||
github.com/cncf/xds/go v0.0.0-20210312221358-fbca930ec8ed/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs=
|
||||
github.com/cncf/xds/go v0.0.0-20210805033703-aa0b78936158/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs=
|
||||
github.com/cncf/xds/go v0.0.0-20210922020428-25de7278fc84/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs=
|
||||
github.com/cncf/xds/go v0.0.0-20211011173535-cb28da3451f1/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs=
|
||||
github.com/coreos/go-semver v0.3.0 h1:wkHLiw0WNATZnSG7epLsujiMCgPAc9xhjJ4tgnAxmfM=
|
||||
github.com/coreos/go-semver v0.3.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk=
|
||||
github.com/coreos/go-systemd/v22 v22.3.2 h1:D9/bQk5vlXQFZ6Kwuu6zaiXJ9oTPe68++AzAJc1DzSI=
|
||||
github.com/coreos/go-systemd/v22 v22.3.2/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc=
|
||||
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
|
||||
github.com/cpuguy83/go-md2man/v2 v2.0.0 h1:EoUDS0afbrsXAZ9YQ9jdu/mZ2sXgT1/2yyNng4PGlyM=
|
||||
github.com/cpuguy83/go-md2man/v2 v2.0.0/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
|
||||
github.com/cpuguy83/go-md2man/v2 v2.0.1 h1:r/myEWzV9lfsM1tFLgDyu0atFtJ1fXn261LKYj/3DxU=
|
||||
github.com/cpuguy83/go-md2man/v2 v2.0.1/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
|
||||
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
|
||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
@@ -91,12 +97,13 @@ github.com/docker/spdystream v0.0.0-20160310174837-449fdfce4d96/go.mod h1:Qh8CwZ
|
||||
github.com/docopt/docopt-go v0.0.0-20180111231733-ee0de3bc6815/go.mod h1:WwZ+bS3ebgob9U8Nd0kOddGdZWjyMGR8Wziv+TBNwSE=
|
||||
github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk=
|
||||
github.com/eapache/go-resiliency v1.1.0/go.mod h1:kFI+JgMyC7bLPUVY133qvEBtVayf5mFgVsvEsIPBvNs=
|
||||
github.com/eapache/go-resiliency v1.2.0/go.mod h1:kFI+JgMyC7bLPUVY133qvEBtVayf5mFgVsvEsIPBvNs=
|
||||
github.com/eapache/go-xerial-snappy v0.0.0-20180814174437-776d5712da21/go.mod h1:+020luEh2TKB4/GOp8oxxtq0Daoen/Cii55CzbTV6DU=
|
||||
github.com/eapache/queue v1.1.0/go.mod h1:6eCeP0CKFpHLu8blIFXhExK/dRa7WDZfr6jVFPTqq+I=
|
||||
github.com/elazarl/goproxy v0.0.0-20180725130230-947c36da3153/go.mod h1:/Zj4wYkgs4iZTTu3o/KG3Itv/qCCa8VVMlb3i9OVuzc=
|
||||
github.com/emicklei/go-restful v0.0.0-20170410110728-ff4f55a20633/go.mod h1:otzb+WCGbkyDHkqmQmT5YD2WR4BBwUdeQoFo8l/7tVs=
|
||||
github.com/emicklei/proto v1.9.0 h1:l0QiNT6Qs7Yj0Mb4X6dnWBQer4ebei2BFcgQLbGqUDc=
|
||||
github.com/emicklei/proto v1.9.0/go.mod h1:rn1FgRS/FANiZdD2djyH7TMA9jdRDcYQ9IEN9yvjX0A=
|
||||
github.com/emicklei/proto v1.9.1 h1:MUgjFo5xlMwYv72TnF5xmmdKZ04u+dVbv6wdARv16D8=
|
||||
github.com/emicklei/proto v1.9.1/go.mod h1:rn1FgRS/FANiZdD2djyH7TMA9jdRDcYQ9IEN9yvjX0A=
|
||||
github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
|
||||
github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
|
||||
github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98=
|
||||
@@ -111,8 +118,9 @@ github.com/fatih/color v1.9.0/go.mod h1:eQcE1qtQxscV5RaZvpXrrb8Drkc3/DdQ+uUYCNjL
|
||||
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/form3tech-oss/jwt-go v3.2.2+incompatible/go.mod h1:pbq4aXjuKjdthFRnoDwaVPLA+WlJuPGy+QneDUgJi2k=
|
||||
github.com/frankban/quicktest v1.7.2 h1:2QxQoC1TS09S7fhCPsrvqYdvP1H5M1P1ih5ABm3BTYk=
|
||||
github.com/frankban/quicktest v1.7.2/go.mod h1:jaStnuzAqU1AJdCO0l53JDCJrVDKcS03DbaAcR7Ks/o=
|
||||
github.com/fortytw2/leaktest v1.3.0/go.mod h1:jDsjWgpAGjm2CA7WthBh/CdZYEPF31XHquHwclZch5g=
|
||||
github.com/frankban/quicktest v1.11.3 h1:8sXhOn0uLys67V8EsXLc6eszDs8VXWxL3iRvebPhedY=
|
||||
github.com/frankban/quicktest v1.11.3/go.mod h1:wRf/ReqHper53s+kmmSZizM8NamnL3IM0I9ntUbOk+k=
|
||||
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
|
||||
github.com/fsnotify/fsnotify v1.4.9 h1:hsms1Qyu0jgnwNXIxa+/V/PDsU6CfLf6CNO8H7IWoS4=
|
||||
github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ=
|
||||
@@ -139,16 +147,13 @@ github.com/go-openapi/jsonreference v0.19.3/go.mod h1:rjx6GuL8TTa9VaixXglHmQmIL9
|
||||
github.com/go-openapi/spec v0.19.3/go.mod h1:FpwSN1ksY1eteniUU7X0N/BgJ7a4WvBFVA8Lj9mJglo=
|
||||
github.com/go-openapi/swag v0.19.2/go.mod h1:POnQmlKehdgb5mhVOsnJFsivZCEZ/vjK9gh66Z9tfKk=
|
||||
github.com/go-openapi/swag v0.19.5/go.mod h1:POnQmlKehdgb5mhVOsnJFsivZCEZ/vjK9gh66Z9tfKk=
|
||||
github.com/go-redis/redis v6.15.7+incompatible h1:3skhDh95XQMpnqeqNftPkQD9jL9e5e36z/1SUm6dy1U=
|
||||
github.com/go-redis/redis v6.15.7+incompatible/go.mod h1:NAIEuMOZ/fxfXJIrKDQDz8wamY7mA7PouImQ2Jvg6kA=
|
||||
github.com/go-redis/redis v6.15.9+incompatible h1:K0pv1D7EQUjfyoMql+r/jZqCLizCGKFlFgcHWWmHQjg=
|
||||
github.com/go-redis/redis v6.15.9+incompatible/go.mod h1:NAIEuMOZ/fxfXJIrKDQDz8wamY7mA7PouImQ2Jvg6kA=
|
||||
github.com/go-sql-driver/mysql v1.4.0/go.mod h1:zAC/RDZ24gD3HViQzih4MyKcchzm+sOG5ZlKdlhCg5w=
|
||||
github.com/go-sql-driver/mysql v1.5.0 h1:ozyZYNQW3x3HtqT1jira07DN2PArx2v7/mN66gGcHOs=
|
||||
github.com/go-sql-driver/mysql v1.5.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg=
|
||||
github.com/go-sql-driver/mysql v1.6.0 h1:BCTh4TKNUYmOmMUcQ3IipzF5prigylS7XXjEkfCHuOE=
|
||||
github.com/go-sql-driver/mysql v1.6.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg=
|
||||
github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY=
|
||||
github.com/go-xorm/builder v0.3.4 h1:FxkeGB4Cggdw3tPwutLCpfjng2jugfkg6LDMrd/KsoY=
|
||||
github.com/go-xorm/builder v0.3.4/go.mod h1:KxkQkNN1DpPKTedxXyTQcmH+rXfvk4LZ9SOOBoZBAxw=
|
||||
github.com/go-xorm/sqlfiddle v0.0.0-20180821085327-62ce714f951a h1:9wScpmSP5A3Bk8V3XHWUcJmYTh+ZnlHVyc+A4oZYS3Y=
|
||||
github.com/go-xorm/sqlfiddle v0.0.0-20180821085327-62ce714f951a/go.mod h1:56xuuqnHyryaerycW3BfssRdxQstACi0Epw/yC5E2xM=
|
||||
github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0/go.mod h1:fyg7847qk6SyHyPtNmDHnmrv/HOrqktSC+C9fM+CJOE=
|
||||
github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
|
||||
github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ=
|
||||
github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q=
|
||||
@@ -165,8 +170,8 @@ github.com/golang/mock v1.2.0/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfb
|
||||
github.com/golang/mock v1.3.1/go.mod h1:sBzyDLLjw3U8JLTeZvSv8jJB+tU5PVekmnlKIyFUx0Y=
|
||||
github.com/golang/mock v1.4.0/go.mod h1:UOMv5ysSaYNkG+OFQykRIcU/QvvxJf3p21QfJ2Bt3cw=
|
||||
github.com/golang/mock v1.4.1/go.mod h1:UOMv5ysSaYNkG+OFQykRIcU/QvvxJf3p21QfJ2Bt3cw=
|
||||
github.com/golang/mock v1.4.3 h1:GV+pQPG/EUUbkh47niozDcADz6go/dUwhVzdUQHIVRw=
|
||||
github.com/golang/mock v1.4.3/go.mod h1:UOMv5ysSaYNkG+OFQykRIcU/QvvxJf3p21QfJ2Bt3cw=
|
||||
github.com/golang/mock v1.6.0 h1:ErTB+efbowRARo13NNdxyJji2egdxLGQhRaY+DUumQc=
|
||||
github.com/golang/mock v1.6.0/go.mod h1:p6yTPP+5HYm5mzsMV8JkE6ZKdX+/wYM6Hr+LicevLPs=
|
||||
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
|
||||
github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
|
||||
github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
|
||||
@@ -184,6 +189,7 @@ github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaS
|
||||
github.com/golang/protobuf v1.5.2 h1:ROPKBNFfQgOUMifHyP+KYbvpjbdoFNs+aK7DXlji0Tw=
|
||||
github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
|
||||
github.com/golang/snappy v0.0.0-20180518054509-2e65f85255db/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
|
||||
github.com/golang/snappy v0.0.4/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
|
||||
github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ=
|
||||
github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ=
|
||||
github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
|
||||
@@ -207,28 +213,38 @@ github.com/google/pprof v0.0.0-20200212024743-f11f1df84d12/go.mod h1:ZgVRPoUq/hf
|
||||
github.com/google/pprof v0.0.0-20200229191704-1ebb73c60ed3/go.mod h1:ZgVRPoUq/hfqzAqh7sHMqb3I9Rq5C59dIz2SbBwJ4eM=
|
||||
github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI=
|
||||
github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||
github.com/google/uuid v1.1.2 h1:EVhdT+1Kseyi1/pUmXKaFxYsDNy9RQYkMWRH68J/W7Y=
|
||||
github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||
github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I=
|
||||
github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||
github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg=
|
||||
github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5mhpdKc/us6bOk=
|
||||
github.com/googleapis/gnostic v0.4.1 h1:DLJCy1n/vrD4HPjOvYcT8aYQXpPIzoRZONaYwyycI+I=
|
||||
github.com/googleapis/gnostic v0.4.1/go.mod h1:LRhVm6pbyptWbWbuZ38d1eyptfvIytN3ir6b65WBswg=
|
||||
github.com/gorilla/context v1.1.1/go.mod h1:kBGZzfjB9CEq2AlWe17Uuf7NDRt0dE0s8S51q0aT7Yg=
|
||||
github.com/gorilla/mux v1.6.2/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2zaAs=
|
||||
github.com/gorilla/mux v1.8.0/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So=
|
||||
github.com/gorilla/securecookie v1.1.1/go.mod h1:ra0sb63/xPlUeL+yeDciTfxMRAA+MP+HVt/4epWDjd4=
|
||||
github.com/gorilla/sessions v1.2.1/go.mod h1:dk2InVEVJ0sfLlnXv9EAgkf6ecYs/i80K/zI+bUmuGM=
|
||||
github.com/gregjones/httpcache v0.0.0-20180305231024-9cad4c3443a7/go.mod h1:FecbI9+v66THATjSRHfNgh1IVFe/9kFxbXtjV0ctIMA=
|
||||
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0/go.mod h1:8NvIoxWQoOIhqOTXgfV/d3M/q6VIi02HzZEHgUlZvzk=
|
||||
github.com/grpc-ecosystem/grpc-gateway v1.16.0/go.mod h1:BDjrQk3hbvj6Nolgz8mAMFbcEtjT1g+wF4CSlocrBnw=
|
||||
github.com/h2non/parth v0.0.0-20190131123155-b4df798d6542 h1:2VTzZjLZBgl62/EtslCrtky5vbi9dd7HrQPQIx6wqiw=
|
||||
github.com/h2non/parth v0.0.0-20190131123155-b4df798d6542/go.mod h1:Ow0tF8D4Kplbc8s8sSb3V2oUCygFHVp8gC3Dn6U4MNI=
|
||||
github.com/hashicorp/go-uuid v1.0.2/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro=
|
||||
github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
|
||||
github.com/hashicorp/golang-lru v0.5.1 h1:0hERBMJE1eitiLkihrMvRVBYAkpHzc/J3QdDN+dAcgU=
|
||||
github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
|
||||
github.com/hpcloud/tail v1.0.0 h1:nfCOvKYfkgYP8hkirhJocXT2+zOD8yUNjXaWfTlyFKI=
|
||||
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
|
||||
github.com/iancoleman/strcase v0.1.2 h1:gnomlvw9tnV3ITTAxzKSgTF+8kFWcU/f+TgttpXGz1U=
|
||||
github.com/iancoleman/strcase v0.1.2/go.mod h1:SK73tn/9oHe+/Y0h39VT4UCxmurVJkR5NA7kMEAOgSE=
|
||||
github.com/iancoleman/strcase v0.2.0 h1:05I4QRnGpI0m37iZQRuskXh+w77mr6Z41lwQzuHLwW0=
|
||||
github.com/iancoleman/strcase v0.2.0/go.mod h1:iwCmte+B7n89clKwxIoIXy/HfoL7AsD47ZCWhYzw7ho=
|
||||
github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
|
||||
github.com/imdario/mergo v0.3.5/go.mod h1:2EnlNZ0deacrJVfApfmtdGgDfMuh/nq6Ok1EcJh5FfA=
|
||||
github.com/jcmturner/aescts/v2 v2.0.0/go.mod h1:AiaICIRyfYg35RUkr8yESTqvSy7csK90qZ5xfvvsoNs=
|
||||
github.com/jcmturner/dnsutils/v2 v2.0.0/go.mod h1:b0TnjGOvI/n42bZa+hmXL+kFJZsFT7G4t3HTlQ184QM=
|
||||
github.com/jcmturner/gofork v1.0.0/go.mod h1:MK8+TM0La+2rjBD4jE12Kj1pCCxK7d2LK/UM3ncEo0o=
|
||||
github.com/jcmturner/goidentity/v6 v6.0.1/go.mod h1:X1YW3bgtvwAXju7V3LCIMpY0Gbxyjn/mY9zx4tFonSg=
|
||||
github.com/jcmturner/gokrb5/v8 v8.4.2/go.mod h1:sb+Xq/fTY5yktf/VxLsE3wlfPqQjp0aWNYyvBVK62bc=
|
||||
github.com/jcmturner/rpc/v2 v2.0.3/go.mod h1:VUJYCIDm3PVOEHw8sgt091/20OJjskO/YJki3ELg/Hc=
|
||||
github.com/jmoiron/sqlx v1.2.0/go.mod h1:1FEQNm3xlJgrMD+FBdI9+xvCksHtbpVBBw5dYhBSsks=
|
||||
github.com/jpillora/backoff v1.0.0/go.mod h1:J/6gKK9jxlEcS3zixgDgUAsiuZ7yrSoa/FX5e0EB2j4=
|
||||
github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU=
|
||||
@@ -243,19 +259,22 @@ github.com/justinas/alice v1.2.0 h1:+MHSA/vccVCF4Uq37S42jwlkvI2Xzl7zTPCN5BnZNVo=
|
||||
github.com/justinas/alice v1.2.0/go.mod h1:fN5HRH/reO/zrUflLfTN43t3vXvKzvZIENsNEe7i7qA=
|
||||
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/compress v1.13.6/go.mod h1:/3/Vjq9QcHkK5uEr5lBEmyoZ1iFhe47etQ6QUkpK6sk=
|
||||
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
|
||||
github.com/konsorten/go-windows-terminal-sequences v1.0.3/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
|
||||
github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc=
|
||||
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
|
||||
github.com/kr/pretty v0.2.0 h1:s5hAObm+yFO5uHYt5dYjxi2rXrsnmRpJx4OYvIWUaQs=
|
||||
github.com/kr/pretty v0.2.0/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
|
||||
github.com/kr/pretty v0.2.1 h1:Fmg33tUaq4/8ym9TJN1x7sLJnHVwhP33CNkpYV/7rwI=
|
||||
github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
|
||||
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
|
||||
github.com/kr/pty v1.1.5/go.mod h1:9r2w37qlBe7rQ6e1fg1S/9xpWHSnaqNdHD3WcMdbPDA=
|
||||
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
|
||||
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
|
||||
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
|
||||
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
|
||||
github.com/lib/pq v1.0.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
|
||||
github.com/lib/pq v1.3.0 h1:/qkRGz8zljWiDcFvgpwUpwIAPu3r07TDvs3Rws+o/pU=
|
||||
github.com/lib/pq v1.3.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
|
||||
github.com/lib/pq v1.10.3 h1:v9QZf2Sn6AmjXtQeFpdoq/eaNtYP6IN+7lcrygsIAtg=
|
||||
github.com/lib/pq v1.10.3/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o=
|
||||
github.com/logrusorgru/aurora v2.0.3+incompatible h1:tOpm7WcpBTn4fjmVfgpQq0EfczGlG91VSDkswnjF5A8=
|
||||
github.com/logrusorgru/aurora v2.0.3+incompatible/go.mod h1:7rIyQOR62GCctdiQpZ/zOJlFyk6y+94wXzv6RNZgaR4=
|
||||
github.com/mailru/easyjson v0.0.0-20190614124828-94de47d64c63/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc=
|
||||
@@ -285,24 +304,34 @@ github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f/go.mod h1:qRW
|
||||
github.com/mxk/go-flowrate v0.0.0-20140419014527-cca7078d478f/go.mod h1:ZdcZmHo+o7JKHSa8/e818NopupXU1YMK5fe1lsApnBw=
|
||||
github.com/nbio/st v0.0.0-20140626010706-e9e8d9816f32 h1:W6apQkHrMkS0Muv8G/TipAy/FJl/rCYT0+EuS8+Z0z4=
|
||||
github.com/nbio/st v0.0.0-20140626010706-e9e8d9816f32/go.mod h1:9wM+0iRr9ahx58uYLpLIr5fm8diHn0JbqRycJi6w0Ms=
|
||||
github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A=
|
||||
github.com/nxadm/tail v1.4.8 h1:nPr65rt6Y5JFSKQO7qToXr7pePgD6Gwiw05lkbyAQTE=
|
||||
github.com/nxadm/tail v1.4.8/go.mod h1:+ncqLTQzXmGhMZNUePPaPqPvBxHAIsmXswZKocGu+AU=
|
||||
github.com/olekukonko/tablewriter v0.0.5 h1:P2Ga83D34wi1o9J6Wh1mRuqd4mF/x/lgBS7N7AbDhec=
|
||||
github.com/olekukonko/tablewriter v0.0.5/go.mod h1:hPp6KlRPjbx+hW8ykQs1w3UBbZlj6HuIJcUGPhkA7kY=
|
||||
github.com/onsi/ginkgo v0.0.0-20170829012221-11459a886d9c/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
|
||||
github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
|
||||
github.com/onsi/ginkgo v1.7.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
|
||||
github.com/onsi/ginkgo v1.11.0 h1:JAKSXpt1YjtLA7YpPiqO9ss6sNXEsPfSGdwN0UHqzrw=
|
||||
github.com/onsi/ginkgo v1.11.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
|
||||
github.com/onsi/ginkgo v1.12.1/go.mod h1:zj2OWP4+oCPe1qIXoGWkgMRwljMUYCdkwsT2108oapk=
|
||||
github.com/onsi/ginkgo v1.16.4/go.mod h1:dX+/inL/fNMqNlz0e9LfyB9TswhZpCVdJM/Z6Vvnwo0=
|
||||
github.com/onsi/ginkgo v1.16.5 h1:8xi0RTUf59SOSfEtZMvwTvXYMzG4gV23XVHOZiXNtnE=
|
||||
github.com/onsi/ginkgo v1.16.5/go.mod h1:+E8gABHa3K6zRBolWtd+ROzc/U5bkGt0FwiG042wbpU=
|
||||
github.com/onsi/gomega v0.0.0-20170829124025-dcabb60a477c/go.mod h1:C1qb7wdrVGGVU+Z6iS04AVkA3Q65CEZX59MT0QO5uiA=
|
||||
github.com/onsi/gomega v1.4.3/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY=
|
||||
github.com/onsi/gomega v1.7.0 h1:XPnZz8VVBHjVsy1vzJmRwIcSwiUO+JFfrv/xGiigmME=
|
||||
github.com/onsi/gomega v1.7.0/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY=
|
||||
github.com/openzipkin/zipkin-go v0.2.5 h1:UwtQQx2pyPIgWYHRg+epgdx1/HnBQTgN3/oIYEJTQzU=
|
||||
github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7JYyY=
|
||||
github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo=
|
||||
github.com/onsi/gomega v1.16.0 h1:6gjqkI8iiRHMvdccRJM8rVKjCWk6ZIm6FTm3ddIe4/c=
|
||||
github.com/onsi/gomega v1.16.0/go.mod h1:HnhC7FXeEQY45zxNK3PPoIUhzk/80Xly9PcubAlGdZY=
|
||||
github.com/openzipkin/zipkin-go v0.2.5/go.mod h1:KpXfKdgRDnnhsxw4pNIH9Md5lyFqKUa4YDFlwRYAMyE=
|
||||
github.com/openzipkin/zipkin-go v0.3.0 h1:XtuXmOLIXLjiU2XduuWREDT0LOKtSgos/g7i7RYyoZQ=
|
||||
github.com/openzipkin/zipkin-go v0.3.0/go.mod h1:4c3sLeE8xjNqehmF5RpAFLPLJxXscc0R4l6Zg0P1tTQ=
|
||||
github.com/peterbourgon/diskv v2.0.1+incompatible/go.mod h1:uqqh8zWWbv1HBMNONnaR/tNboyR3/BZd58JJSHlUSCU=
|
||||
github.com/pierrec/lz4 v1.0.2-0.20190131084431-473cd7ce01a1/go.mod h1:3/3N9NVKO0jef7pBehbT1qWhCMrIgbYNnFAZCqQ5LRc=
|
||||
github.com/pierrec/lz4 v2.0.5+incompatible/go.mod h1:pdkljMzZIN41W+lC3N2tnIh5sFi+IEE17M5jbnwPHcY=
|
||||
github.com/pierrec/lz4 v2.5.1+incompatible h1:Yq0up0149Hh5Ekhm/91lgkZuD1ZDnXNM26bycpTzYBM=
|
||||
github.com/pierrec/lz4 v2.5.1+incompatible/go.mod h1:pdkljMzZIN41W+lC3N2tnIh5sFi+IEE17M5jbnwPHcY=
|
||||
github.com/pierrec/lz4 v2.6.1+incompatible h1:9UY3+iC23yxF0UfGaYrGplQ+79Rg+h/q9FV9ix19jjM=
|
||||
github.com/pierrec/lz4 v2.6.1+incompatible/go.mod h1:pdkljMzZIN41W+lC3N2tnIh5sFi+IEE17M5jbnwPHcY=
|
||||
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
|
||||
@@ -329,7 +358,9 @@ github.com/prometheus/procfs v0.0.2/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsT
|
||||
github.com/prometheus/procfs v0.1.3/go.mod h1:lV6e/gmhEcM9IjHGsFOCxxuZ+z1YqCvr4OA4YeYWdaU=
|
||||
github.com/prometheus/procfs v0.6.0 h1:mxy4L2jP6qMonqmq+aTtOx1ifVWUgG/TAmntgbh3xv4=
|
||||
github.com/prometheus/procfs v0.6.0/go.mod h1:cz+aTbrPOrUb4q7XlbU9ygM+/jj0fzG6c1xBZuNvfVA=
|
||||
github.com/rabbitmq/amqp091-go v1.1.0/go.mod h1:ogQDLSOACsLPsIq0NpbtiifNZi2YOz0VTJ0kHRghqbM=
|
||||
github.com/rcrowley/go-metrics v0.0.0-20181016184325-3113b8401b8a/go.mod h1:bCqnVzQkZxMG4s8nGwiZ5l3QUCyqpo9Y+/ZMZ9VjZe4=
|
||||
github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475/go.mod h1:bCqnVzQkZxMG4s8nGwiZ5l3QUCyqpo9Y+/ZMZ9VjZe4=
|
||||
github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ=
|
||||
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
|
||||
github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
|
||||
@@ -339,6 +370,7 @@ github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeV
|
||||
github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo=
|
||||
github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE=
|
||||
github.com/sirupsen/logrus v1.6.0/go.mod h1:7uNnSEd1DgxDLC74fIahvMZmmYsHGZGEOFrfsX/uA88=
|
||||
github.com/sirupsen/logrus v1.8.1/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0=
|
||||
github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA=
|
||||
github.com/spaolacci/murmur3 v1.1.0 h1:7c1g84S4BPRrfL5Xrdp6fOJ206sU9y293DDHaoy0bLI=
|
||||
github.com/spaolacci/murmur3 v1.1.0/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA=
|
||||
@@ -360,42 +392,44 @@ github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5Cc
|
||||
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||
github.com/urfave/cli v1.22.5 h1:lNq9sAHXK2qfdI8W+GRItjCEkI+2oR4d+MEHy1CKXoU=
|
||||
github.com/urfave/cli v1.22.5/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0=
|
||||
github.com/urfave/cli/v2 v2.3.0/go.mod h1:LJmUH05zAU44vOAcrfzZQKsZbVcdbOG8rtL3/XcUArI=
|
||||
github.com/xdg-go/pbkdf2 v1.0.0/go.mod h1:jrpuAogTd400dnrH08LKmI/xc1MbPOebTwRqcT5RDeI=
|
||||
github.com/xdg-go/scram v1.0.2/go.mod h1:1WAq6h33pAW+iRreB34OORO2Nf7qel3VV3fjBj+hCSs=
|
||||
github.com/xdg-go/stringprep v1.0.2/go.mod h1:8F9zXuvzgwmyT5DUm4GUfZGDdT3W+LCvS6+da4O5kxM=
|
||||
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
|
||||
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
|
||||
github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
|
||||
github.com/yuin/gopher-lua v0.0.0-20191220021717-ab39c6098bdb h1:ZkM6LRnq40pR1Ox0hTHlnpkcOTuFIDQpZ1IN8rKKhX0=
|
||||
github.com/yuin/gopher-lua v0.0.0-20191220021717-ab39c6098bdb/go.mod h1:gqRgreBUhTSL0GeU64rtZ3Uq3wtjOa/TB2YfrtkCbVQ=
|
||||
github.com/yuin/gopher-lua v0.0.0-20200816102855-ee81675732da h1:NimzV1aGyq29m5ukMK0AMWEhFaL/lrEOaephfuoiARg=
|
||||
github.com/yuin/gopher-lua v0.0.0-20200816102855-ee81675732da/go.mod h1:E1AXubJBdNmFERAOucpDIxNzeGfLzg0mYh+UfMWdChA=
|
||||
github.com/zeromicro/antlr v0.0.1 h1:CQpIn/dc0pUjgGQ81y98s/NGOm2Hfru2NNio2I9mQgk=
|
||||
github.com/zeromicro/antlr v0.0.1/go.mod h1:nfpjEwFR6Q4xGDJMcZnCL9tEfQRgszMwu3rDz2Z+p5M=
|
||||
github.com/zeromicro/ddl-parser v0.0.0-20210712021150-63520aca7348 h1:OhxL9tn28gDeJVzreIUiE5oVxZCjL3tBJ0XBNw8p5R8=
|
||||
github.com/zeromicro/ddl-parser v0.0.0-20210712021150-63520aca7348/go.mod h1:ISU/8NuPyEpl9pa17Py9TBPetMjtsiHrb9f5XGiYbo8=
|
||||
github.com/zeromicro/protobuf v0.0.0-20210921042113-636cd51f0c35 h1:LKLiozf78evAX4+82AHw/rG7TvefD7TJII7XB7Oip7o=
|
||||
github.com/zeromicro/protobuf v0.0.0-20210921042113-636cd51f0c35/go.mod h1:CJvyESptK/6uU5003fPJQ9Hmubl3vRuGqaLgzUU0R7Y=
|
||||
go.etcd.io/etcd/api/v3 v3.5.0 h1:GsV3S+OfZEOCNXdtNkBSR7kgLobAa/SO6tCxRa0GAYw=
|
||||
go.etcd.io/etcd/api/v3 v3.5.0/go.mod h1:cbVKeC6lCfl7j/8jBhAK6aIYO9XOjdptoxU/nLQcPvs=
|
||||
go.etcd.io/etcd/client/pkg/v3 v3.5.0 h1:2aQv6F436YnN7I4VbI8PPYrBhu+SmrTaADcf8Mi/6PU=
|
||||
go.etcd.io/etcd/client/pkg/v3 v3.5.0/go.mod h1:IJHfcCEKxYu1Os13ZdwCwIUTUVGYTSAM3YSwc9/Ac1g=
|
||||
go.etcd.io/etcd/client/v3 v3.5.0 h1:62Eh0XOro+rDwkrypAGDfgmNh5Joq+z+W9HZdlXMzek=
|
||||
go.etcd.io/etcd/client/v3 v3.5.0/go.mod h1:AIKXXVX/DQXtfTEqBryiLTUXwON+GuvO6Z7lLS/oTh0=
|
||||
go.etcd.io/etcd/api/v3 v3.5.1 h1:v28cktvBq+7vGyJXF8G+rWJmj+1XUmMtqcLnH8hDocM=
|
||||
go.etcd.io/etcd/api/v3 v3.5.1/go.mod h1:cbVKeC6lCfl7j/8jBhAK6aIYO9XOjdptoxU/nLQcPvs=
|
||||
go.etcd.io/etcd/client/pkg/v3 v3.5.1 h1:XIQcHCFSG53bJETYeRJtIxdLv2EWRGxcfzR8lSnTH4E=
|
||||
go.etcd.io/etcd/client/pkg/v3 v3.5.1/go.mod h1:IJHfcCEKxYu1Os13ZdwCwIUTUVGYTSAM3YSwc9/Ac1g=
|
||||
go.etcd.io/etcd/client/v3 v3.5.1 h1:oImGuV5LGKjCqXdjkMHCyWa5OO1gYKCnC/1sgdfj1Uk=
|
||||
go.etcd.io/etcd/client/v3 v3.5.1/go.mod h1:OnjH4M8OnAotwaB2l9bVgZzRFKru7/ZMoS46OtKyd3Q=
|
||||
go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU=
|
||||
go.opencensus.io v0.22.0/go.mod h1:+kGneAE2xo2IficOXnaByMWTGM9T73dGwxeWcUqIpI8=
|
||||
go.opencensus.io v0.22.2/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw=
|
||||
go.opencensus.io v0.22.3/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw=
|
||||
go.opentelemetry.io/otel v1.0.1 h1:4XKyXmfqJLOQ7feyV5DB6gsBFZ0ltB8vLtp6pj4JIcc=
|
||||
go.opentelemetry.io/otel v1.0.1/go.mod h1:OPEOD4jIT2SlZPMmwT6FqZz2C0ZNdQqiWcoK6M0SNFU=
|
||||
go.opentelemetry.io/otel/exporters/jaeger v1.0.1 h1:fg9udWIWWJMAT+Gq2ATFd/DFy3OZvKEZy9VK2amxvkw=
|
||||
go.opentelemetry.io/otel/exporters/jaeger v1.0.1/go.mod h1:85Ym3qknJdIdfRzYS9Ofy9NeLi9gKPFzFDBEHCKpfXI=
|
||||
go.opentelemetry.io/otel/exporters/zipkin v1.0.1 h1:Li6OvM1Po5qrP+HnXlZa+FyLkMun7JG4R0vTAch12qs=
|
||||
go.opentelemetry.io/otel/exporters/zipkin v1.0.1/go.mod h1:KXb2W6IVINSd/rKugSARqP3TsByxngvea3B1vm5ju74=
|
||||
go.opentelemetry.io/otel/sdk v1.0.1 h1:wXxFEWGo7XfXupPwVJvTBOaPBC9FEg0wB8hMNrKk+cA=
|
||||
go.opentelemetry.io/otel/sdk v1.0.1/go.mod h1:HrdXne+BiwsOHYYkBE5ysIcv2bvdZstxzmCQhxTcZkI=
|
||||
go.opentelemetry.io/otel/trace v1.0.1 h1:StTeIH6Q3G4r0Fiw34LTokUFESZgIDUr0qIJ7mKmAfw=
|
||||
go.opentelemetry.io/otel/trace v1.0.1/go.mod h1:5g4i4fKLaX2BQpSBsxw8YYcgKpMMSW3x7ZTuYBr3sUk=
|
||||
go.opentelemetry.io/otel v1.1.0 h1:8p0uMLcyyIx0KHNTgO8o3CW8A1aA+dJZJW6PvnMz0Wc=
|
||||
go.opentelemetry.io/otel v1.1.0/go.mod h1:7cww0OW51jQ8IaZChIEdqLwgh+44+7uiTdWsAL0wQpA=
|
||||
go.opentelemetry.io/otel/exporters/jaeger v1.1.0 h1:VRF+Hf3EePFO6ab7/wfPoyWzSY4z5X0tTvQtV9/Mq8Y=
|
||||
go.opentelemetry.io/otel/exporters/jaeger v1.1.0/go.mod h1:D/GIBwAdrFTTqCy1iITpC9nh5rgJpIbFVgkhlz2vCXk=
|
||||
go.opentelemetry.io/otel/exporters/zipkin v1.1.0 h1:NfP5auMWoVOYnAeQPY+fxNG8UMAu94heSL4rtOL8Bsg=
|
||||
go.opentelemetry.io/otel/exporters/zipkin v1.1.0/go.mod h1:LZwDnf1mVGTPMq9hdRUHfFBH30SuQvZ1BJaVywpg0VI=
|
||||
go.opentelemetry.io/otel/sdk v1.1.0 h1:j/1PngUJIDOddkCILQYTevrTIbWd494djgGkSsMit+U=
|
||||
go.opentelemetry.io/otel/sdk v1.1.0/go.mod h1:3aQvM6uLm6C4wJpHtT8Od3vNzeZ34Pqc6bps8MywWzo=
|
||||
go.opentelemetry.io/otel/trace v1.1.0 h1:N25T9qCL0+7IpOT8RrRy0WYlL7y6U0WiUJzXcVdXY/o=
|
||||
go.opentelemetry.io/otel/trace v1.1.0/go.mod h1:i47XtdcBQiktu5IsrPqOHe8w+sBmnLwwHt8wiUsWGTI=
|
||||
go.opentelemetry.io/proto/otlp v0.7.0/go.mod h1:PqfVotwruBrMGOCsRd/89rSnXhoiJIqeYNgFYFoEGnI=
|
||||
go.uber.org/atomic v1.7.0 h1:ADUqmZGgLDDfbSL9ZmPxKTybcoEYHgpYfELNoN+7hsw=
|
||||
go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc=
|
||||
go.uber.org/automaxprocs v1.3.0 h1:II28aZoGdaglS5vVNnspf28lnZpXScxtIozx1lAjdb0=
|
||||
go.uber.org/automaxprocs v1.3.0/go.mod h1:9CWT6lKIep8U41DDaPiH6eFscnTyjfTANNQNx6LrIcA=
|
||||
go.uber.org/automaxprocs v1.4.0 h1:CpDZl6aOlLhReez+8S3eEotD7Jx0Os++lemPlMULQP0=
|
||||
go.uber.org/automaxprocs v1.4.0/go.mod h1:/mTEdr7LvHhs0v7mjdxDreTz1OG5zdZGqgOnhWiR/+Q=
|
||||
go.uber.org/multierr v1.6.0 h1:y6IPFStTAIT5Ytl7/XYmHvzXQ7S3g/IeZW9hyZ5thw4=
|
||||
go.uber.org/multierr v1.6.0/go.mod h1:cdWPpRnG4AhwMwsgIHip0KRBQjJy5kYEpYjJxpXp9iU=
|
||||
go.uber.org/zap v1.17.0 h1:MTjgFu6ZLKvY6Pvaqk97GlxNBuMpV4Hy/3P6tRGlI2U=
|
||||
@@ -407,8 +441,10 @@ golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5/go.mod h1:yigFU9vqHzYiE8U
|
||||
golang.org/x/crypto v0.0.0-20190611184440-5c40567a22f8/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
||||
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
||||
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
||||
golang.org/x/crypto v0.0.0-20201002170205-7f63de1d35b0 h1:hb9wdF1z5waM+dSIICn1l0DkLVDT3hqhhQsDNUmHPRE=
|
||||
golang.org/x/crypto v0.0.0-20201002170205-7f63de1d35b0/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
||||
golang.org/x/crypto v0.0.0-20201112155050-0c6587e931a9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
||||
golang.org/x/crypto v0.0.0-20210920023735-84f357641f63 h1:kETrAMYZq6WVGPa8IIixL0CaEcIUNi+1WX7grUoi3y8=
|
||||
golang.org/x/crypto v0.0.0-20210920023735-84f357641f63/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
|
||||
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
|
||||
golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
|
||||
golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8=
|
||||
@@ -463,11 +499,15 @@ golang.org/x/net v0.0.0-20200222125558-5a598a2470a0/go.mod h1:z5CRVTTTmAJ677TzLL
|
||||
golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||
golang.org/x/net v0.0.0-20200301022130-244492dfa37a/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||
golang.org/x/net v0.0.0-20200324143707-d3edc9973b7e/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
|
||||
golang.org/x/net v0.0.0-20200520004742-59133d7f0dd7/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
|
||||
golang.org/x/net v0.0.0-20200625001655-4c5254603344/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA=
|
||||
golang.org/x/net v0.0.0-20200822124328-c89045814202/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-20201110031124-69a78807bb2b/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-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM=
|
||||
golang.org/x/net v0.0.0-20210428140749-89ef3d95e781/go.mod h1:OJAsFXCWl8Ukc7SiCT/9KSuxbyM7479/AVlXFRxuMCk=
|
||||
golang.org/x/net v0.0.0-20210917221730-978cfadd31cf/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
|
||||
golang.org/x/net v0.0.0-20210928044308-7d9f5e0b762b h1:eB48h3HiRycXNy8E0Gf5e0hv7YT6Kt14L/D73G1fuwo=
|
||||
golang.org/x/net v0.0.0-20210928044308-7d9f5e0b762b/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
|
||||
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
|
||||
@@ -501,9 +541,11 @@ golang.org/x/sys v0.0.0-20190606165138-5da285871e9c/go.mod h1:h1NjWce9XRLGQEsW7w
|
||||
golang.org/x/sys v0.0.0-20190616124812-15dcb6c0061f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20190624142023-c5567b49c5d0/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20190726091711-fc99dfbffb4e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20190904154756-749cb33beabd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20191001151750-bb3f8db39f24/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20191005200804-aed5e4c7ecf9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20191120155948-bd437916bb0e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20191204072324-ce4227a45e2e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20191228213918-04cbcbbfeed8/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20200106162015-b016eb3dc98e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
@@ -520,6 +562,7 @@ golang.org/x/sys v0.0.0-20200625212154-ddb9806d33ae/go.mod h1:h1NjWce9XRLGQEsW7w
|
||||
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20201112073958-5cba982894dd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20210112080510-489259a85091/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20210403161142-5e06dd20ab57/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
@@ -527,15 +570,16 @@ golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7w
|
||||
golang.org/x/sys v0.0.0-20210423185535-09eb48e85fd7/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20210603081109-ebe580a85c40/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20211002104244-808efd93c36d h1:SABT8Vei3iTiu+Gy8KOzpSNz+W1EQ5YBCRtiEETxF+0=
|
||||
golang.org/x/sys v0.0.0-20211002104244-808efd93c36d/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20211106132015-ebca88c72f68 h1:Ywe/f3fNleF8I6F6qv3MeFoSZ6CTf2zBMMa/7qVML8M=
|
||||
golang.org/x/sys v0.0.0-20211106132015-ebca88c72f68/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1 h1:v+OssWQX+hTHEmOBgwxdZxK4zHq3yOs8F9J7mk0PY8E=
|
||||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
||||
golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
|
||||
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||
golang.org/x/text v0.3.4/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||
golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||
golang.org/x/text v0.3.7 h1:olpwvP2KacW1ZWvsR7uQhoyTYvKAupfQrRGBFM352Gk=
|
||||
@@ -578,7 +622,9 @@ golang.org/x/tools v0.0.0-20200212150539-ea181f53ac56/go.mod h1:TB2adYChydJhpapK
|
||||
golang.org/x/tools v0.0.0-20200224181240-023911ca70b2/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28=
|
||||
golang.org/x/tools v0.0.0-20200304193943-95d2e580d8eb/go.mod h1:o4KQGtdN14AW+yjsvvwRTJJuXz8XRtIHtEnmAXLyFUw=
|
||||
golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE=
|
||||
golang.org/x/tools v0.0.0-20201224043029-2b0845dc783e/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
|
||||
golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
|
||||
golang.org/x/tools v0.1.1/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
|
||||
golang.org/x/tools v0.1.2/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
|
||||
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=
|
||||
@@ -637,8 +683,9 @@ google.golang.org/grpc v1.33.1/go.mod h1:fr5YgcSWrqhRRxogOsw7RzIpsmvOZ6IcH4kBYTp
|
||||
google.golang.org/grpc v1.36.0/go.mod h1:qjiiYl8FncCW8feJPdyg3v6XW24KsRHe+dy9BAGRRjU=
|
||||
google.golang.org/grpc v1.38.0/go.mod h1:NREThFqKR1f3iQ6oBuvc5LadQuXVGo9rkm5ZGrQdJfM=
|
||||
google.golang.org/grpc v1.40.0/go.mod h1:ogyxbiOoUXAkP+4+xa6PZSE9DZgIHtSpzjDTB9KAK34=
|
||||
google.golang.org/grpc v1.41.0 h1:f+PlOh7QV4iIJkPrx5NQ7qaNGFQ3OTse67yaDHfju4E=
|
||||
google.golang.org/grpc v1.41.0/go.mod h1:U3l9uK9J0sini8mHphKoXyaqDA/8VyGnDee1zzIUK6k=
|
||||
google.golang.org/grpc v1.42.0 h1:XT2/MFpuPFsEX2fWh3YQtHkZ+WYZFQRfaUgLZYj/p6A=
|
||||
google.golang.org/grpc v1.42.0/go.mod h1:k+4IHHFw41K8+bbowsex27ge2rCb65oeWqe4jJ590SU=
|
||||
google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8=
|
||||
google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0=
|
||||
google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM=
|
||||
@@ -655,15 +702,15 @@ google.golang.org/protobuf v1.27.1/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQ
|
||||
gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo=
|
||||
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
|
||||
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
|
||||
gopkg.in/cheggaaa/pb.v1 v1.0.28 h1:n1tBJnnK2r7g9OW2btFH91V92STTUevLXYFb8gy9EMk=
|
||||
gopkg.in/cheggaaa/pb.v1 v1.0.28/go.mod h1:V/YB90LKu/1FcN3WVnfiiE5oMCibMjukxqG/qStrOgw=
|
||||
gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=
|
||||
gopkg.in/fsnotify.v1 v1.4.7 h1:xOHLXZwVvI9hhs+cLKq5+I5onOuwQLhQwiu63xxlHs4=
|
||||
gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys=
|
||||
gopkg.in/h2non/gock.v1 v1.0.15 h1:SzLqcIlb/fDfg7UvukMpNcWsu7sI5tWwL+KCATZqks0=
|
||||
gopkg.in/h2non/gock.v1 v1.0.15/go.mod h1:sX4zAkdYX1TRGJ2JY156cFspQn4yRWn6p9EMdODlynE=
|
||||
gopkg.in/h2non/gock.v1 v1.1.2 h1:jBbHXgGBK/AoPVfJh5x4r/WxIrElvbLel8TCZkkZJoY=
|
||||
gopkg.in/h2non/gock.v1 v1.1.2/go.mod h1:n7UGz/ckNChHiK05rDoiC4MYSunEC/lyaUm2WWaDva0=
|
||||
gopkg.in/inf.v0 v0.9.1 h1:73M5CoZyi3ZLMOyDlQh031Cx6N9NDJ2Vvfl76EDAgDc=
|
||||
gopkg.in/inf.v0 v0.9.1/go.mod h1:cWUDdTG/fYaXco+Dcufb5Vnc6Gp2YChqWtbxRZE0mXw=
|
||||
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ=
|
||||
@@ -686,12 +733,12 @@ honnef.co/go/tools v0.0.0-20190418001031-e561f6794a2a/go.mod h1:rf3lG4BRIbNafJWh
|
||||
honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
||||
honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg=
|
||||
honnef.co/go/tools v0.0.1-2020.1.3/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k=
|
||||
k8s.io/api v0.20.10 h1:kAdgi1zcyenV88/uVEzS9B/fn1m4KRbmdKB0Lxl6z/M=
|
||||
k8s.io/api v0.20.10/go.mod h1:0kei3F6biGjtRQBo5dUeujq6Ji3UCh9aOSfp/THYd7I=
|
||||
k8s.io/apimachinery v0.20.10 h1:GcFwz5hsGgKLohcNgv8GrInk60vUdFgBXW7uOY1i1YM=
|
||||
k8s.io/apimachinery v0.20.10/go.mod h1:kQa//VOAwyVwJ2+L9kOREbsnryfsGSkSM1przND4+mw=
|
||||
k8s.io/client-go v0.20.10 h1:TgAL2pqcNWMH4eZoS9Uw0BLh2lu5a2A4pmegjp5pmsk=
|
||||
k8s.io/client-go v0.20.10/go.mod h1:fFg+aLoasv/R+xiVaWjxeqGFYltzgQcOQzkFaSRfnJ0=
|
||||
k8s.io/api v0.20.12 h1:LfRpmRkJLwPP8eaYehsVVmIIfg1yCBIIUHaSsdqCgHA=
|
||||
k8s.io/api v0.20.12/go.mod h1:A2brwyEkVLM3wQGNnzoAa5JsQRzHK0uoOQ+bsnv7V68=
|
||||
k8s.io/apimachinery v0.20.12 h1:2c0LIVNMvB8k2Ozstmhl2zGeCEcPazznuLYEwxFdNjM=
|
||||
k8s.io/apimachinery v0.20.12/go.mod h1:uM7hCI0NyBymUwgshMgZyte475lxhr+QH6h3cvdnzEc=
|
||||
k8s.io/client-go v0.20.12 h1:U75SxTC31BHT9i7CbX/hL4v+U1Wkzy/E1vt5ClDPp3I=
|
||||
k8s.io/client-go v0.20.12/go.mod h1:NBJj6Evp73Xy/4v/O/RDRaH0+3JoxNfjRxkyRgrdbsA=
|
||||
k8s.io/gengo v0.0.0-20200413195148-3a45101e95ac/go.mod h1:ezvh/TsK7cY6rbqRK0oQQ8IAqLxYwwyPxAX1Pzy0ii0=
|
||||
k8s.io/klog/v2 v2.0.0/go.mod h1:PBfzABfn139FHAV07az/IF9Wp1bkk3vpT2XSJ76fSDE=
|
||||
k8s.io/klog/v2 v2.4.0 h1:7+X0fUguPyrKEC4WjH8iGDg3laWgMo5tMnRTIGTTxGQ=
|
||||
|
||||
12
readme-cn.md
12
readme-cn.md
@@ -104,10 +104,10 @@ GO111MODULE=on GOPROXY=https://goproxy.cn/,direct go get -u github.com/tal-tech/
|
||||
|
||||
```shell
|
||||
# Go 1.15 及之前版本
|
||||
GO111MODULE=on GOPROXY=https://goproxy.cn/,direct go get -u github.com/tal-tech/go-zero/tools/goctl
|
||||
GO111MODULE=on GOPROXY=https://goproxy.cn/,direct go get -u github.com/tal-tech/go-zero/tools/goctl@cli
|
||||
|
||||
# Go 1.16 及以后版本
|
||||
go install github.com/tal-tech/go-zero/tools/goctl@latest
|
||||
GOPROXY=https://goproxy.cn/,direct go install github.com/tal-tech/go-zero/tools/goctl@cli
|
||||
```
|
||||
|
||||
确保 goctl 可执行
|
||||
@@ -226,6 +226,12 @@ go-zero 已被许多公司用于生产部署,接入场景如在线教育、电
|
||||
>40. 马鞍山百助网络科技有限公司
|
||||
>41. 上海阿莫尔科技有限公司
|
||||
>42. 发明者量化
|
||||
>43. 济南超级盟网络科技有限公司
|
||||
>44. 苏州互盟信息存储技术有限公司
|
||||
>45. 成都艾途教育科技集团有限公司
|
||||
>46. 上海游族网络
|
||||
>47. 深信服
|
||||
>48. 中免日上科技互联有限公司
|
||||
|
||||
如果贵公司也已使用 go-zero,欢迎在 [登记地址](https://github.com/zeromicro/go-zero/issues/602) 登记,仅仅为了推广,不做其它用途。
|
||||
|
||||
@@ -242,7 +248,7 @@ go-zero 收录在 [CNCF Cloud Native 云原生技术全景图](https://landscape
|
||||
|
||||
`go-zero` 相关文章和视频都会在 `微服务实践` 公众号整理呈现,欢迎扫码关注 👏
|
||||
|
||||
<img src="https://raw.githubusercontent.com/zeromicro/zero-doc/main/doc/images/wechat-micro.jpg" alt="wechat" width="300" />
|
||||
<img src="https://raw.githubusercontent.com/zeromicro/zero-doc/main/doc/images/zeromicro.jpg" alt="wechat" width="600" />
|
||||
|
||||
## 11. 微信交流群
|
||||
|
||||
|
||||
@@ -107,10 +107,10 @@ go get -u github.com/tal-tech/go-zero
|
||||
|
||||
```shell
|
||||
# for Go 1.15 and earlier
|
||||
GO111MODULE=on go get -u github.com/tal-tech/go-zero/tools/goctl
|
||||
GO111MODULE=on go get -u github.com/tal-tech/go-zero/tools/goctl@cli
|
||||
|
||||
# for Go 1.16 and later
|
||||
go install github.com/tal-tech/go-zero/tools/goctl@latest
|
||||
go install github.com/tal-tech/go-zero/tools/goctl@cli
|
||||
```
|
||||
|
||||
make sure goctl is executable.
|
||||
|
||||
@@ -35,7 +35,7 @@ type (
|
||||
KeyFile string `json:",optional"`
|
||||
Verbose bool `json:",optional"`
|
||||
MaxConns int `json:",default=10000"`
|
||||
MaxBytes int64 `json:",default=1048576,range=[0:33554432]"`
|
||||
MaxBytes int64 `json:",default=1048576"`
|
||||
// milliseconds
|
||||
Timeout int64 `json:",default=3000"`
|
||||
CpuThreshold int64 `json:",default=900,range=[0:1000]"`
|
||||
|
||||
136
rest/engine.go
136
rest/engine.go
@@ -1,6 +1,7 @@
|
||||
package rest
|
||||
|
||||
import (
|
||||
"crypto/tls"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/http"
|
||||
@@ -13,7 +14,6 @@ import (
|
||||
"github.com/tal-tech/go-zero/rest/handler"
|
||||
"github.com/tal-tech/go-zero/rest/httpx"
|
||||
"github.com/tal-tech/go-zero/rest/internal"
|
||||
"github.com/tal-tech/go-zero/rest/router"
|
||||
)
|
||||
|
||||
// use 1000m to represent 100%
|
||||
@@ -30,6 +30,7 @@ type engine struct {
|
||||
middlewares []Middleware
|
||||
shedder load.Shedder
|
||||
priorityShedder load.Shedder
|
||||
tlsConfig *tls.Config
|
||||
}
|
||||
|
||||
func newEngine(c RestConf) *engine {
|
||||
@@ -45,58 +46,34 @@ func newEngine(c RestConf) *engine {
|
||||
return srv
|
||||
}
|
||||
|
||||
func (s *engine) AddRoutes(r featuredRoutes) {
|
||||
s.routes = append(s.routes, r)
|
||||
func (ng *engine) addRoutes(r featuredRoutes) {
|
||||
ng.routes = append(ng.routes, r)
|
||||
}
|
||||
|
||||
func (s *engine) SetUnauthorizedCallback(callback handler.UnauthorizedCallback) {
|
||||
s.unauthorizedCallback = callback
|
||||
}
|
||||
|
||||
func (s *engine) SetUnsignedCallback(callback handler.UnsignedCallback) {
|
||||
s.unsignedCallback = callback
|
||||
}
|
||||
|
||||
func (s *engine) Start() error {
|
||||
return s.StartWithRouter(router.NewRouter())
|
||||
}
|
||||
|
||||
func (s *engine) StartWithRouter(router httpx.Router) error {
|
||||
if err := s.bindRoutes(router); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if len(s.conf.CertFile) == 0 && len(s.conf.KeyFile) == 0 {
|
||||
return internal.StartHttp(s.conf.Host, s.conf.Port, router)
|
||||
}
|
||||
|
||||
return internal.StartHttps(s.conf.Host, s.conf.Port, s.conf.CertFile, s.conf.KeyFile, router)
|
||||
}
|
||||
|
||||
func (s *engine) appendAuthHandler(fr featuredRoutes, chain alice.Chain,
|
||||
func (ng *engine) appendAuthHandler(fr featuredRoutes, chain alice.Chain,
|
||||
verifier func(alice.Chain) alice.Chain) alice.Chain {
|
||||
if fr.jwt.enabled {
|
||||
if len(fr.jwt.prevSecret) == 0 {
|
||||
chain = chain.Append(handler.Authorize(fr.jwt.secret,
|
||||
handler.WithUnauthorizedCallback(s.unauthorizedCallback)))
|
||||
handler.WithUnauthorizedCallback(ng.unauthorizedCallback)))
|
||||
} else {
|
||||
chain = chain.Append(handler.Authorize(fr.jwt.secret,
|
||||
handler.WithPrevSecret(fr.jwt.prevSecret),
|
||||
handler.WithUnauthorizedCallback(s.unauthorizedCallback)))
|
||||
handler.WithUnauthorizedCallback(ng.unauthorizedCallback)))
|
||||
}
|
||||
}
|
||||
|
||||
return verifier(chain)
|
||||
}
|
||||
|
||||
func (s *engine) bindFeaturedRoutes(router httpx.Router, fr featuredRoutes, metrics *stat.Metrics) error {
|
||||
verifier, err := s.signatureVerifier(fr.signature)
|
||||
func (ng *engine) bindFeaturedRoutes(router httpx.Router, fr featuredRoutes, metrics *stat.Metrics) error {
|
||||
verifier, err := ng.signatureVerifier(fr.signature)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for _, route := range fr.routes {
|
||||
if err := s.bindRoute(fr, router, metrics, route, verifier); err != nil {
|
||||
if err := ng.bindRoute(fr, router, metrics, route, verifier); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
@@ -104,24 +81,24 @@ func (s *engine) bindFeaturedRoutes(router httpx.Router, fr featuredRoutes, metr
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *engine) bindRoute(fr featuredRoutes, router httpx.Router, metrics *stat.Metrics,
|
||||
func (ng *engine) bindRoute(fr featuredRoutes, router httpx.Router, metrics *stat.Metrics,
|
||||
route Route, verifier func(chain alice.Chain) alice.Chain) error {
|
||||
chain := alice.New(
|
||||
handler.TracingHandler(s.conf.Name, route.Path),
|
||||
s.getLogHandler(),
|
||||
handler.TracingHandler(ng.conf.Name, route.Path),
|
||||
ng.getLogHandler(),
|
||||
handler.PrometheusHandler(route.Path),
|
||||
handler.MaxConns(s.conf.MaxConns),
|
||||
handler.MaxConns(ng.conf.MaxConns),
|
||||
handler.BreakerHandler(route.Method, route.Path, metrics),
|
||||
handler.SheddingHandler(s.getShedder(fr.priority), metrics),
|
||||
handler.TimeoutHandler(time.Duration(s.conf.Timeout)*time.Millisecond),
|
||||
handler.SheddingHandler(ng.getShedder(fr.priority), metrics),
|
||||
handler.TimeoutHandler(ng.checkedTimeout(fr.timeout)),
|
||||
handler.RecoverHandler,
|
||||
handler.MetricHandler(metrics),
|
||||
handler.MaxBytesHandler(s.conf.MaxBytes),
|
||||
handler.MaxBytesHandler(ng.conf.MaxBytes),
|
||||
handler.GunzipHandler,
|
||||
)
|
||||
chain = s.appendAuthHandler(fr, chain, verifier)
|
||||
chain = ng.appendAuthHandler(fr, chain, verifier)
|
||||
|
||||
for _, middleware := range s.middlewares {
|
||||
for _, middleware := range ng.middlewares {
|
||||
chain = chain.Append(convertMiddleware(middleware))
|
||||
}
|
||||
handle := chain.ThenFunc(route.Handler)
|
||||
@@ -129,11 +106,11 @@ func (s *engine) bindRoute(fr featuredRoutes, router httpx.Router, metrics *stat
|
||||
return router.Handle(route.Method, route.Path, handle)
|
||||
}
|
||||
|
||||
func (s *engine) bindRoutes(router httpx.Router) error {
|
||||
metrics := s.createMetrics()
|
||||
func (ng *engine) bindRoutes(router httpx.Router) error {
|
||||
metrics := ng.createMetrics()
|
||||
|
||||
for _, fr := range s.routes {
|
||||
if err := s.bindFeaturedRoutes(router, fr, metrics); err != nil {
|
||||
for _, fr := range ng.routes {
|
||||
if err := ng.bindFeaturedRoutes(router, fr, metrics); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
@@ -141,35 +118,55 @@ func (s *engine) bindRoutes(router httpx.Router) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *engine) createMetrics() *stat.Metrics {
|
||||
func (ng *engine) checkedTimeout(timeout time.Duration) time.Duration {
|
||||
if timeout > 0 {
|
||||
return timeout
|
||||
}
|
||||
|
||||
return time.Duration(ng.conf.Timeout) * time.Millisecond
|
||||
}
|
||||
|
||||
func (ng *engine) createMetrics() *stat.Metrics {
|
||||
var metrics *stat.Metrics
|
||||
|
||||
if len(s.conf.Name) > 0 {
|
||||
metrics = stat.NewMetrics(s.conf.Name)
|
||||
if len(ng.conf.Name) > 0 {
|
||||
metrics = stat.NewMetrics(ng.conf.Name)
|
||||
} else {
|
||||
metrics = stat.NewMetrics(fmt.Sprintf("%s:%d", s.conf.Host, s.conf.Port))
|
||||
metrics = stat.NewMetrics(fmt.Sprintf("%s:%d", ng.conf.Host, ng.conf.Port))
|
||||
}
|
||||
|
||||
return metrics
|
||||
}
|
||||
|
||||
func (s *engine) getLogHandler() func(http.Handler) http.Handler {
|
||||
if s.conf.Verbose {
|
||||
func (ng *engine) getLogHandler() func(http.Handler) http.Handler {
|
||||
if ng.conf.Verbose {
|
||||
return handler.DetailedLogHandler
|
||||
}
|
||||
|
||||
return handler.LogHandler
|
||||
}
|
||||
|
||||
func (s *engine) getShedder(priority bool) load.Shedder {
|
||||
if priority && s.priorityShedder != nil {
|
||||
return s.priorityShedder
|
||||
func (ng *engine) getShedder(priority bool) load.Shedder {
|
||||
if priority && ng.priorityShedder != nil {
|
||||
return ng.priorityShedder
|
||||
}
|
||||
|
||||
return s.shedder
|
||||
return ng.shedder
|
||||
}
|
||||
|
||||
func (s *engine) signatureVerifier(signature signatureSetting) (func(chain alice.Chain) alice.Chain, error) {
|
||||
func (ng *engine) setTlsConfig(cfg *tls.Config) {
|
||||
ng.tlsConfig = cfg
|
||||
}
|
||||
|
||||
func (ng *engine) setUnauthorizedCallback(callback handler.UnauthorizedCallback) {
|
||||
ng.unauthorizedCallback = callback
|
||||
}
|
||||
|
||||
func (ng *engine) setUnsignedCallback(callback handler.UnsignedCallback) {
|
||||
ng.unsignedCallback = callback
|
||||
}
|
||||
|
||||
func (ng *engine) signatureVerifier(signature signatureSetting) (func(chain alice.Chain) alice.Chain, error) {
|
||||
if !signature.enabled {
|
||||
return func(chain alice.Chain) alice.Chain {
|
||||
return chain
|
||||
@@ -199,9 +196,9 @@ func (s *engine) signatureVerifier(signature signatureSetting) (func(chain alice
|
||||
}
|
||||
|
||||
return func(chain alice.Chain) alice.Chain {
|
||||
if s.unsignedCallback != nil {
|
||||
if ng.unsignedCallback != nil {
|
||||
return chain.Append(handler.ContentSecurityHandler(
|
||||
decrypters, signature.Expiry, signature.Strict, s.unsignedCallback))
|
||||
decrypters, signature.Expiry, signature.Strict, ng.unsignedCallback))
|
||||
}
|
||||
|
||||
return chain.Append(handler.ContentSecurityHandler(
|
||||
@@ -209,8 +206,25 @@ func (s *engine) signatureVerifier(signature signatureSetting) (func(chain alice
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (s *engine) use(middleware Middleware) {
|
||||
s.middlewares = append(s.middlewares, middleware)
|
||||
func (ng *engine) start(router httpx.Router) error {
|
||||
if err := ng.bindRoutes(router); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if len(ng.conf.CertFile) == 0 && len(ng.conf.KeyFile) == 0 {
|
||||
return internal.StartHttp(ng.conf.Host, ng.conf.Port, router)
|
||||
}
|
||||
|
||||
return internal.StartHttps(ng.conf.Host, ng.conf.Port, ng.conf.CertFile,
|
||||
ng.conf.KeyFile, router, func(srv *http.Server) {
|
||||
if ng.tlsConfig != nil {
|
||||
srv.TLSConfig = ng.tlsConfig
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func (ng *engine) use(middleware Middleware) {
|
||||
ng.middlewares = append(ng.middlewares, middleware)
|
||||
}
|
||||
|
||||
func convertMiddleware(ware Middleware) func(http.Handler) http.Handler {
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"errors"
|
||||
"net/http"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/tal-tech/go-zero/core/conf"
|
||||
@@ -143,17 +144,52 @@ Verbose: true
|
||||
var cnf RestConf
|
||||
assert.Nil(t, conf.LoadConfigFromYamlBytes([]byte(yaml), &cnf))
|
||||
ng := newEngine(cnf)
|
||||
ng.AddRoutes(route)
|
||||
ng.addRoutes(route)
|
||||
ng.use(func(next http.HandlerFunc) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
next.ServeHTTP(w, r)
|
||||
}
|
||||
})
|
||||
assert.NotNil(t, ng.StartWithRouter(mockedRouter{}))
|
||||
assert.NotNil(t, ng.start(mockedRouter{}))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestEngine_checkedTimeout(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
timeout time.Duration
|
||||
expect time.Duration
|
||||
}{
|
||||
{
|
||||
name: "not set",
|
||||
expect: time.Second,
|
||||
},
|
||||
{
|
||||
name: "less",
|
||||
timeout: time.Millisecond * 500,
|
||||
expect: time.Millisecond * 500,
|
||||
},
|
||||
{
|
||||
name: "equal",
|
||||
timeout: time.Second,
|
||||
expect: time.Second,
|
||||
},
|
||||
{
|
||||
name: "more",
|
||||
timeout: time.Millisecond * 1500,
|
||||
expect: time.Millisecond * 1500,
|
||||
},
|
||||
}
|
||||
|
||||
ng := newEngine(RestConf{
|
||||
Timeout: 1000,
|
||||
})
|
||||
for _, test := range tests {
|
||||
assert.Equal(t, test.expect, ng.checkedTimeout(test.timeout))
|
||||
}
|
||||
}
|
||||
|
||||
type mockedRouter struct{}
|
||||
|
||||
func (m mockedRouter) ServeHTTP(writer http.ResponseWriter, request *http.Request) {
|
||||
|
||||
@@ -16,6 +16,7 @@ import (
|
||||
|
||||
"github.com/tal-tech/go-zero/core/iox"
|
||||
"github.com/tal-tech/go-zero/core/logx"
|
||||
"github.com/tal-tech/go-zero/core/syncx"
|
||||
"github.com/tal-tech/go-zero/core/timex"
|
||||
"github.com/tal-tech/go-zero/core/utils"
|
||||
"github.com/tal-tech/go-zero/rest/httpx"
|
||||
@@ -23,10 +24,12 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
limitBodyBytes = 1024
|
||||
slowThreshold = time.Millisecond * 500
|
||||
limitBodyBytes = 1024
|
||||
defaultSlowThreshold = time.Millisecond * 500
|
||||
)
|
||||
|
||||
var slowThreshold = syncx.ForAtomicDuration(defaultSlowThreshold)
|
||||
|
||||
type loggedResponseWriter struct {
|
||||
w http.ResponseWriter
|
||||
r *http.Request
|
||||
@@ -140,6 +143,11 @@ func DetailedLogHandler(next http.Handler) http.Handler {
|
||||
})
|
||||
}
|
||||
|
||||
// SetSlowThreshold sets the slow threshold.
|
||||
func SetSlowThreshold(threshold time.Duration) {
|
||||
slowThreshold.Set(threshold)
|
||||
}
|
||||
|
||||
func dumpRequest(r *http.Request) string {
|
||||
reqContent, err := httputil.DumpRequest(r, true)
|
||||
if err != nil {
|
||||
@@ -155,7 +163,7 @@ func logBrief(r *http.Request, code int, timer *utils.ElapsedTimer, logs *intern
|
||||
logger := logx.WithContext(r.Context())
|
||||
buf.WriteString(fmt.Sprintf("[HTTP] %s - %d - %s - %s - %s - %s",
|
||||
r.Method, code, r.RequestURI, httpx.GetRemoteAddr(r), r.UserAgent(), timex.ReprOfDuration(duration)))
|
||||
if duration > slowThreshold {
|
||||
if duration > slowThreshold.Load() {
|
||||
logger.Slowf("[HTTP] %s - %d - %s - %s - %s - slowcall(%s)",
|
||||
r.Method, code, r.RequestURI, httpx.GetRemoteAddr(r), r.UserAgent(), timex.ReprOfDuration(duration))
|
||||
}
|
||||
@@ -191,7 +199,7 @@ func logDetails(r *http.Request, response *detailLoggedResponseWriter, timer *ut
|
||||
logger := logx.WithContext(r.Context())
|
||||
buf.WriteString(fmt.Sprintf("[HTTP] %s - %d - %s - %s\n=> %s\n",
|
||||
r.Method, response.writer.code, r.RemoteAddr, timex.ReprOfDuration(duration), dumpRequest(r)))
|
||||
if duration > slowThreshold {
|
||||
if duration > defaultSlowThreshold {
|
||||
logger.Slowf("[HTTP] %s - %d - %s - slowcall(%s)\n=> %s\n",
|
||||
r.Method, response.writer.code, r.RemoteAddr, timex.ReprOfDuration(duration), dumpRequest(r))
|
||||
}
|
||||
|
||||
@@ -53,7 +53,7 @@ func TestLogHandlerSlow(t *testing.T) {
|
||||
for _, logHandler := range handlers {
|
||||
req := httptest.NewRequest(http.MethodGet, "http://localhost", nil)
|
||||
handler := logHandler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
time.Sleep(slowThreshold + time.Millisecond*50)
|
||||
time.Sleep(defaultSlowThreshold + time.Millisecond*50)
|
||||
}))
|
||||
|
||||
resp := httptest.NewRecorder()
|
||||
@@ -100,6 +100,12 @@ func TestDetailedLogHandler_Hijack(t *testing.T) {
|
||||
})
|
||||
}
|
||||
|
||||
func TestSetSlowThreshold(t *testing.T) {
|
||||
assert.Equal(t, defaultSlowThreshold, slowThreshold.Load())
|
||||
SetSlowThreshold(time.Second)
|
||||
assert.Equal(t, time.Second, slowThreshold.Load())
|
||||
}
|
||||
|
||||
func BenchmarkLogHandler(b *testing.B) {
|
||||
b.ReportAllocs()
|
||||
|
||||
|
||||
@@ -1,27 +0,0 @@
|
||||
package rest
|
||||
|
||||
import "net/http"
|
||||
|
||||
const (
|
||||
allowOrigin = "Access-Control-Allow-Origin"
|
||||
allOrigins = "*"
|
||||
allowMethods = "Access-Control-Allow-Methods"
|
||||
allowHeaders = "Access-Control-Allow-Headers"
|
||||
headers = "Content-Type, Content-Length, Origin"
|
||||
methods = "GET, HEAD, POST, PATCH, PUT, DELETE"
|
||||
)
|
||||
|
||||
// CorsHandler handles cross domain OPTIONS requests.
|
||||
// At most one origin can be specified, other origins are ignored if given.
|
||||
func CorsHandler(origins ...string) http.Handler {
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
if len(origins) > 0 {
|
||||
w.Header().Set(allowOrigin, origins[0])
|
||||
} else {
|
||||
w.Header().Set(allowOrigin, allOrigins)
|
||||
}
|
||||
w.Header().Set(allowMethods, methods)
|
||||
w.Header().Set(allowHeaders, headers)
|
||||
w.WriteHeader(http.StatusNoContent)
|
||||
})
|
||||
}
|
||||
@@ -1,42 +0,0 @@
|
||||
package rest
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestCorsHandlerWithOrigins(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
origins []string
|
||||
expect string
|
||||
}{
|
||||
{
|
||||
name: "allow all origins",
|
||||
expect: allOrigins,
|
||||
},
|
||||
{
|
||||
name: "allow one origin",
|
||||
origins: []string{"local"},
|
||||
expect: "local",
|
||||
},
|
||||
{
|
||||
name: "allow many origins",
|
||||
origins: []string{"local", "remote"},
|
||||
expect: "local",
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
w := httptest.NewRecorder()
|
||||
handler := CorsHandler(test.origins...)
|
||||
handler.ServeHTTP(w, nil)
|
||||
assert.Equal(t, http.StatusNoContent, w.Result().StatusCode)
|
||||
assert.Equal(t, test.expect, w.Header().Get(allowOrigin))
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -8,6 +8,7 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/tal-tech/go-zero/rest/pathvar"
|
||||
)
|
||||
|
||||
func TestParseForm(t *testing.T) {
|
||||
@@ -17,7 +18,7 @@ func TestParseForm(t *testing.T) {
|
||||
Percent float64 `form:"percent,optional"`
|
||||
}
|
||||
|
||||
r, err := http.NewRequest(http.MethodGet, "http://hello.com/a?name=hello&age=18&percent=3.4", nil)
|
||||
r, err := http.NewRequest(http.MethodGet, "/a?name=hello&age=18&percent=3.4", nil)
|
||||
assert.Nil(t, err)
|
||||
assert.Nil(t, Parse(r, &v))
|
||||
assert.Equal(t, "hello", v.Name)
|
||||
@@ -25,11 +26,83 @@ func TestParseForm(t *testing.T) {
|
||||
assert.Equal(t, 3.4, v.Percent)
|
||||
}
|
||||
|
||||
func TestParseForm_Error(t *testing.T) {
|
||||
var v struct {
|
||||
Name string `form:"name"`
|
||||
Age int `form:"age"`
|
||||
}
|
||||
|
||||
r := httptest.NewRequest(http.MethodGet, "/a?name=hello;", nil)
|
||||
assert.NotNil(t, ParseForm(r, &v))
|
||||
}
|
||||
|
||||
func TestParseHeader(t *testing.T) {
|
||||
m := ParseHeader("key=value;")
|
||||
assert.EqualValues(t, map[string]string{
|
||||
"key": "value",
|
||||
}, m)
|
||||
tests := []struct {
|
||||
name string
|
||||
value string
|
||||
expect map[string]string
|
||||
}{
|
||||
{
|
||||
name: "empty",
|
||||
value: "",
|
||||
expect: map[string]string{},
|
||||
},
|
||||
{
|
||||
name: "regular",
|
||||
value: "key=value",
|
||||
expect: map[string]string{"key": "value"},
|
||||
},
|
||||
{
|
||||
name: "next empty",
|
||||
value: "key=value;",
|
||||
expect: map[string]string{"key": "value"},
|
||||
},
|
||||
{
|
||||
name: "regular",
|
||||
value: "key=value;foo",
|
||||
expect: map[string]string{"key": "value"},
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
test := test
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
m := ParseHeader(test.value)
|
||||
assert.EqualValues(t, test.expect, m)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestParsePath(t *testing.T) {
|
||||
var v struct {
|
||||
Name string `path:"name"`
|
||||
Age int `path:"age"`
|
||||
}
|
||||
|
||||
r := httptest.NewRequest(http.MethodGet, "/", nil)
|
||||
r = pathvar.WithVars(r, map[string]string{
|
||||
"name": "foo",
|
||||
"age": "18",
|
||||
})
|
||||
err := Parse(r, &v)
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, "foo", v.Name)
|
||||
assert.Equal(t, 18, v.Age)
|
||||
}
|
||||
|
||||
func TestParsePath_Error(t *testing.T) {
|
||||
var v struct {
|
||||
Name string `path:"name"`
|
||||
Age int `path:"age"`
|
||||
}
|
||||
|
||||
r := httptest.NewRequest(http.MethodGet, "/", nil)
|
||||
r = pathvar.WithVars(r, map[string]string{
|
||||
"name": "foo",
|
||||
})
|
||||
assert.NotNil(t, Parse(r, &v))
|
||||
}
|
||||
|
||||
func TestParseFormOutOfRange(t *testing.T) {
|
||||
@@ -42,23 +115,23 @@ func TestParseFormOutOfRange(t *testing.T) {
|
||||
pass bool
|
||||
}{
|
||||
{
|
||||
url: "http://hello.com/a?age=5",
|
||||
url: "/a?age=5",
|
||||
pass: false,
|
||||
},
|
||||
{
|
||||
url: "http://hello.com/a?age=10",
|
||||
url: "/a?age=10",
|
||||
pass: true,
|
||||
},
|
||||
{
|
||||
url: "http://hello.com/a?age=15",
|
||||
url: "/a?age=15",
|
||||
pass: true,
|
||||
},
|
||||
{
|
||||
url: "http://hello.com/a?age=20",
|
||||
url: "/a?age=20",
|
||||
pass: false,
|
||||
},
|
||||
{
|
||||
url: "http://hello.com/a?age=28",
|
||||
url: "/a?age=28",
|
||||
pass: false,
|
||||
},
|
||||
}
|
||||
@@ -92,7 +165,7 @@ Content-Disposition: form-data; name="age"
|
||||
18
|
||||
----------------------------220477612388154780019383--`, "\n", "\r\n", -1)
|
||||
|
||||
r := httptest.NewRequest(http.MethodPost, "http://localhost:3333/", strings.NewReader(body))
|
||||
r := httptest.NewRequest(http.MethodPost, "/", strings.NewReader(body))
|
||||
r.Header.Set(ContentType, "multipart/form-data; boundary=--------------------------220477612388154780019383")
|
||||
|
||||
assert.Nil(t, Parse(r, &v))
|
||||
@@ -116,7 +189,7 @@ Content-Disposition: form-data; name="age"
|
||||
18
|
||||
----------------------------22047761238815478001938--`, "\n", "\r\n", -1)
|
||||
|
||||
r := httptest.NewRequest(http.MethodPost, "http://localhost:3333/", strings.NewReader(body))
|
||||
r := httptest.NewRequest(http.MethodPost, "/", strings.NewReader(body))
|
||||
r.Header.Set(ContentType, "multipart/form-data; boundary=--------------------------220477612388154780019383")
|
||||
|
||||
assert.NotNil(t, Parse(r, &v))
|
||||
@@ -129,7 +202,7 @@ func TestParseJsonBody(t *testing.T) {
|
||||
}
|
||||
|
||||
body := `{"name":"kevin", "age": 18}`
|
||||
r := httptest.NewRequest(http.MethodPost, "http://localhost:3333/", strings.NewReader(body))
|
||||
r := httptest.NewRequest(http.MethodPost, "/", strings.NewReader(body))
|
||||
r.Header.Set(ContentType, ApplicationJson)
|
||||
|
||||
assert.Nil(t, Parse(r, &v))
|
||||
@@ -143,7 +216,7 @@ func TestParseRequired(t *testing.T) {
|
||||
Percent float64 `form:"percent"`
|
||||
}{}
|
||||
|
||||
r, err := http.NewRequest(http.MethodGet, "http://hello.com/a?name=hello", nil)
|
||||
r, err := http.NewRequest(http.MethodGet, "/a?name=hello", nil)
|
||||
assert.Nil(t, err)
|
||||
assert.NotNil(t, Parse(r, &v))
|
||||
}
|
||||
@@ -153,11 +226,57 @@ func TestParseOptions(t *testing.T) {
|
||||
Position int8 `form:"pos,options=1|2"`
|
||||
}{}
|
||||
|
||||
r, err := http.NewRequest(http.MethodGet, "http://hello.com/a?pos=4", nil)
|
||||
r, err := http.NewRequest(http.MethodGet, "/a?pos=4", nil)
|
||||
assert.Nil(t, err)
|
||||
assert.NotNil(t, Parse(r, &v))
|
||||
}
|
||||
|
||||
func TestParseHeaders(t *testing.T) {
|
||||
type AnonymousStruct struct {
|
||||
XRealIP string `header:"x-real-ip"`
|
||||
Accept string `header:"Accept,optional"`
|
||||
}
|
||||
v := struct {
|
||||
Name string `header:"name,optional"`
|
||||
Percent string `header:"percent"`
|
||||
Addrs []string `header:"addrs"`
|
||||
XForwardedFor string `header:"X-Forwarded-For,optional"`
|
||||
AnonymousStruct
|
||||
}{}
|
||||
request, err := http.NewRequest("POST", "/", nil)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
request.Header.Set("name", "chenquan")
|
||||
request.Header.Set("percent", "1")
|
||||
request.Header.Add("addrs", "addr1")
|
||||
request.Header.Add("addrs", "addr2")
|
||||
request.Header.Add("X-Forwarded-For", "10.0.10.11")
|
||||
request.Header.Add("x-real-ip", "10.0.11.10")
|
||||
request.Header.Add("Accept", "application/json")
|
||||
err = ParseHeaders(request, &v)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
assert.Equal(t, "chenquan", v.Name)
|
||||
assert.Equal(t, "1", v.Percent)
|
||||
assert.Equal(t, []string{"addr1", "addr2"}, v.Addrs)
|
||||
assert.Equal(t, "10.0.10.11", v.XForwardedFor)
|
||||
assert.Equal(t, "10.0.11.10", v.XRealIP)
|
||||
assert.Equal(t, "application/json", v.Accept)
|
||||
}
|
||||
|
||||
func TestParseHeaders_Error(t *testing.T) {
|
||||
v := struct {
|
||||
Name string `header:"name"`
|
||||
Age int `header:"age"`
|
||||
}{}
|
||||
|
||||
r := httptest.NewRequest("POST", "/", nil)
|
||||
r.Header.Set("name", "foo")
|
||||
assert.NotNil(t, Parse(r, &v))
|
||||
}
|
||||
|
||||
func BenchmarkParseRaw(b *testing.B) {
|
||||
r, err := http.NewRequest(http.MethodGet, "http://hello.com/a?name=hello&age=18&percent=3.4", nil)
|
||||
if err != nil {
|
||||
@@ -201,38 +320,3 @@ func BenchmarkParseAuto(b *testing.B) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseHeaders(t *testing.T) {
|
||||
type AnonymousStruct struct {
|
||||
XRealIP string `header:"x-real-ip"`
|
||||
Accept string `header:"Accept,optional"`
|
||||
}
|
||||
v := struct {
|
||||
Name string `header:"name,optional"`
|
||||
Percent string `header:"percent"`
|
||||
Addrs []string `header:"addrs"`
|
||||
XForwardedFor string `header:"X-Forwarded-For,optional"`
|
||||
AnonymousStruct
|
||||
}{}
|
||||
request, err := http.NewRequest("POST", "http://hello.com/", nil)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
request.Header.Set("name", "chenquan")
|
||||
request.Header.Set("percent", "1")
|
||||
request.Header.Add("addrs", "addr1")
|
||||
request.Header.Add("addrs", "addr2")
|
||||
request.Header.Add("X-Forwarded-For", "10.0.10.11")
|
||||
request.Header.Add("x-real-ip", "10.0.11.10")
|
||||
request.Header.Add("Accept", "application/json")
|
||||
err = ParseHeaders(request, &v)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
assert.Equal(t, "chenquan", v.Name)
|
||||
assert.Equal(t, "1", v.Percent)
|
||||
assert.Equal(t, []string{"addr1", "addr2"}, v.Addrs)
|
||||
assert.Equal(t, "10.0.10.11", v.XForwardedFor)
|
||||
assert.Equal(t, "10.0.11.10", v.XRealIP)
|
||||
assert.Equal(t, "application/json", v.Accept)
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ func Error(w http.ResponseWriter, err error) {
|
||||
return
|
||||
}
|
||||
|
||||
code, body := errorHandler(err)
|
||||
code, body := handler(err)
|
||||
if body == nil {
|
||||
w.WriteHeader(code)
|
||||
return
|
||||
|
||||
@@ -10,5 +10,6 @@ func GetRemoteAddr(r *http.Request) string {
|
||||
if len(v) > 0 {
|
||||
return v
|
||||
}
|
||||
|
||||
return r.RemoteAddr
|
||||
}
|
||||
|
||||
@@ -16,3 +16,10 @@ func TestGetRemoteAddr(t *testing.T) {
|
||||
r.Header.Set(xForwardedFor, host)
|
||||
assert.Equal(t, host, GetRemoteAddr(r))
|
||||
}
|
||||
|
||||
func TestGetRemoteAddrNoHeader(t *testing.T) {
|
||||
r, err := http.NewRequest(http.MethodGet, "/", strings.NewReader(""))
|
||||
assert.Nil(t, err)
|
||||
|
||||
assert.True(t, len(GetRemoteAddr(r)) == 0)
|
||||
}
|
||||
|
||||
150
rest/internal/cors/handlers.go
Normal file
150
rest/internal/cors/handlers.go
Normal file
@@ -0,0 +1,150 @@
|
||||
package cors
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"errors"
|
||||
"net"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
const (
|
||||
allowOrigin = "Access-Control-Allow-Origin"
|
||||
allOrigins = "*"
|
||||
allowMethods = "Access-Control-Allow-Methods"
|
||||
allowHeaders = "Access-Control-Allow-Headers"
|
||||
allowCredentials = "Access-Control-Allow-Credentials"
|
||||
exposeHeaders = "Access-Control-Expose-Headers"
|
||||
requestMethod = "Access-Control-Request-Method"
|
||||
requestHeaders = "Access-Control-Request-Headers"
|
||||
allowHeadersVal = "Content-Type, Origin, X-CSRF-Token, Authorization, AccessToken, Token, Range"
|
||||
exposeHeadersVal = "Content-Length, Access-Control-Allow-Origin, Access-Control-Allow-Headers"
|
||||
methods = "GET, HEAD, POST, PATCH, PUT, DELETE"
|
||||
allowTrue = "true"
|
||||
maxAgeHeader = "Access-Control-Max-Age"
|
||||
maxAgeHeaderVal = "86400"
|
||||
varyHeader = "Vary"
|
||||
originHeader = "Origin"
|
||||
)
|
||||
|
||||
// NotAllowedHandler handles cross domain not allowed requests.
|
||||
// At most one origin can be specified, other origins are ignored if given, default to be *.
|
||||
func NotAllowedHandler(fn func(w http.ResponseWriter), origins ...string) http.Handler {
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
gw := &guardedResponseWriter{w: w}
|
||||
checkAndSetHeaders(gw, r, origins)
|
||||
if fn != nil {
|
||||
fn(gw)
|
||||
}
|
||||
|
||||
if r.Method == http.MethodOptions {
|
||||
gw.WriteHeader(http.StatusNoContent)
|
||||
} else {
|
||||
gw.WriteHeader(http.StatusNotFound)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// Middleware returns a middleware that adds CORS headers to the response.
|
||||
func Middleware(fn func(w http.Header), origins ...string) func(http.HandlerFunc) http.HandlerFunc {
|
||||
return func(next http.HandlerFunc) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
checkAndSetHeaders(w, r, origins)
|
||||
if fn != nil {
|
||||
fn(w.Header())
|
||||
}
|
||||
|
||||
if r.Method == http.MethodOptions {
|
||||
w.WriteHeader(http.StatusNoContent)
|
||||
} else {
|
||||
next(w, r)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
type guardedResponseWriter struct {
|
||||
w http.ResponseWriter
|
||||
wroteHeader bool
|
||||
}
|
||||
|
||||
func (w *guardedResponseWriter) Flush() {
|
||||
if flusher, ok := w.w.(http.Flusher); ok {
|
||||
flusher.Flush()
|
||||
}
|
||||
}
|
||||
|
||||
func (w *guardedResponseWriter) Header() http.Header {
|
||||
return w.w.Header()
|
||||
}
|
||||
|
||||
// Hijack implements the http.Hijacker interface.
|
||||
// This expands the Response to fulfill http.Hijacker if the underlying http.ResponseWriter supports it.
|
||||
func (w *guardedResponseWriter) Hijack() (net.Conn, *bufio.ReadWriter, error) {
|
||||
if hijacked, ok := w.w.(http.Hijacker); ok {
|
||||
return hijacked.Hijack()
|
||||
}
|
||||
|
||||
return nil, nil, errors.New("server doesn't support hijacking")
|
||||
}
|
||||
|
||||
func (w *guardedResponseWriter) Write(bytes []byte) (int, error) {
|
||||
return w.w.Write(bytes)
|
||||
}
|
||||
|
||||
func (w *guardedResponseWriter) WriteHeader(code int) {
|
||||
if w.wroteHeader {
|
||||
return
|
||||
}
|
||||
|
||||
w.w.WriteHeader(code)
|
||||
w.wroteHeader = true
|
||||
}
|
||||
|
||||
func checkAndSetHeaders(w http.ResponseWriter, r *http.Request, origins []string) {
|
||||
setVaryHeaders(w, r)
|
||||
|
||||
if len(origins) == 0 {
|
||||
setHeader(w, allOrigins)
|
||||
return
|
||||
}
|
||||
|
||||
origin := r.Header.Get(originHeader)
|
||||
if isOriginAllowed(origins, origin) {
|
||||
setHeader(w, origin)
|
||||
}
|
||||
}
|
||||
|
||||
func isOriginAllowed(allows []string, origin string) bool {
|
||||
for _, o := range allows {
|
||||
if o == allOrigins {
|
||||
return true
|
||||
}
|
||||
|
||||
if o == origin {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
func setHeader(w http.ResponseWriter, origin string) {
|
||||
header := w.Header()
|
||||
header.Set(allowOrigin, origin)
|
||||
header.Set(allowMethods, methods)
|
||||
header.Set(allowHeaders, allowHeadersVal)
|
||||
header.Set(exposeHeaders, exposeHeadersVal)
|
||||
if origin != allOrigins {
|
||||
header.Set(allowCredentials, allowTrue)
|
||||
}
|
||||
header.Set(maxAgeHeader, maxAgeHeaderVal)
|
||||
}
|
||||
|
||||
func setVaryHeaders(w http.ResponseWriter, r *http.Request) {
|
||||
header := w.Header()
|
||||
header.Add(varyHeader, originHeader)
|
||||
if r.Method == http.MethodOptions {
|
||||
header.Add(varyHeader, requestMethod)
|
||||
header.Add(varyHeader, requestHeaders)
|
||||
}
|
||||
}
|
||||
178
rest/internal/cors/handlers_test.go
Normal file
178
rest/internal/cors/handlers_test.go
Normal file
@@ -0,0 +1,178 @@
|
||||
package cors
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"net"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestCorsHandlerWithOrigins(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
origins []string
|
||||
reqOrigin string
|
||||
expect string
|
||||
}{
|
||||
{
|
||||
name: "allow all origins",
|
||||
expect: allOrigins,
|
||||
},
|
||||
{
|
||||
name: "allow one origin",
|
||||
origins: []string{"http://local"},
|
||||
reqOrigin: "http://local",
|
||||
expect: "http://local",
|
||||
},
|
||||
{
|
||||
name: "allow many origins",
|
||||
origins: []string{"http://local", "http://remote"},
|
||||
reqOrigin: "http://local",
|
||||
expect: "http://local",
|
||||
},
|
||||
{
|
||||
name: "allow all origins",
|
||||
reqOrigin: "http://local",
|
||||
expect: "*",
|
||||
},
|
||||
{
|
||||
name: "allow many origins with all mark",
|
||||
origins: []string{"http://local", "http://remote", "*"},
|
||||
reqOrigin: "http://another",
|
||||
expect: "http://another",
|
||||
},
|
||||
{
|
||||
name: "not allow origin",
|
||||
origins: []string{"http://local", "http://remote"},
|
||||
reqOrigin: "http://another",
|
||||
},
|
||||
}
|
||||
|
||||
methods := []string{
|
||||
http.MethodOptions,
|
||||
http.MethodGet,
|
||||
http.MethodPost,
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
for _, method := range methods {
|
||||
test := test
|
||||
t.Run(test.name+"-handler", func(t *testing.T) {
|
||||
r := httptest.NewRequest(method, "http://localhost", nil)
|
||||
r.Header.Set(originHeader, test.reqOrigin)
|
||||
w := httptest.NewRecorder()
|
||||
handler := NotAllowedHandler(nil, test.origins...)
|
||||
handler.ServeHTTP(w, r)
|
||||
if method == http.MethodOptions {
|
||||
assert.Equal(t, http.StatusNoContent, w.Result().StatusCode)
|
||||
} else {
|
||||
assert.Equal(t, http.StatusNotFound, w.Result().StatusCode)
|
||||
}
|
||||
assert.Equal(t, test.expect, w.Header().Get(allowOrigin))
|
||||
})
|
||||
t.Run(test.name+"-handler-custom", func(t *testing.T) {
|
||||
r := httptest.NewRequest(method, "http://localhost", nil)
|
||||
r.Header.Set(originHeader, test.reqOrigin)
|
||||
w := httptest.NewRecorder()
|
||||
handler := NotAllowedHandler(func(w http.ResponseWriter) {
|
||||
w.Header().Set("foo", "bar")
|
||||
}, test.origins...)
|
||||
handler.ServeHTTP(w, r)
|
||||
if method == http.MethodOptions {
|
||||
assert.Equal(t, http.StatusNoContent, w.Result().StatusCode)
|
||||
} else {
|
||||
assert.Equal(t, http.StatusNotFound, w.Result().StatusCode)
|
||||
}
|
||||
assert.Equal(t, test.expect, w.Header().Get(allowOrigin))
|
||||
assert.Equal(t, "bar", w.Header().Get("foo"))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
for _, method := range methods {
|
||||
test := test
|
||||
t.Run(test.name+"-middleware", func(t *testing.T) {
|
||||
r := httptest.NewRequest(method, "http://localhost", nil)
|
||||
r.Header.Set(originHeader, test.reqOrigin)
|
||||
w := httptest.NewRecorder()
|
||||
handler := Middleware(nil, test.origins...)(func(w http.ResponseWriter, r *http.Request) {
|
||||
w.WriteHeader(http.StatusOK)
|
||||
})
|
||||
handler.ServeHTTP(w, r)
|
||||
if method == http.MethodOptions {
|
||||
assert.Equal(t, http.StatusNoContent, w.Result().StatusCode)
|
||||
} else {
|
||||
assert.Equal(t, http.StatusOK, w.Result().StatusCode)
|
||||
}
|
||||
assert.Equal(t, test.expect, w.Header().Get(allowOrigin))
|
||||
})
|
||||
t.Run(test.name+"-middleware-custom", func(t *testing.T) {
|
||||
r := httptest.NewRequest(method, "http://localhost", nil)
|
||||
r.Header.Set(originHeader, test.reqOrigin)
|
||||
w := httptest.NewRecorder()
|
||||
handler := Middleware(func(header http.Header) {
|
||||
header.Set("foo", "bar")
|
||||
}, test.origins...)(func(w http.ResponseWriter, r *http.Request) {
|
||||
w.WriteHeader(http.StatusOK)
|
||||
})
|
||||
handler.ServeHTTP(w, r)
|
||||
if method == http.MethodOptions {
|
||||
assert.Equal(t, http.StatusNoContent, w.Result().StatusCode)
|
||||
} else {
|
||||
assert.Equal(t, http.StatusOK, w.Result().StatusCode)
|
||||
}
|
||||
assert.Equal(t, test.expect, w.Header().Get(allowOrigin))
|
||||
assert.Equal(t, "bar", w.Header().Get("foo"))
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestGuardedResponseWriter_Flush(t *testing.T) {
|
||||
req := httptest.NewRequest(http.MethodGet, "http://localhost", nil)
|
||||
handler := NotAllowedHandler(func(w http.ResponseWriter) {
|
||||
w.Header().Set("X-Test", "test")
|
||||
w.WriteHeader(http.StatusServiceUnavailable)
|
||||
_, err := w.Write([]byte("content"))
|
||||
assert.Nil(t, err)
|
||||
|
||||
flusher, ok := w.(http.Flusher)
|
||||
assert.True(t, ok)
|
||||
flusher.Flush()
|
||||
}, "foo.com")
|
||||
|
||||
resp := httptest.NewRecorder()
|
||||
handler.ServeHTTP(resp, req)
|
||||
assert.Equal(t, http.StatusServiceUnavailable, resp.Code)
|
||||
assert.Equal(t, "test", resp.Header().Get("X-Test"))
|
||||
assert.Equal(t, "content", resp.Body.String())
|
||||
}
|
||||
|
||||
func TestGuardedResponseWriter_Hijack(t *testing.T) {
|
||||
resp := httptest.NewRecorder()
|
||||
writer := &guardedResponseWriter{
|
||||
w: resp,
|
||||
}
|
||||
assert.NotPanics(t, func() {
|
||||
writer.Hijack()
|
||||
})
|
||||
|
||||
writer = &guardedResponseWriter{
|
||||
w: mockedHijackable{resp},
|
||||
}
|
||||
assert.NotPanics(t, func() {
|
||||
writer.Hijack()
|
||||
})
|
||||
}
|
||||
|
||||
type mockedHijackable struct {
|
||||
*httptest.ResponseRecorder
|
||||
}
|
||||
|
||||
func (m mockedHijackable) Hijack() (net.Conn, *bufio.ReadWriter, error) {
|
||||
return nil, nil, nil
|
||||
}
|
||||
@@ -5,31 +5,43 @@ import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
||||
"github.com/tal-tech/go-zero/core/logx"
|
||||
"github.com/tal-tech/go-zero/core/proc"
|
||||
)
|
||||
|
||||
// StartOption defines the method to customize http.Server.
|
||||
type StartOption func(srv *http.Server)
|
||||
|
||||
// StartHttp starts a http server.
|
||||
func StartHttp(host string, port int, handler http.Handler) error {
|
||||
func StartHttp(host string, port int, handler http.Handler, opts ...StartOption) error {
|
||||
return start(host, port, handler, func(srv *http.Server) error {
|
||||
return srv.ListenAndServe()
|
||||
})
|
||||
}, opts...)
|
||||
}
|
||||
|
||||
// StartHttps starts a https server.
|
||||
func StartHttps(host string, port int, certFile, keyFile string, handler http.Handler) error {
|
||||
func StartHttps(host string, port int, certFile, keyFile string, handler http.Handler,
|
||||
opts ...StartOption) error {
|
||||
return start(host, port, handler, func(srv *http.Server) error {
|
||||
// certFile and keyFile are set in buildHttpsServer
|
||||
return srv.ListenAndServeTLS(certFile, keyFile)
|
||||
})
|
||||
}, opts...)
|
||||
}
|
||||
|
||||
func start(host string, port int, handler http.Handler, run func(srv *http.Server) error) (err error) {
|
||||
func start(host string, port int, handler http.Handler, run func(srv *http.Server) error,
|
||||
opts ...StartOption) (err error) {
|
||||
server := &http.Server{
|
||||
Addr: fmt.Sprintf("%s:%d", host, port),
|
||||
Handler: handler,
|
||||
}
|
||||
for _, opt := range opts {
|
||||
opt(server)
|
||||
}
|
||||
|
||||
waitForCalled := proc.AddWrapUpListener(func() {
|
||||
server.Shutdown(context.Background())
|
||||
if e := server.Shutdown(context.Background()); err != nil {
|
||||
logx.Error(e)
|
||||
}
|
||||
})
|
||||
defer func() {
|
||||
if err == http.ErrServerClosed {
|
||||
|
||||
@@ -105,19 +105,22 @@ func TestPatRouter(t *testing.T) {
|
||||
t.Run(test.method+":"+test.path, func(t *testing.T) {
|
||||
routed := false
|
||||
router := NewRouter()
|
||||
err := router.Handle(test.method, "/a/:b", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
routed = true
|
||||
assert.Equal(t, 1, len(pathvar.Vars(r)))
|
||||
}))
|
||||
err := router.Handle(test.method, "/a/:b", http.HandlerFunc(
|
||||
func(w http.ResponseWriter, r *http.Request) {
|
||||
routed = true
|
||||
assert.Equal(t, 1, len(pathvar.Vars(r)))
|
||||
}))
|
||||
assert.Nil(t, err)
|
||||
err = router.Handle(test.method, "/a/b/c", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
routed = true
|
||||
assert.Nil(t, pathvar.Vars(r))
|
||||
}))
|
||||
err = router.Handle(test.method, "/a/b/c", http.HandlerFunc(
|
||||
func(w http.ResponseWriter, r *http.Request) {
|
||||
routed = true
|
||||
assert.Nil(t, pathvar.Vars(r))
|
||||
}))
|
||||
assert.Nil(t, err)
|
||||
err = router.Handle(test.method, "/b/c", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
routed = true
|
||||
}))
|
||||
err = router.Handle(test.method, "/b/c", http.HandlerFunc(
|
||||
func(w http.ResponseWriter, r *http.Request) {
|
||||
routed = true
|
||||
}))
|
||||
assert.Nil(t, err)
|
||||
|
||||
w := new(mockedResponseWriter)
|
||||
|
||||
@@ -1,27 +1,27 @@
|
||||
package rest
|
||||
|
||||
import (
|
||||
"crypto/tls"
|
||||
"log"
|
||||
"net/http"
|
||||
"path"
|
||||
"time"
|
||||
|
||||
"github.com/tal-tech/go-zero/core/logx"
|
||||
"github.com/tal-tech/go-zero/rest/handler"
|
||||
"github.com/tal-tech/go-zero/rest/httpx"
|
||||
"github.com/tal-tech/go-zero/rest/internal/cors"
|
||||
"github.com/tal-tech/go-zero/rest/router"
|
||||
)
|
||||
|
||||
type (
|
||||
runOptions struct {
|
||||
start func(*engine) error
|
||||
}
|
||||
|
||||
// RunOption defines the method to customize a Server.
|
||||
RunOption func(*Server)
|
||||
|
||||
// A Server is a http server.
|
||||
Server struct {
|
||||
ngin *engine
|
||||
opts runOptions
|
||||
ngin *engine
|
||||
router httpx.Router
|
||||
}
|
||||
)
|
||||
|
||||
@@ -45,12 +45,8 @@ func NewServer(c RestConf, opts ...RunOption) (*Server, error) {
|
||||
}
|
||||
|
||||
server := &Server{
|
||||
ngin: newEngine(c),
|
||||
opts: runOptions{
|
||||
start: func(srv *engine) error {
|
||||
return srv.Start()
|
||||
},
|
||||
},
|
||||
ngin: newEngine(c),
|
||||
router: router.NewRouter(),
|
||||
}
|
||||
|
||||
for _, opt := range opts {
|
||||
@@ -68,7 +64,7 @@ func (s *Server) AddRoutes(rs []Route, opts ...RouteOption) {
|
||||
for _, opt := range opts {
|
||||
opt(&r)
|
||||
}
|
||||
s.ngin.AddRoutes(r)
|
||||
s.ngin.addRoutes(r)
|
||||
}
|
||||
|
||||
// AddRoute adds given route into the Server.
|
||||
@@ -80,7 +76,7 @@ func (s *Server) AddRoute(r Route, opts ...RouteOption) {
|
||||
// Graceful shutdown is enabled by default.
|
||||
// Use proc.SetTimeToForceQuit to customize the graceful shutdown period.
|
||||
func (s *Server) Start() {
|
||||
handleError(s.opts.start(s.ngin))
|
||||
handleError(s.ngin.start(s.router))
|
||||
}
|
||||
|
||||
// Stop stops the Server.
|
||||
@@ -100,6 +96,24 @@ func ToMiddleware(handler func(next http.Handler) http.Handler) Middleware {
|
||||
}
|
||||
}
|
||||
|
||||
// WithCors returns a func to enable CORS for given origin, or default to all origins (*).
|
||||
func WithCors(origin ...string) RunOption {
|
||||
return func(server *Server) {
|
||||
server.router.SetNotAllowedHandler(cors.NotAllowedHandler(nil, origin...))
|
||||
server.Use(cors.Middleware(nil, origin...))
|
||||
}
|
||||
}
|
||||
|
||||
// WithCustomCors returns a func to enable CORS for given origin, or default to all origins (*),
|
||||
// fn lets caller customizing the response.
|
||||
func WithCustomCors(middlewareFn func(header http.Header), notAllowedFn func(http.ResponseWriter),
|
||||
origin ...string) RunOption {
|
||||
return func(server *Server) {
|
||||
server.router.SetNotAllowedHandler(cors.NotAllowedHandler(notAllowedFn, origin...))
|
||||
server.Use(cors.Middleware(middlewareFn, origin...))
|
||||
}
|
||||
}
|
||||
|
||||
// WithJwt returns a func to enable jwt authentication in given route.
|
||||
func WithJwt(secret string) RouteOption {
|
||||
return func(r *featuredRoutes) {
|
||||
@@ -148,16 +162,32 @@ func WithMiddleware(middleware Middleware, rs ...Route) []Route {
|
||||
|
||||
// WithNotFoundHandler returns a RunOption with not found handler set to given handler.
|
||||
func WithNotFoundHandler(handler http.Handler) RunOption {
|
||||
rt := router.NewRouter()
|
||||
rt.SetNotFoundHandler(handler)
|
||||
return WithRouter(rt)
|
||||
return func(server *Server) {
|
||||
server.router.SetNotFoundHandler(handler)
|
||||
}
|
||||
}
|
||||
|
||||
// WithNotAllowedHandler returns a RunOption with not allowed handler set to given handler.
|
||||
func WithNotAllowedHandler(handler http.Handler) RunOption {
|
||||
rt := router.NewRouter()
|
||||
rt.SetNotAllowedHandler(handler)
|
||||
return WithRouter(rt)
|
||||
return func(server *Server) {
|
||||
server.router.SetNotAllowedHandler(handler)
|
||||
}
|
||||
}
|
||||
|
||||
// WithPrefix adds group as a prefix to the route paths.
|
||||
func WithPrefix(group string) RouteOption {
|
||||
return func(r *featuredRoutes) {
|
||||
var routes []Route
|
||||
for _, rt := range r.routes {
|
||||
p := path.Join(group, rt.Path)
|
||||
routes = append(routes, Route{
|
||||
Method: rt.Method,
|
||||
Path: p,
|
||||
Handler: rt.Handler,
|
||||
})
|
||||
}
|
||||
r.routes = routes
|
||||
}
|
||||
}
|
||||
|
||||
// WithPriority returns a RunOption with priority.
|
||||
@@ -170,9 +200,7 @@ func WithPriority() RouteOption {
|
||||
// WithRouter returns a RunOption that make server run with given router.
|
||||
func WithRouter(router httpx.Router) RunOption {
|
||||
return func(server *Server) {
|
||||
server.opts.start = func(srv *engine) error {
|
||||
return srv.StartWithRouter(router)
|
||||
}
|
||||
server.router = router
|
||||
}
|
||||
}
|
||||
|
||||
@@ -186,17 +214,31 @@ func WithSignature(signature SignatureConf) RouteOption {
|
||||
}
|
||||
}
|
||||
|
||||
// WithTimeout returns a RouteOption to set timeout with given value.
|
||||
func WithTimeout(timeout time.Duration) RouteOption {
|
||||
return func(r *featuredRoutes) {
|
||||
r.timeout = timeout
|
||||
}
|
||||
}
|
||||
|
||||
// WithTLSConfig returns a RunOption that with given tls config.
|
||||
func WithTLSConfig(cfg *tls.Config) RunOption {
|
||||
return func(srv *Server) {
|
||||
srv.ngin.setTlsConfig(cfg)
|
||||
}
|
||||
}
|
||||
|
||||
// WithUnauthorizedCallback returns a RunOption that with given unauthorized callback set.
|
||||
func WithUnauthorizedCallback(callback handler.UnauthorizedCallback) RunOption {
|
||||
return func(engine *Server) {
|
||||
engine.ngin.SetUnauthorizedCallback(callback)
|
||||
return func(srv *Server) {
|
||||
srv.ngin.setUnauthorizedCallback(callback)
|
||||
}
|
||||
}
|
||||
|
||||
// WithUnsignedCallback returns a RunOption that with given unsigned callback set.
|
||||
func WithUnsignedCallback(callback handler.UnsignedCallback) RunOption {
|
||||
return func(engine *Server) {
|
||||
engine.ngin.SetUnsignedCallback(callback)
|
||||
return func(srv *Server) {
|
||||
srv.ngin.setUnsignedCallback(callback)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,11 +1,13 @@
|
||||
package rest
|
||||
|
||||
import (
|
||||
"crypto/tls"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/tal-tech/go-zero/core/conf"
|
||||
@@ -20,11 +22,6 @@ Port: 54321
|
||||
`
|
||||
var cnf RestConf
|
||||
assert.Nil(t, conf.LoadConfigFromYamlBytes([]byte(configYaml), &cnf))
|
||||
failStart := func(server *Server) {
|
||||
server.opts.start = func(e *engine) error {
|
||||
return http.ErrServerClosed
|
||||
}
|
||||
}
|
||||
|
||||
tests := []struct {
|
||||
c RestConf
|
||||
@@ -33,38 +30,40 @@ Port: 54321
|
||||
}{
|
||||
{
|
||||
c: RestConf{},
|
||||
opts: []RunOption{failStart},
|
||||
opts: []RunOption{WithRouter(mockedRouter{}), WithCors()},
|
||||
fail: true,
|
||||
},
|
||||
{
|
||||
c: cnf,
|
||||
opts: []RunOption{failStart},
|
||||
opts: []RunOption{WithRouter(mockedRouter{})},
|
||||
},
|
||||
{
|
||||
c: cnf,
|
||||
opts: []RunOption{WithNotAllowedHandler(nil), failStart},
|
||||
opts: []RunOption{WithRouter(mockedRouter{}), WithNotAllowedHandler(nil)},
|
||||
},
|
||||
{
|
||||
c: cnf,
|
||||
opts: []RunOption{WithNotFoundHandler(nil), failStart},
|
||||
opts: []RunOption{WithNotFoundHandler(nil), WithRouter(mockedRouter{})},
|
||||
},
|
||||
{
|
||||
c: cnf,
|
||||
opts: []RunOption{WithUnauthorizedCallback(nil), failStart},
|
||||
opts: []RunOption{WithUnauthorizedCallback(nil), WithRouter(mockedRouter{})},
|
||||
},
|
||||
{
|
||||
c: cnf,
|
||||
opts: []RunOption{WithUnsignedCallback(nil), failStart},
|
||||
opts: []RunOption{WithUnsignedCallback(nil), WithRouter(mockedRouter{})},
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
srv, err := NewServer(test.c, test.opts...)
|
||||
var srv *Server
|
||||
var err error
|
||||
if test.fail {
|
||||
_, err = NewServer(test.c, test.opts...)
|
||||
assert.NotNil(t, err)
|
||||
}
|
||||
if err != nil {
|
||||
continue
|
||||
} else {
|
||||
srv = MustNewServer(test.c, test.opts...)
|
||||
}
|
||||
|
||||
srv.Use(ToMiddleware(func(next http.Handler) http.Handler {
|
||||
@@ -78,8 +77,21 @@ Port: 54321
|
||||
Handler: nil,
|
||||
}, WithJwt("thesecret"), WithSignature(SignatureConf{}),
|
||||
WithJwtTransition("preivous", "thenewone"))
|
||||
srv.Start()
|
||||
srv.Stop()
|
||||
|
||||
func() {
|
||||
defer func() {
|
||||
p := recover()
|
||||
switch v := p.(type) {
|
||||
case error:
|
||||
assert.Equal(t, "foo", v.Error())
|
||||
default:
|
||||
t.Fail()
|
||||
}
|
||||
}()
|
||||
|
||||
srv.Start()
|
||||
srv.Stop()
|
||||
}()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -178,6 +190,9 @@ func TestMultiMiddlewares(t *testing.T) {
|
||||
next.ServeHTTP(w, r)
|
||||
}
|
||||
},
|
||||
ToMiddleware(func(next http.Handler) http.Handler {
|
||||
return next
|
||||
}),
|
||||
}, Route{
|
||||
Method: http.MethodGet,
|
||||
Path: "/first/:name/:year",
|
||||
@@ -212,8 +227,105 @@ func TestMultiMiddlewares(t *testing.T) {
|
||||
}, m)
|
||||
}
|
||||
|
||||
func TestWithPrefix(t *testing.T) {
|
||||
fr := featuredRoutes{
|
||||
routes: []Route{
|
||||
{
|
||||
Path: "/hello",
|
||||
},
|
||||
{
|
||||
Path: "/world",
|
||||
},
|
||||
},
|
||||
}
|
||||
WithPrefix("/api")(&fr)
|
||||
var vals []string
|
||||
for _, r := range fr.routes {
|
||||
vals = append(vals, r.Path)
|
||||
}
|
||||
assert.EqualValues(t, []string{"/api/hello", "/api/world"}, vals)
|
||||
}
|
||||
|
||||
func TestWithPriority(t *testing.T) {
|
||||
var fr featuredRoutes
|
||||
WithPriority()(&fr)
|
||||
assert.True(t, fr.priority)
|
||||
}
|
||||
|
||||
func TestWithTimeout(t *testing.T) {
|
||||
var fr featuredRoutes
|
||||
WithTimeout(time.Hour)(&fr)
|
||||
assert.Equal(t, time.Hour, fr.timeout)
|
||||
}
|
||||
|
||||
func TestWithTLSConfig(t *testing.T) {
|
||||
const configYaml = `
|
||||
Name: foo
|
||||
Port: 54321
|
||||
`
|
||||
var cnf RestConf
|
||||
assert.Nil(t, conf.LoadConfigFromYamlBytes([]byte(configYaml), &cnf))
|
||||
|
||||
testConfig := &tls.Config{
|
||||
CipherSuites: []uint16{
|
||||
tls.TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
|
||||
},
|
||||
}
|
||||
|
||||
testCases := []struct {
|
||||
c RestConf
|
||||
opts []RunOption
|
||||
res *tls.Config
|
||||
}{
|
||||
{
|
||||
c: cnf,
|
||||
opts: []RunOption{WithTLSConfig(testConfig)},
|
||||
res: testConfig,
|
||||
},
|
||||
{
|
||||
c: cnf,
|
||||
opts: []RunOption{WithUnsignedCallback(nil)},
|
||||
res: nil,
|
||||
},
|
||||
}
|
||||
|
||||
for _, testCase := range testCases {
|
||||
srv, err := NewServer(testCase.c, testCase.opts...)
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, srv.ngin.tlsConfig, testCase.res)
|
||||
}
|
||||
}
|
||||
|
||||
func TestWithCors(t *testing.T) {
|
||||
const configYaml = `
|
||||
Name: foo
|
||||
Port: 54321
|
||||
`
|
||||
var cnf RestConf
|
||||
assert.Nil(t, conf.LoadConfigFromYamlBytes([]byte(configYaml), &cnf))
|
||||
rt := router.NewRouter()
|
||||
srv, err := NewServer(cnf, WithRouter(rt))
|
||||
assert.Nil(t, err)
|
||||
|
||||
opt := WithCors("local")
|
||||
opt(srv)
|
||||
}
|
||||
|
||||
func TestWithCustomCors(t *testing.T) {
|
||||
const configYaml = `
|
||||
Name: foo
|
||||
Port: 54321
|
||||
`
|
||||
var cnf RestConf
|
||||
assert.Nil(t, conf.LoadConfigFromYamlBytes([]byte(configYaml), &cnf))
|
||||
rt := router.NewRouter()
|
||||
srv, err := NewServer(cnf, WithRouter(rt))
|
||||
assert.Nil(t, err)
|
||||
|
||||
opt := WithCustomCors(func(header http.Header) {
|
||||
header.Set("foo", "bar")
|
||||
}, func(w http.ResponseWriter) {
|
||||
w.WriteHeader(http.StatusOK)
|
||||
}, "local")
|
||||
opt(srv)
|
||||
}
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
package rest
|
||||
|
||||
import "net/http"
|
||||
import (
|
||||
"net/http"
|
||||
"time"
|
||||
)
|
||||
|
||||
type (
|
||||
// Middleware defines the middleware method.
|
||||
@@ -28,6 +31,7 @@ type (
|
||||
}
|
||||
|
||||
featuredRoutes struct {
|
||||
timeout time.Duration
|
||||
priority bool
|
||||
jwt jwtSetting
|
||||
signature signatureSetting
|
||||
|
||||
@@ -25,6 +25,7 @@ func DartCommand(c *cli.Context) error {
|
||||
return err
|
||||
}
|
||||
|
||||
api.Service = api.Service.JoinPrefix()
|
||||
if !strings.HasSuffix(dir, "/") {
|
||||
dir = dir + "/"
|
||||
}
|
||||
|
||||
@@ -42,14 +42,15 @@ func DocCommand(c *cli.Context) error {
|
||||
return err
|
||||
}
|
||||
|
||||
for _, path := range files {
|
||||
api, err := parser.Parse(path)
|
||||
for _, p := range files {
|
||||
api, err := parser.Parse(p)
|
||||
if err != nil {
|
||||
return fmt.Errorf("parse file: %s, err: %s", path, err.Error())
|
||||
return fmt.Errorf("parse file: %s, err: %s", p, err.Error())
|
||||
}
|
||||
|
||||
err = genDoc(api, filepath.Dir(filepath.Join(outputDir, path[len(dir):])),
|
||||
strings.Replace(path[len(filepath.Dir(path)):], ".api", ".md", 1))
|
||||
api.Service = api.Service.JoinPrefix()
|
||||
err = genDoc(api, filepath.Dir(filepath.Join(outputDir, p[len(dir):])),
|
||||
strings.Replace(p[len(filepath.Dir(p)):], ".api", ".md", 1))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -3,8 +3,10 @@ package gogen
|
||||
import (
|
||||
"fmt"
|
||||
"path"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/tal-tech/go-zero/tools/goctl/api/parser/g4/gen/api"
|
||||
"github.com/tal-tech/go-zero/tools/goctl/api/spec"
|
||||
"github.com/tal-tech/go-zero/tools/goctl/config"
|
||||
ctlutil "github.com/tal-tech/go-zero/tools/goctl/util"
|
||||
@@ -64,12 +66,8 @@ func genLogicByRoute(dir, rootPkg string, cfg *config.Config, group spec.Group,
|
||||
var requestString string
|
||||
if len(route.ResponseTypeName()) > 0 {
|
||||
resp := responseGoTypeName(route, typesPacket)
|
||||
responseString = "(" + resp + ", error)"
|
||||
if strings.HasPrefix(resp, "*") {
|
||||
returnString = fmt.Sprintf("return &%s{}, nil", strings.TrimPrefix(resp, "*"))
|
||||
} else {
|
||||
returnString = fmt.Sprintf("return %s{}, nil", resp)
|
||||
}
|
||||
responseString = "(resp " + resp + ", err error)"
|
||||
returnString = "return"
|
||||
} else {
|
||||
responseString = "error"
|
||||
returnString = "return nil"
|
||||
@@ -116,9 +114,47 @@ func genLogicImports(route spec.Route, parentPkg string) string {
|
||||
var imports []string
|
||||
imports = append(imports, `"context"`+"\n")
|
||||
imports = append(imports, fmt.Sprintf("\"%s\"", ctlutil.JoinPackages(parentPkg, contextDir)))
|
||||
if len(route.ResponseTypeName()) > 0 || len(route.RequestTypeName()) > 0 {
|
||||
if shallImportTypesPackage(route) {
|
||||
imports = append(imports, fmt.Sprintf("\"%s\"\n", ctlutil.JoinPackages(parentPkg, typesDir)))
|
||||
}
|
||||
imports = append(imports, fmt.Sprintf("\"%s/core/logx\"", vars.ProjectOpenSourceURL))
|
||||
return strings.Join(imports, "\n\t")
|
||||
}
|
||||
|
||||
func onlyPrimitiveTypes(val string) bool {
|
||||
fields := strings.FieldsFunc(val, func(r rune) bool {
|
||||
return r == '[' || r == ']' || r == ' '
|
||||
})
|
||||
|
||||
for _, field := range fields {
|
||||
if field == "map" {
|
||||
continue
|
||||
}
|
||||
// ignore array dimension number, like [5]int
|
||||
if _, err := strconv.Atoi(field); err == nil {
|
||||
continue
|
||||
}
|
||||
if !api.IsBasicType(field) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
func shallImportTypesPackage(route spec.Route) bool {
|
||||
if len(route.RequestTypeName()) > 0 {
|
||||
return true
|
||||
}
|
||||
|
||||
respTypeName := route.ResponseTypeName()
|
||||
if len(respTypeName) == 0 {
|
||||
return false
|
||||
}
|
||||
|
||||
if onlyPrimitiveTypes(respTypeName) {
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
@@ -27,24 +27,27 @@ import (
|
||||
{{.importPackages}}
|
||||
)
|
||||
|
||||
func RegisterHandlers(engine *rest.Server, serverCtx *svc.ServiceContext) {
|
||||
func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
|
||||
{{.routesAdditions}}
|
||||
}
|
||||
`
|
||||
routesAdditionTemplate = `
|
||||
engine.AddRoutes(
|
||||
{{.routes}} {{.jwt}}{{.signature}}
|
||||
server.AddRoutes(
|
||||
{{.routes}} {{.jwt}}{{.signature}} {{.prefix}}
|
||||
)
|
||||
`
|
||||
)
|
||||
|
||||
var mapping = map[string]string{
|
||||
"delete": "http.MethodDelete",
|
||||
"get": "http.MethodGet",
|
||||
"head": "http.MethodHead",
|
||||
"post": "http.MethodPost",
|
||||
"put": "http.MethodPut",
|
||||
"patch": "http.MethodPatch",
|
||||
"delete": "http.MethodDelete",
|
||||
"get": "http.MethodGet",
|
||||
"head": "http.MethodHead",
|
||||
"post": "http.MethodPost",
|
||||
"put": "http.MethodPut",
|
||||
"patch": "http.MethodPatch",
|
||||
"connect": "http.MethodConnect",
|
||||
"options": "http.MethodOptions",
|
||||
"trace": "http.MethodTrace",
|
||||
}
|
||||
|
||||
type (
|
||||
@@ -54,6 +57,7 @@ type (
|
||||
signatureEnabled bool
|
||||
authName string
|
||||
middlewares []string
|
||||
prefix string
|
||||
}
|
||||
route struct {
|
||||
method string
|
||||
@@ -87,10 +91,14 @@ func genRoutes(dir, rootPkg string, cfg *config.Config, api *spec.ApiSpec) error
|
||||
if g.jwtEnabled {
|
||||
jwt = fmt.Sprintf("\n rest.WithJwt(serverCtx.Config.%s.AccessSecret),", g.authName)
|
||||
}
|
||||
var signature string
|
||||
var signature, prefix string
|
||||
if g.signatureEnabled {
|
||||
signature = "\n rest.WithSignature(serverCtx.Config.Signature),"
|
||||
}
|
||||
if len(g.prefix) > 0 {
|
||||
prefix = fmt.Sprintf(`
|
||||
rest.WithPrefix("%s"),`, g.prefix)
|
||||
}
|
||||
|
||||
var routes string
|
||||
if len(g.middlewares) > 0 {
|
||||
@@ -111,6 +119,7 @@ func genRoutes(dir, rootPkg string, cfg *config.Config, api *spec.ApiSpec) error
|
||||
"routes": routes,
|
||||
"jwt": jwt,
|
||||
"signature": signature,
|
||||
"prefix": prefix,
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -200,6 +209,13 @@ func getRoutes(api *spec.ApiSpec) ([]group, error) {
|
||||
groupedRoutes.middlewares = append(groupedRoutes.middlewares,
|
||||
strings.Split(middleware, ",")...)
|
||||
}
|
||||
prefix := g.GetAnnotation(spec.RoutePrefixKey)
|
||||
prefix = strings.ReplaceAll(prefix, `"`, "")
|
||||
prefix = strings.TrimSpace(prefix)
|
||||
if len(prefix) > 0 {
|
||||
prefix = path.Join("/", prefix)
|
||||
groupedRoutes.prefix = prefix
|
||||
}
|
||||
routes = append(routes, groupedRoutes)
|
||||
}
|
||||
|
||||
|
||||
@@ -28,6 +28,7 @@ func JavaCommand(c *cli.Context) error {
|
||||
return err
|
||||
}
|
||||
|
||||
api.Service = api.Service.JoinPrefix()
|
||||
packetName := strings.TrimSuffix(api.Service.Name, "-api")
|
||||
logx.Must(util.MkdirIfNotExist(dir))
|
||||
logx.Must(genPacket(dir, packetName, api))
|
||||
|
||||
@@ -27,6 +27,7 @@ func KtCommand(c *cli.Context) error {
|
||||
return e
|
||||
}
|
||||
|
||||
api.Service = api.Service.JoinPrefix()
|
||||
e = genBase(dir, pkg, api)
|
||||
if e != nil {
|
||||
return e
|
||||
|
||||
@@ -24,7 +24,7 @@ type Response {
|
||||
|
||||
service {{.name}}-api {
|
||||
@handler {{.handler}}Handler
|
||||
get /from/:name(Request) returns (Response);
|
||||
get /from/:name(Request) returns (Response)
|
||||
}
|
||||
`
|
||||
|
||||
|
||||
@@ -63,11 +63,11 @@ serviceApi: {match(p,"service")}serviceToken=ID serviceName lbrace='{' servi
|
||||
serviceRoute: atDoc? (atServer|atHandler) route;
|
||||
atDoc: ATDOC lp='('? ((kvLit+)|STRING) rp=')'?;
|
||||
atHandler: ATHANDLER ID;
|
||||
route: {checkHttpMethod(p)}httpMethod=ID path request=body? returnToken=ID? response=replybody?;
|
||||
route: {checkHTTPMethod(p)}httpMethod=ID path request=body? returnToken=ID? response=replybody?;
|
||||
body: lp='(' (ID)? rp=')';
|
||||
replybody: lp='(' dataType? rp=')';
|
||||
// kv
|
||||
kvLit: key=ID {checkKeyValue(p)}value=LINE_VALUE;
|
||||
|
||||
serviceName: (ID '-'?)+;
|
||||
path: (('/' (ID ('-' ID)*))|('/:' (ID ('-' ID)?)))+;
|
||||
path: (('/' (ID ('-' ID)*))|('/:' (ID ('-' ID)?)))+ | '/';
|
||||
@@ -2,11 +2,14 @@ package ast
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"path"
|
||||
"sort"
|
||||
|
||||
"github.com/tal-tech/go-zero/tools/goctl/api/parser/g4/gen/api"
|
||||
)
|
||||
|
||||
const prefixKey = "prefix"
|
||||
|
||||
// Api describes syntax for api
|
||||
type Api struct {
|
||||
LinePrefix string
|
||||
@@ -49,8 +52,15 @@ func (v *ApiVisitor) acceptService(root, final *Api) {
|
||||
}
|
||||
v.duplicateServerItemCheck(service)
|
||||
|
||||
var prefix string
|
||||
if service.AtServer != nil {
|
||||
p := service.AtServer.Kv.Get(prefixKey)
|
||||
if p != nil {
|
||||
prefix = p.Text()
|
||||
}
|
||||
}
|
||||
for _, route := range service.ServiceApi.ServiceRoute {
|
||||
uniqueRoute := fmt.Sprintf("%s %s", route.Route.Method.Text(), route.Route.Path.Text())
|
||||
uniqueRoute := fmt.Sprintf("%s %s", route.Route.Method.Text(), path.Join(prefix, route.Route.Path.Text()))
|
||||
if _, ok := final.routeM[uniqueRoute]; ok {
|
||||
v.panic(route.Route.Method, fmt.Sprintf("duplicate route '%s'", uniqueRoute))
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package ast
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
@@ -113,13 +114,13 @@ func (p *Parser) parse(filename, content string) (*Api, error) {
|
||||
apiAstList = append(apiAstList, root)
|
||||
for _, imp := range root.Import {
|
||||
dir := filepath.Dir(p.src)
|
||||
path := filepath.Join(dir, imp.Value.Text())
|
||||
data, err := p.readContent(path)
|
||||
imp := filepath.Join(dir, imp.Value.Text())
|
||||
data, err := p.readContent(imp)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
nestedApi, err := p.invoke(path, data)
|
||||
nestedApi, err := p.invoke(imp, data)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -196,8 +197,8 @@ func (p *Parser) valid(mainApi, nestedApi *Api) error {
|
||||
if handler.IsNotNil() {
|
||||
handlerName := handler.Text()
|
||||
handlerMap[handlerName] = Holder
|
||||
path := fmt.Sprintf("%s://%s", g.Route.Method.Text(), g.Route.Path.Text())
|
||||
routeMap[path] = Holder
|
||||
route := fmt.Sprintf("%s://%s", g.Route.Method.Text(), g.Route.Path.Text())
|
||||
routeMap[route] = Holder
|
||||
}
|
||||
}
|
||||
|
||||
@@ -239,6 +240,13 @@ func (p *Parser) valid(mainApi, nestedApi *Api) error {
|
||||
|
||||
func (p *Parser) duplicateRouteCheck(nestedApi *Api, mainHandlerMap, mainRouteMap map[string]PlaceHolder) error {
|
||||
for _, each := range nestedApi.Service {
|
||||
var prefix string
|
||||
if each.AtServer != nil {
|
||||
p := each.AtServer.Kv.Get(prefixKey)
|
||||
if p != nil {
|
||||
prefix = p.Text()
|
||||
}
|
||||
}
|
||||
for _, r := range each.ServiceApi.ServiceRoute {
|
||||
handler := r.GetHandler()
|
||||
if !handler.IsNotNil() {
|
||||
@@ -250,8 +258,8 @@ func (p *Parser) duplicateRouteCheck(nestedApi *Api, mainHandlerMap, mainRouteMa
|
||||
nestedApi.LinePrefix, handler.Line(), handler.Column(), handler.Text())
|
||||
}
|
||||
|
||||
path := fmt.Sprintf("%s://%s", r.Route.Method.Text(), r.Route.Path.Text())
|
||||
if _, ok := mainRouteMap[path]; ok {
|
||||
p := fmt.Sprintf("%s://%s", r.Route.Method.Text(), path.Join(prefix, r.Route.Path.Text()))
|
||||
if _, ok := mainRouteMap[p]; ok {
|
||||
return fmt.Errorf("%s line %d:%d duplicate route '%s'",
|
||||
nestedApi.LinePrefix, r.Route.Method.Line(), r.Route.Method.Column(), r.Route.Method.Text()+" "+r.Route.Path.Text())
|
||||
}
|
||||
|
||||
@@ -212,24 +212,40 @@ func (v *ApiVisitor) VisitRoute(ctx *api.RouteContext) interface{} {
|
||||
// VisitBody implements from api.BaseApiParserVisitor
|
||||
func (v *ApiVisitor) VisitBody(ctx *api.BodyContext) interface{} {
|
||||
if ctx.ID() == nil {
|
||||
if v.debug {
|
||||
msg := fmt.Sprintf(
|
||||
`%s line %d: expr "()" is deprecated, if there has no request body, please omit it`,
|
||||
v.prefix,
|
||||
ctx.GetStart().GetLine(),
|
||||
)
|
||||
v.log.Warning(msg)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
idRxpr := v.newExprWithTerminalNode(ctx.ID())
|
||||
if api.IsGolangKeyWord(idRxpr.Text()) {
|
||||
v.panic(idRxpr, fmt.Sprintf("expecting 'ID', but found golang keyword '%s'", idRxpr.Text()))
|
||||
idExpr := v.newExprWithTerminalNode(ctx.ID())
|
||||
if api.IsGolangKeyWord(idExpr.Text()) {
|
||||
v.panic(idExpr, fmt.Sprintf("expecting 'ID', but found golang keyword '%s'", idExpr.Text()))
|
||||
}
|
||||
|
||||
return &Body{
|
||||
Lp: v.newExprWithToken(ctx.GetLp()),
|
||||
Rp: v.newExprWithToken(ctx.GetRp()),
|
||||
Name: &Literal{Literal: idRxpr},
|
||||
Name: &Literal{Literal: idExpr},
|
||||
}
|
||||
}
|
||||
|
||||
// VisitReplybody implements from api.BaseApiParserVisitor
|
||||
func (v *ApiVisitor) VisitReplybody(ctx *api.ReplybodyContext) interface{} {
|
||||
if ctx.DataType() == nil {
|
||||
if v.debug {
|
||||
msg := fmt.Sprintf(
|
||||
`%s line %d: expr "returns ()" or "()" is deprecated, if there has no response body, please omit it`,
|
||||
v.prefix,
|
||||
ctx.GetStart().GetLine(),
|
||||
)
|
||||
v.log.Warning(msg)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -251,11 +267,8 @@ func (v *ApiVisitor) VisitReplybody(ctx *api.ReplybodyContext) interface{} {
|
||||
}
|
||||
case *Literal:
|
||||
lit := dataType.Literal.Text()
|
||||
if api.IsGolangKeyWord(dataType.Literal.Text()) {
|
||||
v.panic(dataType.Literal, fmt.Sprintf("expecting 'ID', but found golang keyword '%s'", dataType.Literal.Text()))
|
||||
}
|
||||
if api.IsBasicType(lit) {
|
||||
v.panic(dt.Expr(), fmt.Sprintf("unsupport %s", dt.Expr().Text()))
|
||||
if api.IsGolangKeyWord(lit) {
|
||||
v.panic(dataType.Literal, fmt.Sprintf("expecting 'ID', but found golang keyword '%s'", lit))
|
||||
}
|
||||
default:
|
||||
v.panic(dt.Expr(), fmt.Sprintf("unsupport %s", dt.Expr().Text()))
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
// Code generated from tools/goctl/api/parser/g4/ApiParser.g4 by ANTLR 4.9. DO NOT EDIT.
|
||||
|
||||
package api // ApiParser
|
||||
import "github.com/zeromicro/antlr"
|
||||
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
// Code generated from tools/goctl/api/parser/g4/ApiParser.g4 by ANTLR 4.9. DO NOT EDIT.
|
||||
|
||||
package api
|
||||
|
||||
import (
|
||||
@@ -10,10 +8,8 @@ import (
|
||||
)
|
||||
|
||||
// Suppress unused import error
|
||||
var (
|
||||
_ = fmt.Printf
|
||||
_ = unicode.IsLetter
|
||||
)
|
||||
var _ = fmt.Printf
|
||||
var _ = unicode.IsLetter
|
||||
|
||||
var serializedLexerAtn = []uint16{
|
||||
3, 24715, 42794, 33075, 47597, 16764, 15335, 30598, 22884, 2, 25, 266,
|
||||
|
||||
5304
tools/goctl/api/parser/g4/gen/api/apiparser_parser.go
Normal file → Executable file
5304
tools/goctl/api/parser/g4/gen/api/apiparser_parser.go
Normal file → Executable file
File diff suppressed because it is too large
Load Diff
615
tools/goctl/api/parser/g4/gen/api/apiparser_parser1.go
Executable file
615
tools/goctl/api/parser/g4/gen/api/apiparser_parser1.go
Executable file
@@ -0,0 +1,615 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
|
||||
"github.com/zeromicro/antlr"
|
||||
)
|
||||
|
||||
// Part 1
|
||||
// The apiparser_parser.go file was split into multiple files because it
|
||||
// was too large and caused a possible memory overflow during goctl installation.
|
||||
|
||||
func (s *SyntaxLitContext) GetParser() antlr.Parser { return s.parser }
|
||||
|
||||
func (s *SyntaxLitContext) GetSyntaxToken() antlr.Token { return s.syntaxToken }
|
||||
|
||||
func (s *SyntaxLitContext) GetAssign() antlr.Token { return s.assign }
|
||||
|
||||
func (s *SyntaxLitContext) GetVersion() antlr.Token { return s.version }
|
||||
|
||||
func (s *SyntaxLitContext) SetSyntaxToken(v antlr.Token) { s.syntaxToken = v }
|
||||
|
||||
func (s *SyntaxLitContext) SetAssign(v antlr.Token) { s.assign = v }
|
||||
|
||||
func (s *SyntaxLitContext) SetVersion(v antlr.Token) { s.version = v }
|
||||
|
||||
func (s *SyntaxLitContext) ID() antlr.TerminalNode {
|
||||
return s.GetToken(ApiParserParserID, 0)
|
||||
}
|
||||
|
||||
func (s *SyntaxLitContext) STRING() antlr.TerminalNode {
|
||||
return s.GetToken(ApiParserParserSTRING, 0)
|
||||
}
|
||||
|
||||
func (s *SyntaxLitContext) GetRuleContext() antlr.RuleContext {
|
||||
return s
|
||||
}
|
||||
|
||||
func (s *SyntaxLitContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string {
|
||||
return antlr.TreesStringTree(s, ruleNames, recog)
|
||||
}
|
||||
|
||||
func (s *SyntaxLitContext) Accept(visitor antlr.ParseTreeVisitor) interface{} {
|
||||
switch t := visitor.(type) {
|
||||
case ApiParserVisitor:
|
||||
return t.VisitSyntaxLit(s)
|
||||
|
||||
default:
|
||||
return t.VisitChildren(s)
|
||||
}
|
||||
}
|
||||
|
||||
func (p *ApiParserParser) SyntaxLit() (localctx ISyntaxLitContext) {
|
||||
localctx = NewSyntaxLitContext(p, p.GetParserRuleContext(), p.GetState())
|
||||
p.EnterRule(localctx, 4, ApiParserParserRULE_syntaxLit)
|
||||
|
||||
defer func() {
|
||||
p.ExitRule()
|
||||
}()
|
||||
|
||||
defer func() {
|
||||
if err := recover(); err != nil {
|
||||
if v, ok := err.(antlr.RecognitionException); ok {
|
||||
localctx.SetException(v)
|
||||
p.GetErrorHandler().ReportError(p, v)
|
||||
p.GetErrorHandler().Recover(p, v)
|
||||
} else {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
p.EnterOuterAlt(localctx, 1)
|
||||
match(p, "syntax")
|
||||
{
|
||||
p.SetState(88)
|
||||
|
||||
var _m = p.Match(ApiParserParserID)
|
||||
|
||||
localctx.(*SyntaxLitContext).syntaxToken = _m
|
||||
}
|
||||
{
|
||||
p.SetState(89)
|
||||
|
||||
var _m = p.Match(ApiParserParserT__0)
|
||||
|
||||
localctx.(*SyntaxLitContext).assign = _m
|
||||
}
|
||||
checkVersion(p)
|
||||
{
|
||||
p.SetState(91)
|
||||
|
||||
var _m = p.Match(ApiParserParserSTRING)
|
||||
|
||||
localctx.(*SyntaxLitContext).version = _m
|
||||
}
|
||||
|
||||
return localctx
|
||||
}
|
||||
|
||||
// IImportSpecContext is an interface to support dynamic dispatch.
|
||||
type IImportSpecContext interface {
|
||||
antlr.ParserRuleContext
|
||||
|
||||
// GetParser returns the parser.
|
||||
GetParser() antlr.Parser
|
||||
|
||||
// IsImportSpecContext differentiates from other interfaces.
|
||||
IsImportSpecContext()
|
||||
}
|
||||
|
||||
type ImportSpecContext struct {
|
||||
*antlr.BaseParserRuleContext
|
||||
parser antlr.Parser
|
||||
}
|
||||
|
||||
func NewEmptyImportSpecContext() *ImportSpecContext {
|
||||
var p = new(ImportSpecContext)
|
||||
p.BaseParserRuleContext = antlr.NewBaseParserRuleContext(nil, -1)
|
||||
p.RuleIndex = ApiParserParserRULE_importSpec
|
||||
return p
|
||||
}
|
||||
|
||||
func (*ImportSpecContext) IsImportSpecContext() {}
|
||||
|
||||
func NewImportSpecContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *ImportSpecContext {
|
||||
var p = new(ImportSpecContext)
|
||||
|
||||
p.BaseParserRuleContext = antlr.NewBaseParserRuleContext(parent, invokingState)
|
||||
|
||||
p.parser = parser
|
||||
p.RuleIndex = ApiParserParserRULE_importSpec
|
||||
|
||||
return p
|
||||
}
|
||||
|
||||
func (s *ImportSpecContext) GetParser() antlr.Parser { return s.parser }
|
||||
|
||||
func (s *ImportSpecContext) ImportLit() IImportLitContext {
|
||||
var t = s.GetTypedRuleContext(reflect.TypeOf((*IImportLitContext)(nil)).Elem(), 0)
|
||||
|
||||
if t == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
return t.(IImportLitContext)
|
||||
}
|
||||
|
||||
func (s *ImportSpecContext) ImportBlock() IImportBlockContext {
|
||||
var t = s.GetTypedRuleContext(reflect.TypeOf((*IImportBlockContext)(nil)).Elem(), 0)
|
||||
|
||||
if t == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
return t.(IImportBlockContext)
|
||||
}
|
||||
|
||||
func (s *ImportSpecContext) GetRuleContext() antlr.RuleContext {
|
||||
return s
|
||||
}
|
||||
|
||||
func (s *ImportSpecContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string {
|
||||
return antlr.TreesStringTree(s, ruleNames, recog)
|
||||
}
|
||||
|
||||
func (s *ImportSpecContext) Accept(visitor antlr.ParseTreeVisitor) interface{} {
|
||||
switch t := visitor.(type) {
|
||||
case ApiParserVisitor:
|
||||
return t.VisitImportSpec(s)
|
||||
|
||||
default:
|
||||
return t.VisitChildren(s)
|
||||
}
|
||||
}
|
||||
|
||||
func (p *ApiParserParser) ImportSpec() (localctx IImportSpecContext) {
|
||||
localctx = NewImportSpecContext(p, p.GetParserRuleContext(), p.GetState())
|
||||
p.EnterRule(localctx, 6, ApiParserParserRULE_importSpec)
|
||||
|
||||
defer func() {
|
||||
p.ExitRule()
|
||||
}()
|
||||
|
||||
defer func() {
|
||||
if err := recover(); err != nil {
|
||||
if v, ok := err.(antlr.RecognitionException); ok {
|
||||
localctx.SetException(v)
|
||||
p.GetErrorHandler().ReportError(p, v)
|
||||
p.GetErrorHandler().Recover(p, v)
|
||||
} else {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
p.SetState(95)
|
||||
p.GetErrorHandler().Sync(p)
|
||||
switch p.GetInterpreter().AdaptivePredict(p.GetTokenStream(), 2, p.GetParserRuleContext()) {
|
||||
case 1:
|
||||
p.EnterOuterAlt(localctx, 1)
|
||||
{
|
||||
p.SetState(93)
|
||||
p.ImportLit()
|
||||
}
|
||||
|
||||
case 2:
|
||||
p.EnterOuterAlt(localctx, 2)
|
||||
{
|
||||
p.SetState(94)
|
||||
p.ImportBlock()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return localctx
|
||||
}
|
||||
|
||||
// IImportLitContext is an interface to support dynamic dispatch.
|
||||
type IImportLitContext interface {
|
||||
antlr.ParserRuleContext
|
||||
|
||||
// GetParser returns the parser.
|
||||
GetParser() antlr.Parser
|
||||
|
||||
// GetImportToken returns the importToken token.
|
||||
GetImportToken() antlr.Token
|
||||
|
||||
// SetImportToken sets the importToken token.
|
||||
SetImportToken(antlr.Token)
|
||||
|
||||
// IsImportLitContext differentiates from other interfaces.
|
||||
IsImportLitContext()
|
||||
}
|
||||
|
||||
type ImportLitContext struct {
|
||||
*antlr.BaseParserRuleContext
|
||||
parser antlr.Parser
|
||||
importToken antlr.Token
|
||||
}
|
||||
|
||||
func NewEmptyImportLitContext() *ImportLitContext {
|
||||
var p = new(ImportLitContext)
|
||||
p.BaseParserRuleContext = antlr.NewBaseParserRuleContext(nil, -1)
|
||||
p.RuleIndex = ApiParserParserRULE_importLit
|
||||
return p
|
||||
}
|
||||
|
||||
func (*ImportLitContext) IsImportLitContext() {}
|
||||
|
||||
func NewImportLitContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *ImportLitContext {
|
||||
var p = new(ImportLitContext)
|
||||
|
||||
p.BaseParserRuleContext = antlr.NewBaseParserRuleContext(parent, invokingState)
|
||||
|
||||
p.parser = parser
|
||||
p.RuleIndex = ApiParserParserRULE_importLit
|
||||
|
||||
return p
|
||||
}
|
||||
|
||||
func (s *ImportLitContext) GetParser() antlr.Parser { return s.parser }
|
||||
|
||||
func (s *ImportLitContext) GetImportToken() antlr.Token { return s.importToken }
|
||||
|
||||
func (s *ImportLitContext) SetImportToken(v antlr.Token) { s.importToken = v }
|
||||
|
||||
func (s *ImportLitContext) ImportValue() IImportValueContext {
|
||||
var t = s.GetTypedRuleContext(reflect.TypeOf((*IImportValueContext)(nil)).Elem(), 0)
|
||||
|
||||
if t == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
return t.(IImportValueContext)
|
||||
}
|
||||
|
||||
func (s *ImportLitContext) ID() antlr.TerminalNode {
|
||||
return s.GetToken(ApiParserParserID, 0)
|
||||
}
|
||||
|
||||
func (s *ImportLitContext) GetRuleContext() antlr.RuleContext {
|
||||
return s
|
||||
}
|
||||
|
||||
func (s *ImportLitContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string {
|
||||
return antlr.TreesStringTree(s, ruleNames, recog)
|
||||
}
|
||||
|
||||
func (s *ImportLitContext) Accept(visitor antlr.ParseTreeVisitor) interface{} {
|
||||
switch t := visitor.(type) {
|
||||
case ApiParserVisitor:
|
||||
return t.VisitImportLit(s)
|
||||
|
||||
default:
|
||||
return t.VisitChildren(s)
|
||||
}
|
||||
}
|
||||
|
||||
func (p *ApiParserParser) ImportLit() (localctx IImportLitContext) {
|
||||
localctx = NewImportLitContext(p, p.GetParserRuleContext(), p.GetState())
|
||||
p.EnterRule(localctx, 8, ApiParserParserRULE_importLit)
|
||||
|
||||
defer func() {
|
||||
p.ExitRule()
|
||||
}()
|
||||
|
||||
defer func() {
|
||||
if err := recover(); err != nil {
|
||||
if v, ok := err.(antlr.RecognitionException); ok {
|
||||
localctx.SetException(v)
|
||||
p.GetErrorHandler().ReportError(p, v)
|
||||
p.GetErrorHandler().Recover(p, v)
|
||||
} else {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
p.EnterOuterAlt(localctx, 1)
|
||||
match(p, "import")
|
||||
{
|
||||
p.SetState(98)
|
||||
|
||||
var _m = p.Match(ApiParserParserID)
|
||||
|
||||
localctx.(*ImportLitContext).importToken = _m
|
||||
}
|
||||
{
|
||||
p.SetState(99)
|
||||
p.ImportValue()
|
||||
}
|
||||
|
||||
return localctx
|
||||
}
|
||||
|
||||
// IImportBlockContext is an interface to support dynamic dispatch.
|
||||
type IImportBlockContext interface {
|
||||
antlr.ParserRuleContext
|
||||
|
||||
// GetParser returns the parser.
|
||||
GetParser() antlr.Parser
|
||||
|
||||
// GetImportToken returns the importToken token.
|
||||
GetImportToken() antlr.Token
|
||||
|
||||
// SetImportToken sets the importToken token.
|
||||
SetImportToken(antlr.Token)
|
||||
|
||||
// IsImportBlockContext differentiates from other interfaces.
|
||||
IsImportBlockContext()
|
||||
}
|
||||
|
||||
type ImportBlockContext struct {
|
||||
*antlr.BaseParserRuleContext
|
||||
parser antlr.Parser
|
||||
importToken antlr.Token
|
||||
}
|
||||
|
||||
func NewEmptyImportBlockContext() *ImportBlockContext {
|
||||
var p = new(ImportBlockContext)
|
||||
p.BaseParserRuleContext = antlr.NewBaseParserRuleContext(nil, -1)
|
||||
p.RuleIndex = ApiParserParserRULE_importBlock
|
||||
return p
|
||||
}
|
||||
|
||||
func (*ImportBlockContext) IsImportBlockContext() {}
|
||||
|
||||
func NewImportBlockContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *ImportBlockContext {
|
||||
var p = new(ImportBlockContext)
|
||||
|
||||
p.BaseParserRuleContext = antlr.NewBaseParserRuleContext(parent, invokingState)
|
||||
|
||||
p.parser = parser
|
||||
p.RuleIndex = ApiParserParserRULE_importBlock
|
||||
|
||||
return p
|
||||
}
|
||||
|
||||
func (s *ImportBlockContext) GetParser() antlr.Parser { return s.parser }
|
||||
|
||||
func (s *ImportBlockContext) GetImportToken() antlr.Token { return s.importToken }
|
||||
|
||||
func (s *ImportBlockContext) SetImportToken(v antlr.Token) { s.importToken = v }
|
||||
|
||||
func (s *ImportBlockContext) ID() antlr.TerminalNode {
|
||||
return s.GetToken(ApiParserParserID, 0)
|
||||
}
|
||||
|
||||
func (s *ImportBlockContext) AllImportBlockValue() []IImportBlockValueContext {
|
||||
var ts = s.GetTypedRuleContexts(reflect.TypeOf((*IImportBlockValueContext)(nil)).Elem())
|
||||
var tst = make([]IImportBlockValueContext, len(ts))
|
||||
|
||||
for i, t := range ts {
|
||||
if t != nil {
|
||||
tst[i] = t.(IImportBlockValueContext)
|
||||
}
|
||||
}
|
||||
|
||||
return tst
|
||||
}
|
||||
|
||||
func (s *ImportBlockContext) ImportBlockValue(i int) IImportBlockValueContext {
|
||||
var t = s.GetTypedRuleContext(reflect.TypeOf((*IImportBlockValueContext)(nil)).Elem(), i)
|
||||
|
||||
if t == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
return t.(IImportBlockValueContext)
|
||||
}
|
||||
|
||||
func (s *ImportBlockContext) GetRuleContext() antlr.RuleContext {
|
||||
return s
|
||||
}
|
||||
|
||||
func (s *ImportBlockContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string {
|
||||
return antlr.TreesStringTree(s, ruleNames, recog)
|
||||
}
|
||||
|
||||
func (s *ImportBlockContext) Accept(visitor antlr.ParseTreeVisitor) interface{} {
|
||||
switch t := visitor.(type) {
|
||||
case ApiParserVisitor:
|
||||
return t.VisitImportBlock(s)
|
||||
|
||||
default:
|
||||
return t.VisitChildren(s)
|
||||
}
|
||||
}
|
||||
|
||||
func (p *ApiParserParser) ImportBlock() (localctx IImportBlockContext) {
|
||||
localctx = NewImportBlockContext(p, p.GetParserRuleContext(), p.GetState())
|
||||
p.EnterRule(localctx, 10, ApiParserParserRULE_importBlock)
|
||||
var _la int
|
||||
|
||||
defer func() {
|
||||
p.ExitRule()
|
||||
}()
|
||||
|
||||
defer func() {
|
||||
if err := recover(); err != nil {
|
||||
if v, ok := err.(antlr.RecognitionException); ok {
|
||||
localctx.SetException(v)
|
||||
p.GetErrorHandler().ReportError(p, v)
|
||||
p.GetErrorHandler().Recover(p, v)
|
||||
} else {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
p.EnterOuterAlt(localctx, 1)
|
||||
match(p, "import")
|
||||
{
|
||||
p.SetState(102)
|
||||
|
||||
var _m = p.Match(ApiParserParserID)
|
||||
|
||||
localctx.(*ImportBlockContext).importToken = _m
|
||||
}
|
||||
{
|
||||
p.SetState(103)
|
||||
p.Match(ApiParserParserT__1)
|
||||
}
|
||||
p.SetState(105)
|
||||
p.GetErrorHandler().Sync(p)
|
||||
|
||||
for ok := true; ok; ok = _la == ApiParserParserSTRING {
|
||||
{
|
||||
p.SetState(104)
|
||||
p.ImportBlockValue()
|
||||
}
|
||||
|
||||
p.SetState(107)
|
||||
p.GetErrorHandler().Sync(p)
|
||||
_la = p.GetTokenStream().LA(1)
|
||||
}
|
||||
{
|
||||
p.SetState(109)
|
||||
p.Match(ApiParserParserT__2)
|
||||
}
|
||||
|
||||
return localctx
|
||||
}
|
||||
|
||||
// IImportBlockValueContext is an interface to support dynamic dispatch.
|
||||
type IImportBlockValueContext interface {
|
||||
antlr.ParserRuleContext
|
||||
|
||||
// GetParser returns the parser.
|
||||
GetParser() antlr.Parser
|
||||
|
||||
// IsImportBlockValueContext differentiates from other interfaces.
|
||||
IsImportBlockValueContext()
|
||||
}
|
||||
|
||||
type ImportBlockValueContext struct {
|
||||
*antlr.BaseParserRuleContext
|
||||
parser antlr.Parser
|
||||
}
|
||||
|
||||
func NewEmptyImportBlockValueContext() *ImportBlockValueContext {
|
||||
var p = new(ImportBlockValueContext)
|
||||
p.BaseParserRuleContext = antlr.NewBaseParserRuleContext(nil, -1)
|
||||
p.RuleIndex = ApiParserParserRULE_importBlockValue
|
||||
return p
|
||||
}
|
||||
|
||||
func (*ImportBlockValueContext) IsImportBlockValueContext() {}
|
||||
|
||||
func NewImportBlockValueContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *ImportBlockValueContext {
|
||||
var p = new(ImportBlockValueContext)
|
||||
|
||||
p.BaseParserRuleContext = antlr.NewBaseParserRuleContext(parent, invokingState)
|
||||
|
||||
p.parser = parser
|
||||
p.RuleIndex = ApiParserParserRULE_importBlockValue
|
||||
|
||||
return p
|
||||
}
|
||||
|
||||
func (s *ImportBlockValueContext) GetParser() antlr.Parser { return s.parser }
|
||||
|
||||
func (s *ImportBlockValueContext) ImportValue() IImportValueContext {
|
||||
var t = s.GetTypedRuleContext(reflect.TypeOf((*IImportValueContext)(nil)).Elem(), 0)
|
||||
|
||||
if t == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
return t.(IImportValueContext)
|
||||
}
|
||||
|
||||
func (s *ImportBlockValueContext) GetRuleContext() antlr.RuleContext {
|
||||
return s
|
||||
}
|
||||
|
||||
func (s *ImportBlockValueContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string {
|
||||
return antlr.TreesStringTree(s, ruleNames, recog)
|
||||
}
|
||||
|
||||
func (s *ImportBlockValueContext) Accept(visitor antlr.ParseTreeVisitor) interface{} {
|
||||
switch t := visitor.(type) {
|
||||
case ApiParserVisitor:
|
||||
return t.VisitImportBlockValue(s)
|
||||
|
||||
default:
|
||||
return t.VisitChildren(s)
|
||||
}
|
||||
}
|
||||
|
||||
func (p *ApiParserParser) ImportBlockValue() (localctx IImportBlockValueContext) {
|
||||
localctx = NewImportBlockValueContext(p, p.GetParserRuleContext(), p.GetState())
|
||||
p.EnterRule(localctx, 12, ApiParserParserRULE_importBlockValue)
|
||||
|
||||
defer func() {
|
||||
p.ExitRule()
|
||||
}()
|
||||
|
||||
defer func() {
|
||||
if err := recover(); err != nil {
|
||||
if v, ok := err.(antlr.RecognitionException); ok {
|
||||
localctx.SetException(v)
|
||||
p.GetErrorHandler().ReportError(p, v)
|
||||
p.GetErrorHandler().Recover(p, v)
|
||||
} else {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
p.EnterOuterAlt(localctx, 1)
|
||||
{
|
||||
p.SetState(111)
|
||||
p.ImportValue()
|
||||
}
|
||||
|
||||
return localctx
|
||||
}
|
||||
|
||||
// IImportValueContext is an interface to support dynamic dispatch.
|
||||
type IImportValueContext interface {
|
||||
antlr.ParserRuleContext
|
||||
|
||||
// GetParser returns the parser.
|
||||
GetParser() antlr.Parser
|
||||
|
||||
// IsImportValueContext differentiates from other interfaces.
|
||||
IsImportValueContext()
|
||||
}
|
||||
|
||||
type ImportValueContext struct {
|
||||
*antlr.BaseParserRuleContext
|
||||
parser antlr.Parser
|
||||
}
|
||||
|
||||
func NewEmptyImportValueContext() *ImportValueContext {
|
||||
var p = new(ImportValueContext)
|
||||
p.BaseParserRuleContext = antlr.NewBaseParserRuleContext(nil, -1)
|
||||
p.RuleIndex = ApiParserParserRULE_importValue
|
||||
return p
|
||||
}
|
||||
|
||||
func (*ImportValueContext) IsImportValueContext() {}
|
||||
|
||||
func NewImportValueContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *ImportValueContext {
|
||||
var p = new(ImportValueContext)
|
||||
|
||||
p.BaseParserRuleContext = antlr.NewBaseParserRuleContext(parent, invokingState)
|
||||
|
||||
p.parser = parser
|
||||
p.RuleIndex = ApiParserParserRULE_importValue
|
||||
|
||||
return p
|
||||
}
|
||||
656
tools/goctl/api/parser/g4/gen/api/apiparser_parser2.go
Executable file
656
tools/goctl/api/parser/g4/gen/api/apiparser_parser2.go
Executable file
@@ -0,0 +1,656 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
|
||||
"github.com/zeromicro/antlr"
|
||||
)
|
||||
|
||||
// Part 2
|
||||
// The apiparser_parser.go file was split into multiple files because it
|
||||
// was too large and caused a possible memory overflow during goctl installation.
|
||||
|
||||
func (s *ImportValueContext) GetParser() antlr.Parser { return s.parser }
|
||||
|
||||
func (s *ImportValueContext) STRING() antlr.TerminalNode {
|
||||
return s.GetToken(ApiParserParserSTRING, 0)
|
||||
}
|
||||
|
||||
func (s *ImportValueContext) GetRuleContext() antlr.RuleContext {
|
||||
return s
|
||||
}
|
||||
|
||||
func (s *ImportValueContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string {
|
||||
return antlr.TreesStringTree(s, ruleNames, recog)
|
||||
}
|
||||
|
||||
func (s *ImportValueContext) Accept(visitor antlr.ParseTreeVisitor) interface{} {
|
||||
switch t := visitor.(type) {
|
||||
case ApiParserVisitor:
|
||||
return t.VisitImportValue(s)
|
||||
|
||||
default:
|
||||
return t.VisitChildren(s)
|
||||
}
|
||||
}
|
||||
|
||||
func (p *ApiParserParser) ImportValue() (localctx IImportValueContext) {
|
||||
localctx = NewImportValueContext(p, p.GetParserRuleContext(), p.GetState())
|
||||
p.EnterRule(localctx, 14, ApiParserParserRULE_importValue)
|
||||
|
||||
defer func() {
|
||||
p.ExitRule()
|
||||
}()
|
||||
|
||||
defer func() {
|
||||
if err := recover(); err != nil {
|
||||
if v, ok := err.(antlr.RecognitionException); ok {
|
||||
localctx.SetException(v)
|
||||
p.GetErrorHandler().ReportError(p, v)
|
||||
p.GetErrorHandler().Recover(p, v)
|
||||
} else {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
p.EnterOuterAlt(localctx, 1)
|
||||
checkImportValue(p)
|
||||
{
|
||||
p.SetState(114)
|
||||
p.Match(ApiParserParserSTRING)
|
||||
}
|
||||
|
||||
return localctx
|
||||
}
|
||||
|
||||
// IInfoSpecContext is an interface to support dynamic dispatch.
|
||||
type IInfoSpecContext interface {
|
||||
antlr.ParserRuleContext
|
||||
|
||||
// GetParser returns the parser.
|
||||
GetParser() antlr.Parser
|
||||
|
||||
// GetInfoToken returns the infoToken token.
|
||||
GetInfoToken() antlr.Token
|
||||
|
||||
// GetLp returns the lp token.
|
||||
GetLp() antlr.Token
|
||||
|
||||
// GetRp returns the rp token.
|
||||
GetRp() antlr.Token
|
||||
|
||||
// SetInfoToken sets the infoToken token.
|
||||
SetInfoToken(antlr.Token)
|
||||
|
||||
// SetLp sets the lp token.
|
||||
SetLp(antlr.Token)
|
||||
|
||||
// SetRp sets the rp token.
|
||||
SetRp(antlr.Token)
|
||||
|
||||
// IsInfoSpecContext differentiates from other interfaces.
|
||||
IsInfoSpecContext()
|
||||
}
|
||||
|
||||
type InfoSpecContext struct {
|
||||
*antlr.BaseParserRuleContext
|
||||
parser antlr.Parser
|
||||
infoToken antlr.Token
|
||||
lp antlr.Token
|
||||
rp antlr.Token
|
||||
}
|
||||
|
||||
func NewEmptyInfoSpecContext() *InfoSpecContext {
|
||||
var p = new(InfoSpecContext)
|
||||
p.BaseParserRuleContext = antlr.NewBaseParserRuleContext(nil, -1)
|
||||
p.RuleIndex = ApiParserParserRULE_infoSpec
|
||||
return p
|
||||
}
|
||||
|
||||
func (*InfoSpecContext) IsInfoSpecContext() {}
|
||||
|
||||
func NewInfoSpecContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *InfoSpecContext {
|
||||
var p = new(InfoSpecContext)
|
||||
|
||||
p.BaseParserRuleContext = antlr.NewBaseParserRuleContext(parent, invokingState)
|
||||
|
||||
p.parser = parser
|
||||
p.RuleIndex = ApiParserParserRULE_infoSpec
|
||||
|
||||
return p
|
||||
}
|
||||
|
||||
func (s *InfoSpecContext) GetParser() antlr.Parser { return s.parser }
|
||||
|
||||
func (s *InfoSpecContext) GetInfoToken() antlr.Token { return s.infoToken }
|
||||
|
||||
func (s *InfoSpecContext) GetLp() antlr.Token { return s.lp }
|
||||
|
||||
func (s *InfoSpecContext) GetRp() antlr.Token { return s.rp }
|
||||
|
||||
func (s *InfoSpecContext) SetInfoToken(v antlr.Token) { s.infoToken = v }
|
||||
|
||||
func (s *InfoSpecContext) SetLp(v antlr.Token) { s.lp = v }
|
||||
|
||||
func (s *InfoSpecContext) SetRp(v antlr.Token) { s.rp = v }
|
||||
|
||||
func (s *InfoSpecContext) ID() antlr.TerminalNode {
|
||||
return s.GetToken(ApiParserParserID, 0)
|
||||
}
|
||||
|
||||
func (s *InfoSpecContext) AllKvLit() []IKvLitContext {
|
||||
var ts = s.GetTypedRuleContexts(reflect.TypeOf((*IKvLitContext)(nil)).Elem())
|
||||
var tst = make([]IKvLitContext, len(ts))
|
||||
|
||||
for i, t := range ts {
|
||||
if t != nil {
|
||||
tst[i] = t.(IKvLitContext)
|
||||
}
|
||||
}
|
||||
|
||||
return tst
|
||||
}
|
||||
|
||||
func (s *InfoSpecContext) KvLit(i int) IKvLitContext {
|
||||
var t = s.GetTypedRuleContext(reflect.TypeOf((*IKvLitContext)(nil)).Elem(), i)
|
||||
|
||||
if t == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
return t.(IKvLitContext)
|
||||
}
|
||||
|
||||
func (s *InfoSpecContext) GetRuleContext() antlr.RuleContext {
|
||||
return s
|
||||
}
|
||||
|
||||
func (s *InfoSpecContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string {
|
||||
return antlr.TreesStringTree(s, ruleNames, recog)
|
||||
}
|
||||
|
||||
func (s *InfoSpecContext) Accept(visitor antlr.ParseTreeVisitor) interface{} {
|
||||
switch t := visitor.(type) {
|
||||
case ApiParserVisitor:
|
||||
return t.VisitInfoSpec(s)
|
||||
|
||||
default:
|
||||
return t.VisitChildren(s)
|
||||
}
|
||||
}
|
||||
|
||||
func (p *ApiParserParser) InfoSpec() (localctx IInfoSpecContext) {
|
||||
localctx = NewInfoSpecContext(p, p.GetParserRuleContext(), p.GetState())
|
||||
p.EnterRule(localctx, 16, ApiParserParserRULE_infoSpec)
|
||||
var _la int
|
||||
|
||||
defer func() {
|
||||
p.ExitRule()
|
||||
}()
|
||||
|
||||
defer func() {
|
||||
if err := recover(); err != nil {
|
||||
if v, ok := err.(antlr.RecognitionException); ok {
|
||||
localctx.SetException(v)
|
||||
p.GetErrorHandler().ReportError(p, v)
|
||||
p.GetErrorHandler().Recover(p, v)
|
||||
} else {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
p.EnterOuterAlt(localctx, 1)
|
||||
match(p, "info")
|
||||
{
|
||||
p.SetState(117)
|
||||
|
||||
var _m = p.Match(ApiParserParserID)
|
||||
|
||||
localctx.(*InfoSpecContext).infoToken = _m
|
||||
}
|
||||
{
|
||||
p.SetState(118)
|
||||
|
||||
var _m = p.Match(ApiParserParserT__1)
|
||||
|
||||
localctx.(*InfoSpecContext).lp = _m
|
||||
}
|
||||
p.SetState(120)
|
||||
p.GetErrorHandler().Sync(p)
|
||||
|
||||
for ok := true; ok; ok = _la == ApiParserParserID {
|
||||
{
|
||||
p.SetState(119)
|
||||
p.KvLit()
|
||||
}
|
||||
|
||||
p.SetState(122)
|
||||
p.GetErrorHandler().Sync(p)
|
||||
_la = p.GetTokenStream().LA(1)
|
||||
}
|
||||
{
|
||||
p.SetState(124)
|
||||
|
||||
var _m = p.Match(ApiParserParserT__2)
|
||||
|
||||
localctx.(*InfoSpecContext).rp = _m
|
||||
}
|
||||
|
||||
return localctx
|
||||
}
|
||||
|
||||
// ITypeSpecContext is an interface to support dynamic dispatch.
|
||||
type ITypeSpecContext interface {
|
||||
antlr.ParserRuleContext
|
||||
|
||||
// GetParser returns the parser.
|
||||
GetParser() antlr.Parser
|
||||
|
||||
// IsTypeSpecContext differentiates from other interfaces.
|
||||
IsTypeSpecContext()
|
||||
}
|
||||
|
||||
type TypeSpecContext struct {
|
||||
*antlr.BaseParserRuleContext
|
||||
parser antlr.Parser
|
||||
}
|
||||
|
||||
func NewEmptyTypeSpecContext() *TypeSpecContext {
|
||||
var p = new(TypeSpecContext)
|
||||
p.BaseParserRuleContext = antlr.NewBaseParserRuleContext(nil, -1)
|
||||
p.RuleIndex = ApiParserParserRULE_typeSpec
|
||||
return p
|
||||
}
|
||||
|
||||
func (*TypeSpecContext) IsTypeSpecContext() {}
|
||||
|
||||
func NewTypeSpecContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *TypeSpecContext {
|
||||
var p = new(TypeSpecContext)
|
||||
|
||||
p.BaseParserRuleContext = antlr.NewBaseParserRuleContext(parent, invokingState)
|
||||
|
||||
p.parser = parser
|
||||
p.RuleIndex = ApiParserParserRULE_typeSpec
|
||||
|
||||
return p
|
||||
}
|
||||
|
||||
func (s *TypeSpecContext) GetParser() antlr.Parser { return s.parser }
|
||||
|
||||
func (s *TypeSpecContext) TypeLit() ITypeLitContext {
|
||||
var t = s.GetTypedRuleContext(reflect.TypeOf((*ITypeLitContext)(nil)).Elem(), 0)
|
||||
|
||||
if t == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
return t.(ITypeLitContext)
|
||||
}
|
||||
|
||||
func (s *TypeSpecContext) TypeBlock() ITypeBlockContext {
|
||||
var t = s.GetTypedRuleContext(reflect.TypeOf((*ITypeBlockContext)(nil)).Elem(), 0)
|
||||
|
||||
if t == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
return t.(ITypeBlockContext)
|
||||
}
|
||||
|
||||
func (s *TypeSpecContext) GetRuleContext() antlr.RuleContext {
|
||||
return s
|
||||
}
|
||||
|
||||
func (s *TypeSpecContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string {
|
||||
return antlr.TreesStringTree(s, ruleNames, recog)
|
||||
}
|
||||
|
||||
func (s *TypeSpecContext) Accept(visitor antlr.ParseTreeVisitor) interface{} {
|
||||
switch t := visitor.(type) {
|
||||
case ApiParserVisitor:
|
||||
return t.VisitTypeSpec(s)
|
||||
|
||||
default:
|
||||
return t.VisitChildren(s)
|
||||
}
|
||||
}
|
||||
|
||||
func (p *ApiParserParser) TypeSpec() (localctx ITypeSpecContext) {
|
||||
localctx = NewTypeSpecContext(p, p.GetParserRuleContext(), p.GetState())
|
||||
p.EnterRule(localctx, 18, ApiParserParserRULE_typeSpec)
|
||||
|
||||
defer func() {
|
||||
p.ExitRule()
|
||||
}()
|
||||
|
||||
defer func() {
|
||||
if err := recover(); err != nil {
|
||||
if v, ok := err.(antlr.RecognitionException); ok {
|
||||
localctx.SetException(v)
|
||||
p.GetErrorHandler().ReportError(p, v)
|
||||
p.GetErrorHandler().Recover(p, v)
|
||||
} else {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
p.SetState(128)
|
||||
p.GetErrorHandler().Sync(p)
|
||||
switch p.GetInterpreter().AdaptivePredict(p.GetTokenStream(), 5, p.GetParserRuleContext()) {
|
||||
case 1:
|
||||
p.EnterOuterAlt(localctx, 1)
|
||||
{
|
||||
p.SetState(126)
|
||||
p.TypeLit()
|
||||
}
|
||||
|
||||
case 2:
|
||||
p.EnterOuterAlt(localctx, 2)
|
||||
{
|
||||
p.SetState(127)
|
||||
p.TypeBlock()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return localctx
|
||||
}
|
||||
|
||||
// ITypeLitContext is an interface to support dynamic dispatch.
|
||||
type ITypeLitContext interface {
|
||||
antlr.ParserRuleContext
|
||||
|
||||
// GetParser returns the parser.
|
||||
GetParser() antlr.Parser
|
||||
|
||||
// GetTypeToken returns the typeToken token.
|
||||
GetTypeToken() antlr.Token
|
||||
|
||||
// SetTypeToken sets the typeToken token.
|
||||
SetTypeToken(antlr.Token)
|
||||
|
||||
// IsTypeLitContext differentiates from other interfaces.
|
||||
IsTypeLitContext()
|
||||
}
|
||||
|
||||
type TypeLitContext struct {
|
||||
*antlr.BaseParserRuleContext
|
||||
parser antlr.Parser
|
||||
typeToken antlr.Token
|
||||
}
|
||||
|
||||
func NewEmptyTypeLitContext() *TypeLitContext {
|
||||
var p = new(TypeLitContext)
|
||||
p.BaseParserRuleContext = antlr.NewBaseParserRuleContext(nil, -1)
|
||||
p.RuleIndex = ApiParserParserRULE_typeLit
|
||||
return p
|
||||
}
|
||||
|
||||
func (*TypeLitContext) IsTypeLitContext() {}
|
||||
|
||||
func NewTypeLitContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *TypeLitContext {
|
||||
var p = new(TypeLitContext)
|
||||
|
||||
p.BaseParserRuleContext = antlr.NewBaseParserRuleContext(parent, invokingState)
|
||||
|
||||
p.parser = parser
|
||||
p.RuleIndex = ApiParserParserRULE_typeLit
|
||||
|
||||
return p
|
||||
}
|
||||
|
||||
func (s *TypeLitContext) GetParser() antlr.Parser { return s.parser }
|
||||
|
||||
func (s *TypeLitContext) GetTypeToken() antlr.Token { return s.typeToken }
|
||||
|
||||
func (s *TypeLitContext) SetTypeToken(v antlr.Token) { s.typeToken = v }
|
||||
|
||||
func (s *TypeLitContext) TypeLitBody() ITypeLitBodyContext {
|
||||
var t = s.GetTypedRuleContext(reflect.TypeOf((*ITypeLitBodyContext)(nil)).Elem(), 0)
|
||||
|
||||
if t == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
return t.(ITypeLitBodyContext)
|
||||
}
|
||||
|
||||
func (s *TypeLitContext) ID() antlr.TerminalNode {
|
||||
return s.GetToken(ApiParserParserID, 0)
|
||||
}
|
||||
|
||||
func (s *TypeLitContext) GetRuleContext() antlr.RuleContext {
|
||||
return s
|
||||
}
|
||||
|
||||
func (s *TypeLitContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string {
|
||||
return antlr.TreesStringTree(s, ruleNames, recog)
|
||||
}
|
||||
|
||||
func (s *TypeLitContext) Accept(visitor antlr.ParseTreeVisitor) interface{} {
|
||||
switch t := visitor.(type) {
|
||||
case ApiParserVisitor:
|
||||
return t.VisitTypeLit(s)
|
||||
|
||||
default:
|
||||
return t.VisitChildren(s)
|
||||
}
|
||||
}
|
||||
|
||||
func (p *ApiParserParser) TypeLit() (localctx ITypeLitContext) {
|
||||
localctx = NewTypeLitContext(p, p.GetParserRuleContext(), p.GetState())
|
||||
p.EnterRule(localctx, 20, ApiParserParserRULE_typeLit)
|
||||
|
||||
defer func() {
|
||||
p.ExitRule()
|
||||
}()
|
||||
|
||||
defer func() {
|
||||
if err := recover(); err != nil {
|
||||
if v, ok := err.(antlr.RecognitionException); ok {
|
||||
localctx.SetException(v)
|
||||
p.GetErrorHandler().ReportError(p, v)
|
||||
p.GetErrorHandler().Recover(p, v)
|
||||
} else {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
p.EnterOuterAlt(localctx, 1)
|
||||
match(p, "type")
|
||||
{
|
||||
p.SetState(131)
|
||||
|
||||
var _m = p.Match(ApiParserParserID)
|
||||
|
||||
localctx.(*TypeLitContext).typeToken = _m
|
||||
}
|
||||
{
|
||||
p.SetState(132)
|
||||
p.TypeLitBody()
|
||||
}
|
||||
|
||||
return localctx
|
||||
}
|
||||
|
||||
// ITypeBlockContext is an interface to support dynamic dispatch.
|
||||
type ITypeBlockContext interface {
|
||||
antlr.ParserRuleContext
|
||||
|
||||
// GetParser returns the parser.
|
||||
GetParser() antlr.Parser
|
||||
|
||||
// GetTypeToken returns the typeToken token.
|
||||
GetTypeToken() antlr.Token
|
||||
|
||||
// GetLp returns the lp token.
|
||||
GetLp() antlr.Token
|
||||
|
||||
// GetRp returns the rp token.
|
||||
GetRp() antlr.Token
|
||||
|
||||
// SetTypeToken sets the typeToken token.
|
||||
SetTypeToken(antlr.Token)
|
||||
|
||||
// SetLp sets the lp token.
|
||||
SetLp(antlr.Token)
|
||||
|
||||
// SetRp sets the rp token.
|
||||
SetRp(antlr.Token)
|
||||
|
||||
// IsTypeBlockContext differentiates from other interfaces.
|
||||
IsTypeBlockContext()
|
||||
}
|
||||
|
||||
type TypeBlockContext struct {
|
||||
*antlr.BaseParserRuleContext
|
||||
parser antlr.Parser
|
||||
typeToken antlr.Token
|
||||
lp antlr.Token
|
||||
rp antlr.Token
|
||||
}
|
||||
|
||||
func NewEmptyTypeBlockContext() *TypeBlockContext {
|
||||
var p = new(TypeBlockContext)
|
||||
p.BaseParserRuleContext = antlr.NewBaseParserRuleContext(nil, -1)
|
||||
p.RuleIndex = ApiParserParserRULE_typeBlock
|
||||
return p
|
||||
}
|
||||
|
||||
func (*TypeBlockContext) IsTypeBlockContext() {}
|
||||
|
||||
func NewTypeBlockContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *TypeBlockContext {
|
||||
var p = new(TypeBlockContext)
|
||||
|
||||
p.BaseParserRuleContext = antlr.NewBaseParserRuleContext(parent, invokingState)
|
||||
|
||||
p.parser = parser
|
||||
p.RuleIndex = ApiParserParserRULE_typeBlock
|
||||
|
||||
return p
|
||||
}
|
||||
|
||||
func (s *TypeBlockContext) GetParser() antlr.Parser { return s.parser }
|
||||
|
||||
func (s *TypeBlockContext) GetTypeToken() antlr.Token { return s.typeToken }
|
||||
|
||||
func (s *TypeBlockContext) GetLp() antlr.Token { return s.lp }
|
||||
|
||||
func (s *TypeBlockContext) GetRp() antlr.Token { return s.rp }
|
||||
|
||||
func (s *TypeBlockContext) SetTypeToken(v antlr.Token) { s.typeToken = v }
|
||||
|
||||
func (s *TypeBlockContext) SetLp(v antlr.Token) { s.lp = v }
|
||||
|
||||
func (s *TypeBlockContext) SetRp(v antlr.Token) { s.rp = v }
|
||||
|
||||
func (s *TypeBlockContext) ID() antlr.TerminalNode {
|
||||
return s.GetToken(ApiParserParserID, 0)
|
||||
}
|
||||
|
||||
func (s *TypeBlockContext) AllTypeBlockBody() []ITypeBlockBodyContext {
|
||||
var ts = s.GetTypedRuleContexts(reflect.TypeOf((*ITypeBlockBodyContext)(nil)).Elem())
|
||||
var tst = make([]ITypeBlockBodyContext, len(ts))
|
||||
|
||||
for i, t := range ts {
|
||||
if t != nil {
|
||||
tst[i] = t.(ITypeBlockBodyContext)
|
||||
}
|
||||
}
|
||||
|
||||
return tst
|
||||
}
|
||||
|
||||
func (s *TypeBlockContext) TypeBlockBody(i int) ITypeBlockBodyContext {
|
||||
var t = s.GetTypedRuleContext(reflect.TypeOf((*ITypeBlockBodyContext)(nil)).Elem(), i)
|
||||
|
||||
if t == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
return t.(ITypeBlockBodyContext)
|
||||
}
|
||||
|
||||
func (s *TypeBlockContext) GetRuleContext() antlr.RuleContext {
|
||||
return s
|
||||
}
|
||||
|
||||
func (s *TypeBlockContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string {
|
||||
return antlr.TreesStringTree(s, ruleNames, recog)
|
||||
}
|
||||
|
||||
func (s *TypeBlockContext) Accept(visitor antlr.ParseTreeVisitor) interface{} {
|
||||
switch t := visitor.(type) {
|
||||
case ApiParserVisitor:
|
||||
return t.VisitTypeBlock(s)
|
||||
|
||||
default:
|
||||
return t.VisitChildren(s)
|
||||
}
|
||||
}
|
||||
|
||||
func (p *ApiParserParser) TypeBlock() (localctx ITypeBlockContext) {
|
||||
localctx = NewTypeBlockContext(p, p.GetParserRuleContext(), p.GetState())
|
||||
p.EnterRule(localctx, 22, ApiParserParserRULE_typeBlock)
|
||||
var _la int
|
||||
|
||||
defer func() {
|
||||
p.ExitRule()
|
||||
}()
|
||||
|
||||
defer func() {
|
||||
if err := recover(); err != nil {
|
||||
if v, ok := err.(antlr.RecognitionException); ok {
|
||||
localctx.SetException(v)
|
||||
p.GetErrorHandler().ReportError(p, v)
|
||||
p.GetErrorHandler().Recover(p, v)
|
||||
} else {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
p.EnterOuterAlt(localctx, 1)
|
||||
match(p, "type")
|
||||
{
|
||||
p.SetState(135)
|
||||
|
||||
var _m = p.Match(ApiParserParserID)
|
||||
|
||||
localctx.(*TypeBlockContext).typeToken = _m
|
||||
}
|
||||
{
|
||||
p.SetState(136)
|
||||
|
||||
var _m = p.Match(ApiParserParserT__1)
|
||||
|
||||
localctx.(*TypeBlockContext).lp = _m
|
||||
}
|
||||
p.SetState(140)
|
||||
p.GetErrorHandler().Sync(p)
|
||||
_la = p.GetTokenStream().LA(1)
|
||||
|
||||
for _la == ApiParserParserID {
|
||||
{
|
||||
p.SetState(137)
|
||||
p.TypeBlockBody()
|
||||
}
|
||||
|
||||
p.SetState(142)
|
||||
p.GetErrorHandler().Sync(p)
|
||||
_la = p.GetTokenStream().LA(1)
|
||||
}
|
||||
{
|
||||
p.SetState(143)
|
||||
|
||||
var _m = p.Match(ApiParserParserT__2)
|
||||
|
||||
localctx.(*TypeBlockContext).rp = _m
|
||||
}
|
||||
|
||||
return localctx
|
||||
}
|
||||
637
tools/goctl/api/parser/g4/gen/api/apiparser_parser3.go
Executable file
637
tools/goctl/api/parser/g4/gen/api/apiparser_parser3.go
Executable file
@@ -0,0 +1,637 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
|
||||
"github.com/zeromicro/antlr"
|
||||
)
|
||||
|
||||
// Part 3
|
||||
// The apiparser_parser.go file was split into multiple files because it
|
||||
// was too large and caused a possible memory overflow during goctl installation.
|
||||
|
||||
// ITypeLitBodyContext is an interface to support dynamic dispatch.
|
||||
type ITypeLitBodyContext interface {
|
||||
antlr.ParserRuleContext
|
||||
|
||||
// GetParser returns the parser.
|
||||
GetParser() antlr.Parser
|
||||
|
||||
// IsTypeLitBodyContext differentiates from other interfaces.
|
||||
IsTypeLitBodyContext()
|
||||
}
|
||||
|
||||
type TypeLitBodyContext struct {
|
||||
*antlr.BaseParserRuleContext
|
||||
parser antlr.Parser
|
||||
}
|
||||
|
||||
func NewEmptyTypeLitBodyContext() *TypeLitBodyContext {
|
||||
var p = new(TypeLitBodyContext)
|
||||
p.BaseParserRuleContext = antlr.NewBaseParserRuleContext(nil, -1)
|
||||
p.RuleIndex = ApiParserParserRULE_typeLitBody
|
||||
return p
|
||||
}
|
||||
|
||||
func (*TypeLitBodyContext) IsTypeLitBodyContext() {}
|
||||
|
||||
func NewTypeLitBodyContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *TypeLitBodyContext {
|
||||
var p = new(TypeLitBodyContext)
|
||||
|
||||
p.BaseParserRuleContext = antlr.NewBaseParserRuleContext(parent, invokingState)
|
||||
|
||||
p.parser = parser
|
||||
p.RuleIndex = ApiParserParserRULE_typeLitBody
|
||||
|
||||
return p
|
||||
}
|
||||
|
||||
func (s *TypeLitBodyContext) GetParser() antlr.Parser { return s.parser }
|
||||
|
||||
func (s *TypeLitBodyContext) TypeStruct() ITypeStructContext {
|
||||
var t = s.GetTypedRuleContext(reflect.TypeOf((*ITypeStructContext)(nil)).Elem(), 0)
|
||||
|
||||
if t == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
return t.(ITypeStructContext)
|
||||
}
|
||||
|
||||
func (s *TypeLitBodyContext) TypeAlias() ITypeAliasContext {
|
||||
var t = s.GetTypedRuleContext(reflect.TypeOf((*ITypeAliasContext)(nil)).Elem(), 0)
|
||||
|
||||
if t == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
return t.(ITypeAliasContext)
|
||||
}
|
||||
|
||||
func (s *TypeLitBodyContext) GetRuleContext() antlr.RuleContext {
|
||||
return s
|
||||
}
|
||||
|
||||
func (s *TypeLitBodyContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string {
|
||||
return antlr.TreesStringTree(s, ruleNames, recog)
|
||||
}
|
||||
|
||||
func (s *TypeLitBodyContext) Accept(visitor antlr.ParseTreeVisitor) interface{} {
|
||||
switch t := visitor.(type) {
|
||||
case ApiParserVisitor:
|
||||
return t.VisitTypeLitBody(s)
|
||||
|
||||
default:
|
||||
return t.VisitChildren(s)
|
||||
}
|
||||
}
|
||||
|
||||
func (p *ApiParserParser) TypeLitBody() (localctx ITypeLitBodyContext) {
|
||||
localctx = NewTypeLitBodyContext(p, p.GetParserRuleContext(), p.GetState())
|
||||
p.EnterRule(localctx, 24, ApiParserParserRULE_typeLitBody)
|
||||
|
||||
defer func() {
|
||||
p.ExitRule()
|
||||
}()
|
||||
|
||||
defer func() {
|
||||
if err := recover(); err != nil {
|
||||
if v, ok := err.(antlr.RecognitionException); ok {
|
||||
localctx.SetException(v)
|
||||
p.GetErrorHandler().ReportError(p, v)
|
||||
p.GetErrorHandler().Recover(p, v)
|
||||
} else {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
p.SetState(147)
|
||||
p.GetErrorHandler().Sync(p)
|
||||
switch p.GetInterpreter().AdaptivePredict(p.GetTokenStream(), 7, p.GetParserRuleContext()) {
|
||||
case 1:
|
||||
p.EnterOuterAlt(localctx, 1)
|
||||
{
|
||||
p.SetState(145)
|
||||
p.TypeStruct()
|
||||
}
|
||||
|
||||
case 2:
|
||||
p.EnterOuterAlt(localctx, 2)
|
||||
{
|
||||
p.SetState(146)
|
||||
p.TypeAlias()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return localctx
|
||||
}
|
||||
|
||||
// ITypeBlockBodyContext is an interface to support dynamic dispatch.
|
||||
type ITypeBlockBodyContext interface {
|
||||
antlr.ParserRuleContext
|
||||
|
||||
// GetParser returns the parser.
|
||||
GetParser() antlr.Parser
|
||||
|
||||
// IsTypeBlockBodyContext differentiates from other interfaces.
|
||||
IsTypeBlockBodyContext()
|
||||
}
|
||||
|
||||
type TypeBlockBodyContext struct {
|
||||
*antlr.BaseParserRuleContext
|
||||
parser antlr.Parser
|
||||
}
|
||||
|
||||
func NewEmptyTypeBlockBodyContext() *TypeBlockBodyContext {
|
||||
var p = new(TypeBlockBodyContext)
|
||||
p.BaseParserRuleContext = antlr.NewBaseParserRuleContext(nil, -1)
|
||||
p.RuleIndex = ApiParserParserRULE_typeBlockBody
|
||||
return p
|
||||
}
|
||||
|
||||
func (*TypeBlockBodyContext) IsTypeBlockBodyContext() {}
|
||||
|
||||
func NewTypeBlockBodyContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *TypeBlockBodyContext {
|
||||
var p = new(TypeBlockBodyContext)
|
||||
|
||||
p.BaseParserRuleContext = antlr.NewBaseParserRuleContext(parent, invokingState)
|
||||
|
||||
p.parser = parser
|
||||
p.RuleIndex = ApiParserParserRULE_typeBlockBody
|
||||
|
||||
return p
|
||||
}
|
||||
|
||||
func (s *TypeBlockBodyContext) GetParser() antlr.Parser { return s.parser }
|
||||
|
||||
func (s *TypeBlockBodyContext) TypeBlockStruct() ITypeBlockStructContext {
|
||||
var t = s.GetTypedRuleContext(reflect.TypeOf((*ITypeBlockStructContext)(nil)).Elem(), 0)
|
||||
|
||||
if t == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
return t.(ITypeBlockStructContext)
|
||||
}
|
||||
|
||||
func (s *TypeBlockBodyContext) TypeBlockAlias() ITypeBlockAliasContext {
|
||||
var t = s.GetTypedRuleContext(reflect.TypeOf((*ITypeBlockAliasContext)(nil)).Elem(), 0)
|
||||
|
||||
if t == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
return t.(ITypeBlockAliasContext)
|
||||
}
|
||||
|
||||
func (s *TypeBlockBodyContext) GetRuleContext() antlr.RuleContext {
|
||||
return s
|
||||
}
|
||||
|
||||
func (s *TypeBlockBodyContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string {
|
||||
return antlr.TreesStringTree(s, ruleNames, recog)
|
||||
}
|
||||
|
||||
func (s *TypeBlockBodyContext) Accept(visitor antlr.ParseTreeVisitor) interface{} {
|
||||
switch t := visitor.(type) {
|
||||
case ApiParserVisitor:
|
||||
return t.VisitTypeBlockBody(s)
|
||||
|
||||
default:
|
||||
return t.VisitChildren(s)
|
||||
}
|
||||
}
|
||||
|
||||
func (p *ApiParserParser) TypeBlockBody() (localctx ITypeBlockBodyContext) {
|
||||
localctx = NewTypeBlockBodyContext(p, p.GetParserRuleContext(), p.GetState())
|
||||
p.EnterRule(localctx, 26, ApiParserParserRULE_typeBlockBody)
|
||||
|
||||
defer func() {
|
||||
p.ExitRule()
|
||||
}()
|
||||
|
||||
defer func() {
|
||||
if err := recover(); err != nil {
|
||||
if v, ok := err.(antlr.RecognitionException); ok {
|
||||
localctx.SetException(v)
|
||||
p.GetErrorHandler().ReportError(p, v)
|
||||
p.GetErrorHandler().Recover(p, v)
|
||||
} else {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
p.SetState(151)
|
||||
p.GetErrorHandler().Sync(p)
|
||||
switch p.GetInterpreter().AdaptivePredict(p.GetTokenStream(), 8, p.GetParserRuleContext()) {
|
||||
case 1:
|
||||
p.EnterOuterAlt(localctx, 1)
|
||||
{
|
||||
p.SetState(149)
|
||||
p.TypeBlockStruct()
|
||||
}
|
||||
|
||||
case 2:
|
||||
p.EnterOuterAlt(localctx, 2)
|
||||
{
|
||||
p.SetState(150)
|
||||
p.TypeBlockAlias()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return localctx
|
||||
}
|
||||
|
||||
// ITypeStructContext is an interface to support dynamic dispatch.
|
||||
type ITypeStructContext interface {
|
||||
antlr.ParserRuleContext
|
||||
|
||||
// GetParser returns the parser.
|
||||
GetParser() antlr.Parser
|
||||
|
||||
// GetStructName returns the structName token.
|
||||
GetStructName() antlr.Token
|
||||
|
||||
// GetStructToken returns the structToken token.
|
||||
GetStructToken() antlr.Token
|
||||
|
||||
// GetLbrace returns the lbrace token.
|
||||
GetLbrace() antlr.Token
|
||||
|
||||
// GetRbrace returns the rbrace token.
|
||||
GetRbrace() antlr.Token
|
||||
|
||||
// SetStructName sets the structName token.
|
||||
SetStructName(antlr.Token)
|
||||
|
||||
// SetStructToken sets the structToken token.
|
||||
SetStructToken(antlr.Token)
|
||||
|
||||
// SetLbrace sets the lbrace token.
|
||||
SetLbrace(antlr.Token)
|
||||
|
||||
// SetRbrace sets the rbrace token.
|
||||
SetRbrace(antlr.Token)
|
||||
|
||||
// IsTypeStructContext differentiates from other interfaces.
|
||||
IsTypeStructContext()
|
||||
}
|
||||
|
||||
type TypeStructContext struct {
|
||||
*antlr.BaseParserRuleContext
|
||||
parser antlr.Parser
|
||||
structName antlr.Token
|
||||
structToken antlr.Token
|
||||
lbrace antlr.Token
|
||||
rbrace antlr.Token
|
||||
}
|
||||
|
||||
func NewEmptyTypeStructContext() *TypeStructContext {
|
||||
var p = new(TypeStructContext)
|
||||
p.BaseParserRuleContext = antlr.NewBaseParserRuleContext(nil, -1)
|
||||
p.RuleIndex = ApiParserParserRULE_typeStruct
|
||||
return p
|
||||
}
|
||||
|
||||
func (*TypeStructContext) IsTypeStructContext() {}
|
||||
|
||||
func NewTypeStructContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *TypeStructContext {
|
||||
var p = new(TypeStructContext)
|
||||
|
||||
p.BaseParserRuleContext = antlr.NewBaseParserRuleContext(parent, invokingState)
|
||||
|
||||
p.parser = parser
|
||||
p.RuleIndex = ApiParserParserRULE_typeStruct
|
||||
|
||||
return p
|
||||
}
|
||||
|
||||
func (s *TypeStructContext) GetParser() antlr.Parser { return s.parser }
|
||||
|
||||
func (s *TypeStructContext) GetStructName() antlr.Token { return s.structName }
|
||||
|
||||
func (s *TypeStructContext) GetStructToken() antlr.Token { return s.structToken }
|
||||
|
||||
func (s *TypeStructContext) GetLbrace() antlr.Token { return s.lbrace }
|
||||
|
||||
func (s *TypeStructContext) GetRbrace() antlr.Token { return s.rbrace }
|
||||
|
||||
func (s *TypeStructContext) SetStructName(v antlr.Token) { s.structName = v }
|
||||
|
||||
func (s *TypeStructContext) SetStructToken(v antlr.Token) { s.structToken = v }
|
||||
|
||||
func (s *TypeStructContext) SetLbrace(v antlr.Token) { s.lbrace = v }
|
||||
|
||||
func (s *TypeStructContext) SetRbrace(v antlr.Token) { s.rbrace = v }
|
||||
|
||||
func (s *TypeStructContext) AllID() []antlr.TerminalNode {
|
||||
return s.GetTokens(ApiParserParserID)
|
||||
}
|
||||
|
||||
func (s *TypeStructContext) ID(i int) antlr.TerminalNode {
|
||||
return s.GetToken(ApiParserParserID, i)
|
||||
}
|
||||
|
||||
func (s *TypeStructContext) AllField() []IFieldContext {
|
||||
var ts = s.GetTypedRuleContexts(reflect.TypeOf((*IFieldContext)(nil)).Elem())
|
||||
var tst = make([]IFieldContext, len(ts))
|
||||
|
||||
for i, t := range ts {
|
||||
if t != nil {
|
||||
tst[i] = t.(IFieldContext)
|
||||
}
|
||||
}
|
||||
|
||||
return tst
|
||||
}
|
||||
|
||||
func (s *TypeStructContext) Field(i int) IFieldContext {
|
||||
var t = s.GetTypedRuleContext(reflect.TypeOf((*IFieldContext)(nil)).Elem(), i)
|
||||
|
||||
if t == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
return t.(IFieldContext)
|
||||
}
|
||||
|
||||
func (s *TypeStructContext) GetRuleContext() antlr.RuleContext {
|
||||
return s
|
||||
}
|
||||
|
||||
func (s *TypeStructContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string {
|
||||
return antlr.TreesStringTree(s, ruleNames, recog)
|
||||
}
|
||||
|
||||
func (s *TypeStructContext) Accept(visitor antlr.ParseTreeVisitor) interface{} {
|
||||
switch t := visitor.(type) {
|
||||
case ApiParserVisitor:
|
||||
return t.VisitTypeStruct(s)
|
||||
|
||||
default:
|
||||
return t.VisitChildren(s)
|
||||
}
|
||||
}
|
||||
|
||||
func (p *ApiParserParser) TypeStruct() (localctx ITypeStructContext) {
|
||||
localctx = NewTypeStructContext(p, p.GetParserRuleContext(), p.GetState())
|
||||
p.EnterRule(localctx, 28, ApiParserParserRULE_typeStruct)
|
||||
var _la int
|
||||
|
||||
defer func() {
|
||||
p.ExitRule()
|
||||
}()
|
||||
|
||||
defer func() {
|
||||
if err := recover(); err != nil {
|
||||
if v, ok := err.(antlr.RecognitionException); ok {
|
||||
localctx.SetException(v)
|
||||
p.GetErrorHandler().ReportError(p, v)
|
||||
p.GetErrorHandler().Recover(p, v)
|
||||
} else {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
var _alt int
|
||||
|
||||
p.EnterOuterAlt(localctx, 1)
|
||||
checkKeyword(p)
|
||||
{
|
||||
p.SetState(154)
|
||||
|
||||
var _m = p.Match(ApiParserParserID)
|
||||
|
||||
localctx.(*TypeStructContext).structName = _m
|
||||
}
|
||||
p.SetState(156)
|
||||
p.GetErrorHandler().Sync(p)
|
||||
_la = p.GetTokenStream().LA(1)
|
||||
|
||||
if _la == ApiParserParserID {
|
||||
{
|
||||
p.SetState(155)
|
||||
|
||||
var _m = p.Match(ApiParserParserID)
|
||||
|
||||
localctx.(*TypeStructContext).structToken = _m
|
||||
}
|
||||
|
||||
}
|
||||
{
|
||||
p.SetState(158)
|
||||
|
||||
var _m = p.Match(ApiParserParserT__3)
|
||||
|
||||
localctx.(*TypeStructContext).lbrace = _m
|
||||
}
|
||||
p.SetState(162)
|
||||
p.GetErrorHandler().Sync(p)
|
||||
_alt = p.GetInterpreter().AdaptivePredict(p.GetTokenStream(), 10, p.GetParserRuleContext())
|
||||
|
||||
for _alt != 2 && _alt != antlr.ATNInvalidAltNumber {
|
||||
if _alt == 1 {
|
||||
{
|
||||
p.SetState(159)
|
||||
p.Field()
|
||||
}
|
||||
|
||||
}
|
||||
p.SetState(164)
|
||||
p.GetErrorHandler().Sync(p)
|
||||
_alt = p.GetInterpreter().AdaptivePredict(p.GetTokenStream(), 10, p.GetParserRuleContext())
|
||||
}
|
||||
{
|
||||
p.SetState(165)
|
||||
|
||||
var _m = p.Match(ApiParserParserT__4)
|
||||
|
||||
localctx.(*TypeStructContext).rbrace = _m
|
||||
}
|
||||
|
||||
return localctx
|
||||
}
|
||||
|
||||
// ITypeAliasContext is an interface to support dynamic dispatch.
|
||||
type ITypeAliasContext interface {
|
||||
antlr.ParserRuleContext
|
||||
|
||||
// GetParser returns the parser.
|
||||
GetParser() antlr.Parser
|
||||
|
||||
// GetAlias returns the alias token.
|
||||
GetAlias() antlr.Token
|
||||
|
||||
// GetAssign returns the assign token.
|
||||
GetAssign() antlr.Token
|
||||
|
||||
// SetAlias sets the alias token.
|
||||
SetAlias(antlr.Token)
|
||||
|
||||
// SetAssign sets the assign token.
|
||||
SetAssign(antlr.Token)
|
||||
|
||||
// IsTypeAliasContext differentiates from other interfaces.
|
||||
IsTypeAliasContext()
|
||||
}
|
||||
|
||||
type TypeAliasContext struct {
|
||||
*antlr.BaseParserRuleContext
|
||||
parser antlr.Parser
|
||||
alias antlr.Token
|
||||
assign antlr.Token
|
||||
}
|
||||
|
||||
func NewEmptyTypeAliasContext() *TypeAliasContext {
|
||||
var p = new(TypeAliasContext)
|
||||
p.BaseParserRuleContext = antlr.NewBaseParserRuleContext(nil, -1)
|
||||
p.RuleIndex = ApiParserParserRULE_typeAlias
|
||||
return p
|
||||
}
|
||||
|
||||
func (*TypeAliasContext) IsTypeAliasContext() {}
|
||||
|
||||
func NewTypeAliasContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *TypeAliasContext {
|
||||
var p = new(TypeAliasContext)
|
||||
|
||||
p.BaseParserRuleContext = antlr.NewBaseParserRuleContext(parent, invokingState)
|
||||
|
||||
p.parser = parser
|
||||
p.RuleIndex = ApiParserParserRULE_typeAlias
|
||||
|
||||
return p
|
||||
}
|
||||
|
||||
func (s *TypeAliasContext) GetParser() antlr.Parser { return s.parser }
|
||||
|
||||
func (s *TypeAliasContext) GetAlias() antlr.Token { return s.alias }
|
||||
|
||||
func (s *TypeAliasContext) GetAssign() antlr.Token { return s.assign }
|
||||
|
||||
func (s *TypeAliasContext) SetAlias(v antlr.Token) { s.alias = v }
|
||||
|
||||
func (s *TypeAliasContext) SetAssign(v antlr.Token) { s.assign = v }
|
||||
|
||||
func (s *TypeAliasContext) DataType() IDataTypeContext {
|
||||
var t = s.GetTypedRuleContext(reflect.TypeOf((*IDataTypeContext)(nil)).Elem(), 0)
|
||||
|
||||
if t == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
return t.(IDataTypeContext)
|
||||
}
|
||||
|
||||
func (s *TypeAliasContext) ID() antlr.TerminalNode {
|
||||
return s.GetToken(ApiParserParserID, 0)
|
||||
}
|
||||
|
||||
func (s *TypeAliasContext) GetRuleContext() antlr.RuleContext {
|
||||
return s
|
||||
}
|
||||
|
||||
func (s *TypeAliasContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string {
|
||||
return antlr.TreesStringTree(s, ruleNames, recog)
|
||||
}
|
||||
|
||||
func (s *TypeAliasContext) Accept(visitor antlr.ParseTreeVisitor) interface{} {
|
||||
switch t := visitor.(type) {
|
||||
case ApiParserVisitor:
|
||||
return t.VisitTypeAlias(s)
|
||||
|
||||
default:
|
||||
return t.VisitChildren(s)
|
||||
}
|
||||
}
|
||||
|
||||
func (p *ApiParserParser) TypeAlias() (localctx ITypeAliasContext) {
|
||||
localctx = NewTypeAliasContext(p, p.GetParserRuleContext(), p.GetState())
|
||||
p.EnterRule(localctx, 30, ApiParserParserRULE_typeAlias)
|
||||
var _la int
|
||||
|
||||
defer func() {
|
||||
p.ExitRule()
|
||||
}()
|
||||
|
||||
defer func() {
|
||||
if err := recover(); err != nil {
|
||||
if v, ok := err.(antlr.RecognitionException); ok {
|
||||
localctx.SetException(v)
|
||||
p.GetErrorHandler().ReportError(p, v)
|
||||
p.GetErrorHandler().Recover(p, v)
|
||||
} else {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
p.EnterOuterAlt(localctx, 1)
|
||||
checkKeyword(p)
|
||||
{
|
||||
p.SetState(168)
|
||||
|
||||
var _m = p.Match(ApiParserParserID)
|
||||
|
||||
localctx.(*TypeAliasContext).alias = _m
|
||||
}
|
||||
p.SetState(170)
|
||||
p.GetErrorHandler().Sync(p)
|
||||
_la = p.GetTokenStream().LA(1)
|
||||
|
||||
if _la == ApiParserParserT__0 {
|
||||
{
|
||||
p.SetState(169)
|
||||
|
||||
var _m = p.Match(ApiParserParserT__0)
|
||||
|
||||
localctx.(*TypeAliasContext).assign = _m
|
||||
}
|
||||
|
||||
}
|
||||
{
|
||||
p.SetState(172)
|
||||
p.DataType()
|
||||
}
|
||||
|
||||
return localctx
|
||||
}
|
||||
|
||||
// ITypeBlockStructContext is an interface to support dynamic dispatch.
|
||||
type ITypeBlockStructContext interface {
|
||||
antlr.ParserRuleContext
|
||||
|
||||
// GetParser returns the parser.
|
||||
GetParser() antlr.Parser
|
||||
|
||||
// GetStructName returns the structName token.
|
||||
GetStructName() antlr.Token
|
||||
|
||||
// GetStructToken returns the structToken token.
|
||||
GetStructToken() antlr.Token
|
||||
|
||||
// GetLbrace returns the lbrace token.
|
||||
GetLbrace() antlr.Token
|
||||
|
||||
// GetRbrace returns the rbrace token.
|
||||
GetRbrace() antlr.Token
|
||||
|
||||
// SetStructName sets the structName token.
|
||||
SetStructName(antlr.Token)
|
||||
|
||||
// SetStructToken sets the structToken token.
|
||||
SetStructToken(antlr.Token)
|
||||
|
||||
// SetLbrace sets the lbrace token.
|
||||
SetLbrace(antlr.Token)
|
||||
|
||||
// SetRbrace sets the rbrace token.
|
||||
SetRbrace(antlr.Token)
|
||||
|
||||
// IsTypeBlockStructContext differentiates from other interfaces.
|
||||
IsTypeBlockStructContext()
|
||||
}
|
||||
617
tools/goctl/api/parser/g4/gen/api/apiparser_parser4.go
Executable file
617
tools/goctl/api/parser/g4/gen/api/apiparser_parser4.go
Executable file
@@ -0,0 +1,617 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
|
||||
"github.com/zeromicro/antlr"
|
||||
)
|
||||
|
||||
// Part 4
|
||||
// The apiparser_parser.go file was split into multiple files because it
|
||||
// was too large and caused a possible memory overflow during goctl installation.
|
||||
|
||||
type TypeBlockStructContext struct {
|
||||
*antlr.BaseParserRuleContext
|
||||
parser antlr.Parser
|
||||
structName antlr.Token
|
||||
structToken antlr.Token
|
||||
lbrace antlr.Token
|
||||
rbrace antlr.Token
|
||||
}
|
||||
|
||||
func NewEmptyTypeBlockStructContext() *TypeBlockStructContext {
|
||||
var p = new(TypeBlockStructContext)
|
||||
p.BaseParserRuleContext = antlr.NewBaseParserRuleContext(nil, -1)
|
||||
p.RuleIndex = ApiParserParserRULE_typeBlockStruct
|
||||
return p
|
||||
}
|
||||
|
||||
func (*TypeBlockStructContext) IsTypeBlockStructContext() {}
|
||||
|
||||
func NewTypeBlockStructContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *TypeBlockStructContext {
|
||||
var p = new(TypeBlockStructContext)
|
||||
|
||||
p.BaseParserRuleContext = antlr.NewBaseParserRuleContext(parent, invokingState)
|
||||
|
||||
p.parser = parser
|
||||
p.RuleIndex = ApiParserParserRULE_typeBlockStruct
|
||||
|
||||
return p
|
||||
}
|
||||
|
||||
func (s *TypeBlockStructContext) GetParser() antlr.Parser { return s.parser }
|
||||
|
||||
func (s *TypeBlockStructContext) GetStructName() antlr.Token { return s.structName }
|
||||
|
||||
func (s *TypeBlockStructContext) GetStructToken() antlr.Token { return s.structToken }
|
||||
|
||||
func (s *TypeBlockStructContext) GetLbrace() antlr.Token { return s.lbrace }
|
||||
|
||||
func (s *TypeBlockStructContext) GetRbrace() antlr.Token { return s.rbrace }
|
||||
|
||||
func (s *TypeBlockStructContext) SetStructName(v antlr.Token) { s.structName = v }
|
||||
|
||||
func (s *TypeBlockStructContext) SetStructToken(v antlr.Token) { s.structToken = v }
|
||||
|
||||
func (s *TypeBlockStructContext) SetLbrace(v antlr.Token) { s.lbrace = v }
|
||||
|
||||
func (s *TypeBlockStructContext) SetRbrace(v antlr.Token) { s.rbrace = v }
|
||||
|
||||
func (s *TypeBlockStructContext) AllID() []antlr.TerminalNode {
|
||||
return s.GetTokens(ApiParserParserID)
|
||||
}
|
||||
|
||||
func (s *TypeBlockStructContext) ID(i int) antlr.TerminalNode {
|
||||
return s.GetToken(ApiParserParserID, i)
|
||||
}
|
||||
|
||||
func (s *TypeBlockStructContext) AllField() []IFieldContext {
|
||||
var ts = s.GetTypedRuleContexts(reflect.TypeOf((*IFieldContext)(nil)).Elem())
|
||||
var tst = make([]IFieldContext, len(ts))
|
||||
|
||||
for i, t := range ts {
|
||||
if t != nil {
|
||||
tst[i] = t.(IFieldContext)
|
||||
}
|
||||
}
|
||||
|
||||
return tst
|
||||
}
|
||||
|
||||
func (s *TypeBlockStructContext) Field(i int) IFieldContext {
|
||||
var t = s.GetTypedRuleContext(reflect.TypeOf((*IFieldContext)(nil)).Elem(), i)
|
||||
|
||||
if t == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
return t.(IFieldContext)
|
||||
}
|
||||
|
||||
func (s *TypeBlockStructContext) GetRuleContext() antlr.RuleContext {
|
||||
return s
|
||||
}
|
||||
|
||||
func (s *TypeBlockStructContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string {
|
||||
return antlr.TreesStringTree(s, ruleNames, recog)
|
||||
}
|
||||
|
||||
func (s *TypeBlockStructContext) Accept(visitor antlr.ParseTreeVisitor) interface{} {
|
||||
switch t := visitor.(type) {
|
||||
case ApiParserVisitor:
|
||||
return t.VisitTypeBlockStruct(s)
|
||||
|
||||
default:
|
||||
return t.VisitChildren(s)
|
||||
}
|
||||
}
|
||||
|
||||
func (p *ApiParserParser) TypeBlockStruct() (localctx ITypeBlockStructContext) {
|
||||
localctx = NewTypeBlockStructContext(p, p.GetParserRuleContext(), p.GetState())
|
||||
p.EnterRule(localctx, 32, ApiParserParserRULE_typeBlockStruct)
|
||||
var _la int
|
||||
|
||||
defer func() {
|
||||
p.ExitRule()
|
||||
}()
|
||||
|
||||
defer func() {
|
||||
if err := recover(); err != nil {
|
||||
if v, ok := err.(antlr.RecognitionException); ok {
|
||||
localctx.SetException(v)
|
||||
p.GetErrorHandler().ReportError(p, v)
|
||||
p.GetErrorHandler().Recover(p, v)
|
||||
} else {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
var _alt int
|
||||
|
||||
p.EnterOuterAlt(localctx, 1)
|
||||
checkKeyword(p)
|
||||
{
|
||||
p.SetState(175)
|
||||
|
||||
var _m = p.Match(ApiParserParserID)
|
||||
|
||||
localctx.(*TypeBlockStructContext).structName = _m
|
||||
}
|
||||
p.SetState(177)
|
||||
p.GetErrorHandler().Sync(p)
|
||||
_la = p.GetTokenStream().LA(1)
|
||||
|
||||
if _la == ApiParserParserID {
|
||||
{
|
||||
p.SetState(176)
|
||||
|
||||
var _m = p.Match(ApiParserParserID)
|
||||
|
||||
localctx.(*TypeBlockStructContext).structToken = _m
|
||||
}
|
||||
|
||||
}
|
||||
{
|
||||
p.SetState(179)
|
||||
|
||||
var _m = p.Match(ApiParserParserT__3)
|
||||
|
||||
localctx.(*TypeBlockStructContext).lbrace = _m
|
||||
}
|
||||
p.SetState(183)
|
||||
p.GetErrorHandler().Sync(p)
|
||||
_alt = p.GetInterpreter().AdaptivePredict(p.GetTokenStream(), 13, p.GetParserRuleContext())
|
||||
|
||||
for _alt != 2 && _alt != antlr.ATNInvalidAltNumber {
|
||||
if _alt == 1 {
|
||||
{
|
||||
p.SetState(180)
|
||||
p.Field()
|
||||
}
|
||||
|
||||
}
|
||||
p.SetState(185)
|
||||
p.GetErrorHandler().Sync(p)
|
||||
_alt = p.GetInterpreter().AdaptivePredict(p.GetTokenStream(), 13, p.GetParserRuleContext())
|
||||
}
|
||||
{
|
||||
p.SetState(186)
|
||||
|
||||
var _m = p.Match(ApiParserParserT__4)
|
||||
|
||||
localctx.(*TypeBlockStructContext).rbrace = _m
|
||||
}
|
||||
|
||||
return localctx
|
||||
}
|
||||
|
||||
// ITypeBlockAliasContext is an interface to support dynamic dispatch.
|
||||
type ITypeBlockAliasContext interface {
|
||||
antlr.ParserRuleContext
|
||||
|
||||
// GetParser returns the parser.
|
||||
GetParser() antlr.Parser
|
||||
|
||||
// GetAlias returns the alias token.
|
||||
GetAlias() antlr.Token
|
||||
|
||||
// GetAssign returns the assign token.
|
||||
GetAssign() antlr.Token
|
||||
|
||||
// SetAlias sets the alias token.
|
||||
SetAlias(antlr.Token)
|
||||
|
||||
// SetAssign sets the assign token.
|
||||
SetAssign(antlr.Token)
|
||||
|
||||
// IsTypeBlockAliasContext differentiates from other interfaces.
|
||||
IsTypeBlockAliasContext()
|
||||
}
|
||||
|
||||
type TypeBlockAliasContext struct {
|
||||
*antlr.BaseParserRuleContext
|
||||
parser antlr.Parser
|
||||
alias antlr.Token
|
||||
assign antlr.Token
|
||||
}
|
||||
|
||||
func NewEmptyTypeBlockAliasContext() *TypeBlockAliasContext {
|
||||
var p = new(TypeBlockAliasContext)
|
||||
p.BaseParserRuleContext = antlr.NewBaseParserRuleContext(nil, -1)
|
||||
p.RuleIndex = ApiParserParserRULE_typeBlockAlias
|
||||
return p
|
||||
}
|
||||
|
||||
func (*TypeBlockAliasContext) IsTypeBlockAliasContext() {}
|
||||
|
||||
func NewTypeBlockAliasContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *TypeBlockAliasContext {
|
||||
var p = new(TypeBlockAliasContext)
|
||||
|
||||
p.BaseParserRuleContext = antlr.NewBaseParserRuleContext(parent, invokingState)
|
||||
|
||||
p.parser = parser
|
||||
p.RuleIndex = ApiParserParserRULE_typeBlockAlias
|
||||
|
||||
return p
|
||||
}
|
||||
|
||||
func (s *TypeBlockAliasContext) GetParser() antlr.Parser { return s.parser }
|
||||
|
||||
func (s *TypeBlockAliasContext) GetAlias() antlr.Token { return s.alias }
|
||||
|
||||
func (s *TypeBlockAliasContext) GetAssign() antlr.Token { return s.assign }
|
||||
|
||||
func (s *TypeBlockAliasContext) SetAlias(v antlr.Token) { s.alias = v }
|
||||
|
||||
func (s *TypeBlockAliasContext) SetAssign(v antlr.Token) { s.assign = v }
|
||||
|
||||
func (s *TypeBlockAliasContext) DataType() IDataTypeContext {
|
||||
var t = s.GetTypedRuleContext(reflect.TypeOf((*IDataTypeContext)(nil)).Elem(), 0)
|
||||
|
||||
if t == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
return t.(IDataTypeContext)
|
||||
}
|
||||
|
||||
func (s *TypeBlockAliasContext) ID() antlr.TerminalNode {
|
||||
return s.GetToken(ApiParserParserID, 0)
|
||||
}
|
||||
|
||||
func (s *TypeBlockAliasContext) GetRuleContext() antlr.RuleContext {
|
||||
return s
|
||||
}
|
||||
|
||||
func (s *TypeBlockAliasContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string {
|
||||
return antlr.TreesStringTree(s, ruleNames, recog)
|
||||
}
|
||||
|
||||
func (s *TypeBlockAliasContext) Accept(visitor antlr.ParseTreeVisitor) interface{} {
|
||||
switch t := visitor.(type) {
|
||||
case ApiParserVisitor:
|
||||
return t.VisitTypeBlockAlias(s)
|
||||
|
||||
default:
|
||||
return t.VisitChildren(s)
|
||||
}
|
||||
}
|
||||
|
||||
func (p *ApiParserParser) TypeBlockAlias() (localctx ITypeBlockAliasContext) {
|
||||
localctx = NewTypeBlockAliasContext(p, p.GetParserRuleContext(), p.GetState())
|
||||
p.EnterRule(localctx, 34, ApiParserParserRULE_typeBlockAlias)
|
||||
var _la int
|
||||
|
||||
defer func() {
|
||||
p.ExitRule()
|
||||
}()
|
||||
|
||||
defer func() {
|
||||
if err := recover(); err != nil {
|
||||
if v, ok := err.(antlr.RecognitionException); ok {
|
||||
localctx.SetException(v)
|
||||
p.GetErrorHandler().ReportError(p, v)
|
||||
p.GetErrorHandler().Recover(p, v)
|
||||
} else {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
p.EnterOuterAlt(localctx, 1)
|
||||
checkKeyword(p)
|
||||
{
|
||||
p.SetState(189)
|
||||
|
||||
var _m = p.Match(ApiParserParserID)
|
||||
|
||||
localctx.(*TypeBlockAliasContext).alias = _m
|
||||
}
|
||||
p.SetState(191)
|
||||
p.GetErrorHandler().Sync(p)
|
||||
_la = p.GetTokenStream().LA(1)
|
||||
|
||||
if _la == ApiParserParserT__0 {
|
||||
{
|
||||
p.SetState(190)
|
||||
|
||||
var _m = p.Match(ApiParserParserT__0)
|
||||
|
||||
localctx.(*TypeBlockAliasContext).assign = _m
|
||||
}
|
||||
|
||||
}
|
||||
{
|
||||
p.SetState(193)
|
||||
p.DataType()
|
||||
}
|
||||
|
||||
return localctx
|
||||
}
|
||||
|
||||
// IFieldContext is an interface to support dynamic dispatch.
|
||||
type IFieldContext interface {
|
||||
antlr.ParserRuleContext
|
||||
|
||||
// GetParser returns the parser.
|
||||
GetParser() antlr.Parser
|
||||
|
||||
// IsFieldContext differentiates from other interfaces.
|
||||
IsFieldContext()
|
||||
}
|
||||
|
||||
type FieldContext struct {
|
||||
*antlr.BaseParserRuleContext
|
||||
parser antlr.Parser
|
||||
}
|
||||
|
||||
func NewEmptyFieldContext() *FieldContext {
|
||||
var p = new(FieldContext)
|
||||
p.BaseParserRuleContext = antlr.NewBaseParserRuleContext(nil, -1)
|
||||
p.RuleIndex = ApiParserParserRULE_field
|
||||
return p
|
||||
}
|
||||
|
||||
func (*FieldContext) IsFieldContext() {}
|
||||
|
||||
func NewFieldContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *FieldContext {
|
||||
var p = new(FieldContext)
|
||||
|
||||
p.BaseParserRuleContext = antlr.NewBaseParserRuleContext(parent, invokingState)
|
||||
|
||||
p.parser = parser
|
||||
p.RuleIndex = ApiParserParserRULE_field
|
||||
|
||||
return p
|
||||
}
|
||||
|
||||
func (s *FieldContext) GetParser() antlr.Parser { return s.parser }
|
||||
|
||||
func (s *FieldContext) NormalField() INormalFieldContext {
|
||||
var t = s.GetTypedRuleContext(reflect.TypeOf((*INormalFieldContext)(nil)).Elem(), 0)
|
||||
|
||||
if t == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
return t.(INormalFieldContext)
|
||||
}
|
||||
|
||||
func (s *FieldContext) AnonymousFiled() IAnonymousFiledContext {
|
||||
var t = s.GetTypedRuleContext(reflect.TypeOf((*IAnonymousFiledContext)(nil)).Elem(), 0)
|
||||
|
||||
if t == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
return t.(IAnonymousFiledContext)
|
||||
}
|
||||
|
||||
func (s *FieldContext) GetRuleContext() antlr.RuleContext {
|
||||
return s
|
||||
}
|
||||
|
||||
func (s *FieldContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string {
|
||||
return antlr.TreesStringTree(s, ruleNames, recog)
|
||||
}
|
||||
|
||||
func (s *FieldContext) Accept(visitor antlr.ParseTreeVisitor) interface{} {
|
||||
switch t := visitor.(type) {
|
||||
case ApiParserVisitor:
|
||||
return t.VisitField(s)
|
||||
|
||||
default:
|
||||
return t.VisitChildren(s)
|
||||
}
|
||||
}
|
||||
|
||||
func (p *ApiParserParser) Field() (localctx IFieldContext) {
|
||||
localctx = NewFieldContext(p, p.GetParserRuleContext(), p.GetState())
|
||||
p.EnterRule(localctx, 36, ApiParserParserRULE_field)
|
||||
|
||||
defer func() {
|
||||
p.ExitRule()
|
||||
}()
|
||||
|
||||
defer func() {
|
||||
if err := recover(); err != nil {
|
||||
if v, ok := err.(antlr.RecognitionException); ok {
|
||||
localctx.SetException(v)
|
||||
p.GetErrorHandler().ReportError(p, v)
|
||||
p.GetErrorHandler().Recover(p, v)
|
||||
} else {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
p.SetState(198)
|
||||
p.GetErrorHandler().Sync(p)
|
||||
switch p.GetInterpreter().AdaptivePredict(p.GetTokenStream(), 15, p.GetParserRuleContext()) {
|
||||
case 1:
|
||||
p.EnterOuterAlt(localctx, 1)
|
||||
p.SetState(195)
|
||||
|
||||
if !(isNormal(p)) {
|
||||
panic(antlr.NewFailedPredicateException(p, "isNormal(p)", ""))
|
||||
}
|
||||
{
|
||||
p.SetState(196)
|
||||
p.NormalField()
|
||||
}
|
||||
|
||||
case 2:
|
||||
p.EnterOuterAlt(localctx, 2)
|
||||
{
|
||||
p.SetState(197)
|
||||
p.AnonymousFiled()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return localctx
|
||||
}
|
||||
|
||||
// INormalFieldContext is an interface to support dynamic dispatch.
|
||||
type INormalFieldContext interface {
|
||||
antlr.ParserRuleContext
|
||||
|
||||
// GetParser returns the parser.
|
||||
GetParser() antlr.Parser
|
||||
|
||||
// GetFieldName returns the fieldName token.
|
||||
GetFieldName() antlr.Token
|
||||
|
||||
// GetTag returns the tag token.
|
||||
GetTag() antlr.Token
|
||||
|
||||
// SetFieldName sets the fieldName token.
|
||||
SetFieldName(antlr.Token)
|
||||
|
||||
// SetTag sets the tag token.
|
||||
SetTag(antlr.Token)
|
||||
|
||||
// IsNormalFieldContext differentiates from other interfaces.
|
||||
IsNormalFieldContext()
|
||||
}
|
||||
|
||||
type NormalFieldContext struct {
|
||||
*antlr.BaseParserRuleContext
|
||||
parser antlr.Parser
|
||||
fieldName antlr.Token
|
||||
tag antlr.Token
|
||||
}
|
||||
|
||||
func NewEmptyNormalFieldContext() *NormalFieldContext {
|
||||
var p = new(NormalFieldContext)
|
||||
p.BaseParserRuleContext = antlr.NewBaseParserRuleContext(nil, -1)
|
||||
p.RuleIndex = ApiParserParserRULE_normalField
|
||||
return p
|
||||
}
|
||||
|
||||
func (*NormalFieldContext) IsNormalFieldContext() {}
|
||||
|
||||
func NewNormalFieldContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *NormalFieldContext {
|
||||
var p = new(NormalFieldContext)
|
||||
|
||||
p.BaseParserRuleContext = antlr.NewBaseParserRuleContext(parent, invokingState)
|
||||
|
||||
p.parser = parser
|
||||
p.RuleIndex = ApiParserParserRULE_normalField
|
||||
|
||||
return p
|
||||
}
|
||||
|
||||
func (s *NormalFieldContext) GetParser() antlr.Parser { return s.parser }
|
||||
|
||||
func (s *NormalFieldContext) GetFieldName() antlr.Token { return s.fieldName }
|
||||
|
||||
func (s *NormalFieldContext) GetTag() antlr.Token { return s.tag }
|
||||
|
||||
func (s *NormalFieldContext) SetFieldName(v antlr.Token) { s.fieldName = v }
|
||||
|
||||
func (s *NormalFieldContext) SetTag(v antlr.Token) { s.tag = v }
|
||||
|
||||
func (s *NormalFieldContext) DataType() IDataTypeContext {
|
||||
var t = s.GetTypedRuleContext(reflect.TypeOf((*IDataTypeContext)(nil)).Elem(), 0)
|
||||
|
||||
if t == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
return t.(IDataTypeContext)
|
||||
}
|
||||
|
||||
func (s *NormalFieldContext) ID() antlr.TerminalNode {
|
||||
return s.GetToken(ApiParserParserID, 0)
|
||||
}
|
||||
|
||||
func (s *NormalFieldContext) RAW_STRING() antlr.TerminalNode {
|
||||
return s.GetToken(ApiParserParserRAW_STRING, 0)
|
||||
}
|
||||
|
||||
func (s *NormalFieldContext) GetRuleContext() antlr.RuleContext {
|
||||
return s
|
||||
}
|
||||
|
||||
func (s *NormalFieldContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string {
|
||||
return antlr.TreesStringTree(s, ruleNames, recog)
|
||||
}
|
||||
|
||||
func (s *NormalFieldContext) Accept(visitor antlr.ParseTreeVisitor) interface{} {
|
||||
switch t := visitor.(type) {
|
||||
case ApiParserVisitor:
|
||||
return t.VisitNormalField(s)
|
||||
|
||||
default:
|
||||
return t.VisitChildren(s)
|
||||
}
|
||||
}
|
||||
|
||||
func (p *ApiParserParser) NormalField() (localctx INormalFieldContext) {
|
||||
localctx = NewNormalFieldContext(p, p.GetParserRuleContext(), p.GetState())
|
||||
p.EnterRule(localctx, 38, ApiParserParserRULE_normalField)
|
||||
|
||||
defer func() {
|
||||
p.ExitRule()
|
||||
}()
|
||||
|
||||
defer func() {
|
||||
if err := recover(); err != nil {
|
||||
if v, ok := err.(antlr.RecognitionException); ok {
|
||||
localctx.SetException(v)
|
||||
p.GetErrorHandler().ReportError(p, v)
|
||||
p.GetErrorHandler().Recover(p, v)
|
||||
} else {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
p.EnterOuterAlt(localctx, 1)
|
||||
checkKeyword(p)
|
||||
{
|
||||
p.SetState(201)
|
||||
|
||||
var _m = p.Match(ApiParserParserID)
|
||||
|
||||
localctx.(*NormalFieldContext).fieldName = _m
|
||||
}
|
||||
{
|
||||
p.SetState(202)
|
||||
p.DataType()
|
||||
}
|
||||
p.SetState(204)
|
||||
p.GetErrorHandler().Sync(p)
|
||||
|
||||
if p.GetInterpreter().AdaptivePredict(p.GetTokenStream(), 16, p.GetParserRuleContext()) == 1 {
|
||||
{
|
||||
p.SetState(203)
|
||||
|
||||
var _m = p.Match(ApiParserParserRAW_STRING)
|
||||
|
||||
localctx.(*NormalFieldContext).tag = _m
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return localctx
|
||||
}
|
||||
|
||||
// IAnonymousFiledContext is an interface to support dynamic dispatch.
|
||||
type IAnonymousFiledContext interface {
|
||||
antlr.ParserRuleContext
|
||||
|
||||
// GetParser returns the parser.
|
||||
GetParser() antlr.Parser
|
||||
|
||||
// GetStar returns the star token.
|
||||
GetStar() antlr.Token
|
||||
|
||||
// SetStar sets the star token.
|
||||
SetStar(antlr.Token)
|
||||
|
||||
// IsAnonymousFiledContext differentiates from other interfaces.
|
||||
IsAnonymousFiledContext()
|
||||
}
|
||||
618
tools/goctl/api/parser/g4/gen/api/apiparser_parser5.go
Executable file
618
tools/goctl/api/parser/g4/gen/api/apiparser_parser5.go
Executable file
@@ -0,0 +1,618 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
|
||||
"github.com/zeromicro/antlr"
|
||||
)
|
||||
|
||||
// Part 5
|
||||
// The apiparser_parser.go file was split into multiple files because it
|
||||
// was too large and caused a possible memory overflow during goctl installation.
|
||||
|
||||
type AnonymousFiledContext struct {
|
||||
*antlr.BaseParserRuleContext
|
||||
parser antlr.Parser
|
||||
star antlr.Token
|
||||
}
|
||||
|
||||
func NewEmptyAnonymousFiledContext() *AnonymousFiledContext {
|
||||
var p = new(AnonymousFiledContext)
|
||||
p.BaseParserRuleContext = antlr.NewBaseParserRuleContext(nil, -1)
|
||||
p.RuleIndex = ApiParserParserRULE_anonymousFiled
|
||||
return p
|
||||
}
|
||||
|
||||
func (*AnonymousFiledContext) IsAnonymousFiledContext() {}
|
||||
|
||||
func NewAnonymousFiledContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *AnonymousFiledContext {
|
||||
var p = new(AnonymousFiledContext)
|
||||
|
||||
p.BaseParserRuleContext = antlr.NewBaseParserRuleContext(parent, invokingState)
|
||||
|
||||
p.parser = parser
|
||||
p.RuleIndex = ApiParserParserRULE_anonymousFiled
|
||||
|
||||
return p
|
||||
}
|
||||
|
||||
func (s *AnonymousFiledContext) GetParser() antlr.Parser { return s.parser }
|
||||
|
||||
func (s *AnonymousFiledContext) GetStar() antlr.Token { return s.star }
|
||||
|
||||
func (s *AnonymousFiledContext) SetStar(v antlr.Token) { s.star = v }
|
||||
|
||||
func (s *AnonymousFiledContext) ID() antlr.TerminalNode {
|
||||
return s.GetToken(ApiParserParserID, 0)
|
||||
}
|
||||
|
||||
func (s *AnonymousFiledContext) GetRuleContext() antlr.RuleContext {
|
||||
return s
|
||||
}
|
||||
|
||||
func (s *AnonymousFiledContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string {
|
||||
return antlr.TreesStringTree(s, ruleNames, recog)
|
||||
}
|
||||
|
||||
func (s *AnonymousFiledContext) Accept(visitor antlr.ParseTreeVisitor) interface{} {
|
||||
switch t := visitor.(type) {
|
||||
case ApiParserVisitor:
|
||||
return t.VisitAnonymousFiled(s)
|
||||
|
||||
default:
|
||||
return t.VisitChildren(s)
|
||||
}
|
||||
}
|
||||
|
||||
func (p *ApiParserParser) AnonymousFiled() (localctx IAnonymousFiledContext) {
|
||||
localctx = NewAnonymousFiledContext(p, p.GetParserRuleContext(), p.GetState())
|
||||
p.EnterRule(localctx, 40, ApiParserParserRULE_anonymousFiled)
|
||||
var _la int
|
||||
|
||||
defer func() {
|
||||
p.ExitRule()
|
||||
}()
|
||||
|
||||
defer func() {
|
||||
if err := recover(); err != nil {
|
||||
if v, ok := err.(antlr.RecognitionException); ok {
|
||||
localctx.SetException(v)
|
||||
p.GetErrorHandler().ReportError(p, v)
|
||||
p.GetErrorHandler().Recover(p, v)
|
||||
} else {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
p.EnterOuterAlt(localctx, 1)
|
||||
p.SetState(207)
|
||||
p.GetErrorHandler().Sync(p)
|
||||
_la = p.GetTokenStream().LA(1)
|
||||
|
||||
if _la == ApiParserParserT__5 {
|
||||
{
|
||||
p.SetState(206)
|
||||
|
||||
var _m = p.Match(ApiParserParserT__5)
|
||||
|
||||
localctx.(*AnonymousFiledContext).star = _m
|
||||
}
|
||||
|
||||
}
|
||||
{
|
||||
p.SetState(209)
|
||||
p.Match(ApiParserParserID)
|
||||
}
|
||||
|
||||
return localctx
|
||||
}
|
||||
|
||||
// IDataTypeContext is an interface to support dynamic dispatch.
|
||||
type IDataTypeContext interface {
|
||||
antlr.ParserRuleContext
|
||||
|
||||
// GetParser returns the parser.
|
||||
GetParser() antlr.Parser
|
||||
|
||||
// GetInter returns the inter token.
|
||||
GetInter() antlr.Token
|
||||
|
||||
// GetTime returns the time token.
|
||||
GetTime() antlr.Token
|
||||
|
||||
// SetInter sets the inter token.
|
||||
SetInter(antlr.Token)
|
||||
|
||||
// SetTime sets the time token.
|
||||
SetTime(antlr.Token)
|
||||
|
||||
// IsDataTypeContext differentiates from other interfaces.
|
||||
IsDataTypeContext()
|
||||
}
|
||||
|
||||
type DataTypeContext struct {
|
||||
*antlr.BaseParserRuleContext
|
||||
parser antlr.Parser
|
||||
inter antlr.Token
|
||||
time antlr.Token
|
||||
}
|
||||
|
||||
func NewEmptyDataTypeContext() *DataTypeContext {
|
||||
var p = new(DataTypeContext)
|
||||
p.BaseParserRuleContext = antlr.NewBaseParserRuleContext(nil, -1)
|
||||
p.RuleIndex = ApiParserParserRULE_dataType
|
||||
return p
|
||||
}
|
||||
|
||||
func (*DataTypeContext) IsDataTypeContext() {}
|
||||
|
||||
func NewDataTypeContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *DataTypeContext {
|
||||
var p = new(DataTypeContext)
|
||||
|
||||
p.BaseParserRuleContext = antlr.NewBaseParserRuleContext(parent, invokingState)
|
||||
|
||||
p.parser = parser
|
||||
p.RuleIndex = ApiParserParserRULE_dataType
|
||||
|
||||
return p
|
||||
}
|
||||
|
||||
func (s *DataTypeContext) GetParser() antlr.Parser { return s.parser }
|
||||
|
||||
func (s *DataTypeContext) GetInter() antlr.Token { return s.inter }
|
||||
|
||||
func (s *DataTypeContext) GetTime() antlr.Token { return s.time }
|
||||
|
||||
func (s *DataTypeContext) SetInter(v antlr.Token) { s.inter = v }
|
||||
|
||||
func (s *DataTypeContext) SetTime(v antlr.Token) { s.time = v }
|
||||
|
||||
func (s *DataTypeContext) ID() antlr.TerminalNode {
|
||||
return s.GetToken(ApiParserParserID, 0)
|
||||
}
|
||||
|
||||
func (s *DataTypeContext) MapType() IMapTypeContext {
|
||||
var t = s.GetTypedRuleContext(reflect.TypeOf((*IMapTypeContext)(nil)).Elem(), 0)
|
||||
|
||||
if t == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
return t.(IMapTypeContext)
|
||||
}
|
||||
|
||||
func (s *DataTypeContext) ArrayType() IArrayTypeContext {
|
||||
var t = s.GetTypedRuleContext(reflect.TypeOf((*IArrayTypeContext)(nil)).Elem(), 0)
|
||||
|
||||
if t == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
return t.(IArrayTypeContext)
|
||||
}
|
||||
|
||||
func (s *DataTypeContext) INTERFACE() antlr.TerminalNode {
|
||||
return s.GetToken(ApiParserParserINTERFACE, 0)
|
||||
}
|
||||
|
||||
func (s *DataTypeContext) PointerType() IPointerTypeContext {
|
||||
var t = s.GetTypedRuleContext(reflect.TypeOf((*IPointerTypeContext)(nil)).Elem(), 0)
|
||||
|
||||
if t == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
return t.(IPointerTypeContext)
|
||||
}
|
||||
|
||||
func (s *DataTypeContext) TypeStruct() ITypeStructContext {
|
||||
var t = s.GetTypedRuleContext(reflect.TypeOf((*ITypeStructContext)(nil)).Elem(), 0)
|
||||
|
||||
if t == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
return t.(ITypeStructContext)
|
||||
}
|
||||
|
||||
func (s *DataTypeContext) GetRuleContext() antlr.RuleContext {
|
||||
return s
|
||||
}
|
||||
|
||||
func (s *DataTypeContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string {
|
||||
return antlr.TreesStringTree(s, ruleNames, recog)
|
||||
}
|
||||
|
||||
func (s *DataTypeContext) Accept(visitor antlr.ParseTreeVisitor) interface{} {
|
||||
switch t := visitor.(type) {
|
||||
case ApiParserVisitor:
|
||||
return t.VisitDataType(s)
|
||||
|
||||
default:
|
||||
return t.VisitChildren(s)
|
||||
}
|
||||
}
|
||||
|
||||
func (p *ApiParserParser) DataType() (localctx IDataTypeContext) {
|
||||
localctx = NewDataTypeContext(p, p.GetParserRuleContext(), p.GetState())
|
||||
p.EnterRule(localctx, 42, ApiParserParserRULE_dataType)
|
||||
|
||||
defer func() {
|
||||
p.ExitRule()
|
||||
}()
|
||||
|
||||
defer func() {
|
||||
if err := recover(); err != nil {
|
||||
if v, ok := err.(antlr.RecognitionException); ok {
|
||||
localctx.SetException(v)
|
||||
p.GetErrorHandler().ReportError(p, v)
|
||||
p.GetErrorHandler().Recover(p, v)
|
||||
} else {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
p.SetState(219)
|
||||
p.GetErrorHandler().Sync(p)
|
||||
switch p.GetInterpreter().AdaptivePredict(p.GetTokenStream(), 18, p.GetParserRuleContext()) {
|
||||
case 1:
|
||||
p.EnterOuterAlt(localctx, 1)
|
||||
isInterface(p)
|
||||
{
|
||||
p.SetState(212)
|
||||
p.Match(ApiParserParserID)
|
||||
}
|
||||
|
||||
case 2:
|
||||
p.EnterOuterAlt(localctx, 2)
|
||||
{
|
||||
p.SetState(213)
|
||||
p.MapType()
|
||||
}
|
||||
|
||||
case 3:
|
||||
p.EnterOuterAlt(localctx, 3)
|
||||
{
|
||||
p.SetState(214)
|
||||
p.ArrayType()
|
||||
}
|
||||
|
||||
case 4:
|
||||
p.EnterOuterAlt(localctx, 4)
|
||||
{
|
||||
p.SetState(215)
|
||||
|
||||
var _m = p.Match(ApiParserParserINTERFACE)
|
||||
|
||||
localctx.(*DataTypeContext).inter = _m
|
||||
}
|
||||
|
||||
case 5:
|
||||
p.EnterOuterAlt(localctx, 5)
|
||||
{
|
||||
p.SetState(216)
|
||||
|
||||
var _m = p.Match(ApiParserParserT__6)
|
||||
|
||||
localctx.(*DataTypeContext).time = _m
|
||||
}
|
||||
|
||||
case 6:
|
||||
p.EnterOuterAlt(localctx, 6)
|
||||
{
|
||||
p.SetState(217)
|
||||
p.PointerType()
|
||||
}
|
||||
|
||||
case 7:
|
||||
p.EnterOuterAlt(localctx, 7)
|
||||
{
|
||||
p.SetState(218)
|
||||
p.TypeStruct()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return localctx
|
||||
}
|
||||
|
||||
// IPointerTypeContext is an interface to support dynamic dispatch.
|
||||
type IPointerTypeContext interface {
|
||||
antlr.ParserRuleContext
|
||||
|
||||
// GetParser returns the parser.
|
||||
GetParser() antlr.Parser
|
||||
|
||||
// GetStar returns the star token.
|
||||
GetStar() antlr.Token
|
||||
|
||||
// SetStar sets the star token.
|
||||
SetStar(antlr.Token)
|
||||
|
||||
// IsPointerTypeContext differentiates from other interfaces.
|
||||
IsPointerTypeContext()
|
||||
}
|
||||
|
||||
type PointerTypeContext struct {
|
||||
*antlr.BaseParserRuleContext
|
||||
parser antlr.Parser
|
||||
star antlr.Token
|
||||
}
|
||||
|
||||
func NewEmptyPointerTypeContext() *PointerTypeContext {
|
||||
var p = new(PointerTypeContext)
|
||||
p.BaseParserRuleContext = antlr.NewBaseParserRuleContext(nil, -1)
|
||||
p.RuleIndex = ApiParserParserRULE_pointerType
|
||||
return p
|
||||
}
|
||||
|
||||
func (*PointerTypeContext) IsPointerTypeContext() {}
|
||||
|
||||
func NewPointerTypeContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *PointerTypeContext {
|
||||
var p = new(PointerTypeContext)
|
||||
|
||||
p.BaseParserRuleContext = antlr.NewBaseParserRuleContext(parent, invokingState)
|
||||
|
||||
p.parser = parser
|
||||
p.RuleIndex = ApiParserParserRULE_pointerType
|
||||
|
||||
return p
|
||||
}
|
||||
|
||||
func (s *PointerTypeContext) GetParser() antlr.Parser { return s.parser }
|
||||
|
||||
func (s *PointerTypeContext) GetStar() antlr.Token { return s.star }
|
||||
|
||||
func (s *PointerTypeContext) SetStar(v antlr.Token) { s.star = v }
|
||||
|
||||
func (s *PointerTypeContext) ID() antlr.TerminalNode {
|
||||
return s.GetToken(ApiParserParserID, 0)
|
||||
}
|
||||
|
||||
func (s *PointerTypeContext) GetRuleContext() antlr.RuleContext {
|
||||
return s
|
||||
}
|
||||
|
||||
func (s *PointerTypeContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string {
|
||||
return antlr.TreesStringTree(s, ruleNames, recog)
|
||||
}
|
||||
|
||||
func (s *PointerTypeContext) Accept(visitor antlr.ParseTreeVisitor) interface{} {
|
||||
switch t := visitor.(type) {
|
||||
case ApiParserVisitor:
|
||||
return t.VisitPointerType(s)
|
||||
|
||||
default:
|
||||
return t.VisitChildren(s)
|
||||
}
|
||||
}
|
||||
|
||||
func (p *ApiParserParser) PointerType() (localctx IPointerTypeContext) {
|
||||
localctx = NewPointerTypeContext(p, p.GetParserRuleContext(), p.GetState())
|
||||
p.EnterRule(localctx, 44, ApiParserParserRULE_pointerType)
|
||||
|
||||
defer func() {
|
||||
p.ExitRule()
|
||||
}()
|
||||
|
||||
defer func() {
|
||||
if err := recover(); err != nil {
|
||||
if v, ok := err.(antlr.RecognitionException); ok {
|
||||
localctx.SetException(v)
|
||||
p.GetErrorHandler().ReportError(p, v)
|
||||
p.GetErrorHandler().Recover(p, v)
|
||||
} else {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
p.EnterOuterAlt(localctx, 1)
|
||||
{
|
||||
p.SetState(221)
|
||||
|
||||
var _m = p.Match(ApiParserParserT__5)
|
||||
|
||||
localctx.(*PointerTypeContext).star = _m
|
||||
}
|
||||
checkKeyword(p)
|
||||
{
|
||||
p.SetState(223)
|
||||
p.Match(ApiParserParserID)
|
||||
}
|
||||
|
||||
return localctx
|
||||
}
|
||||
|
||||
// IMapTypeContext is an interface to support dynamic dispatch.
|
||||
type IMapTypeContext interface {
|
||||
antlr.ParserRuleContext
|
||||
|
||||
// GetParser returns the parser.
|
||||
GetParser() antlr.Parser
|
||||
|
||||
// GetMapToken returns the mapToken token.
|
||||
GetMapToken() antlr.Token
|
||||
|
||||
// GetLbrack returns the lbrack token.
|
||||
GetLbrack() antlr.Token
|
||||
|
||||
// GetKey returns the key token.
|
||||
GetKey() antlr.Token
|
||||
|
||||
// GetRbrack returns the rbrack token.
|
||||
GetRbrack() antlr.Token
|
||||
|
||||
// SetMapToken sets the mapToken token.
|
||||
SetMapToken(antlr.Token)
|
||||
|
||||
// SetLbrack sets the lbrack token.
|
||||
SetLbrack(antlr.Token)
|
||||
|
||||
// SetKey sets the key token.
|
||||
SetKey(antlr.Token)
|
||||
|
||||
// SetRbrack sets the rbrack token.
|
||||
SetRbrack(antlr.Token)
|
||||
|
||||
// GetValue returns the value rule contexts.
|
||||
GetValue() IDataTypeContext
|
||||
|
||||
// SetValue sets the value rule contexts.
|
||||
SetValue(IDataTypeContext)
|
||||
|
||||
// IsMapTypeContext differentiates from other interfaces.
|
||||
IsMapTypeContext()
|
||||
}
|
||||
|
||||
type MapTypeContext struct {
|
||||
*antlr.BaseParserRuleContext
|
||||
parser antlr.Parser
|
||||
mapToken antlr.Token
|
||||
lbrack antlr.Token
|
||||
key antlr.Token
|
||||
rbrack antlr.Token
|
||||
value IDataTypeContext
|
||||
}
|
||||
|
||||
func NewEmptyMapTypeContext() *MapTypeContext {
|
||||
var p = new(MapTypeContext)
|
||||
p.BaseParserRuleContext = antlr.NewBaseParserRuleContext(nil, -1)
|
||||
p.RuleIndex = ApiParserParserRULE_mapType
|
||||
return p
|
||||
}
|
||||
|
||||
func (*MapTypeContext) IsMapTypeContext() {}
|
||||
|
||||
func NewMapTypeContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *MapTypeContext {
|
||||
var p = new(MapTypeContext)
|
||||
|
||||
p.BaseParserRuleContext = antlr.NewBaseParserRuleContext(parent, invokingState)
|
||||
|
||||
p.parser = parser
|
||||
p.RuleIndex = ApiParserParserRULE_mapType
|
||||
|
||||
return p
|
||||
}
|
||||
|
||||
func (s *MapTypeContext) GetParser() antlr.Parser { return s.parser }
|
||||
|
||||
func (s *MapTypeContext) GetMapToken() antlr.Token { return s.mapToken }
|
||||
|
||||
func (s *MapTypeContext) GetLbrack() antlr.Token { return s.lbrack }
|
||||
|
||||
func (s *MapTypeContext) GetKey() antlr.Token { return s.key }
|
||||
|
||||
func (s *MapTypeContext) GetRbrack() antlr.Token { return s.rbrack }
|
||||
|
||||
func (s *MapTypeContext) SetMapToken(v antlr.Token) { s.mapToken = v }
|
||||
|
||||
func (s *MapTypeContext) SetLbrack(v antlr.Token) { s.lbrack = v }
|
||||
|
||||
func (s *MapTypeContext) SetKey(v antlr.Token) { s.key = v }
|
||||
|
||||
func (s *MapTypeContext) SetRbrack(v antlr.Token) { s.rbrack = v }
|
||||
|
||||
func (s *MapTypeContext) GetValue() IDataTypeContext { return s.value }
|
||||
|
||||
func (s *MapTypeContext) SetValue(v IDataTypeContext) { s.value = v }
|
||||
|
||||
func (s *MapTypeContext) AllID() []antlr.TerminalNode {
|
||||
return s.GetTokens(ApiParserParserID)
|
||||
}
|
||||
|
||||
func (s *MapTypeContext) ID(i int) antlr.TerminalNode {
|
||||
return s.GetToken(ApiParserParserID, i)
|
||||
}
|
||||
|
||||
func (s *MapTypeContext) DataType() IDataTypeContext {
|
||||
var t = s.GetTypedRuleContext(reflect.TypeOf((*IDataTypeContext)(nil)).Elem(), 0)
|
||||
|
||||
if t == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
return t.(IDataTypeContext)
|
||||
}
|
||||
|
||||
func (s *MapTypeContext) GetRuleContext() antlr.RuleContext {
|
||||
return s
|
||||
}
|
||||
|
||||
func (s *MapTypeContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string {
|
||||
return antlr.TreesStringTree(s, ruleNames, recog)
|
||||
}
|
||||
|
||||
func (s *MapTypeContext) Accept(visitor antlr.ParseTreeVisitor) interface{} {
|
||||
switch t := visitor.(type) {
|
||||
case ApiParserVisitor:
|
||||
return t.VisitMapType(s)
|
||||
|
||||
default:
|
||||
return t.VisitChildren(s)
|
||||
}
|
||||
}
|
||||
|
||||
func (p *ApiParserParser) MapType() (localctx IMapTypeContext) {
|
||||
localctx = NewMapTypeContext(p, p.GetParserRuleContext(), p.GetState())
|
||||
p.EnterRule(localctx, 46, ApiParserParserRULE_mapType)
|
||||
|
||||
defer func() {
|
||||
p.ExitRule()
|
||||
}()
|
||||
|
||||
defer func() {
|
||||
if err := recover(); err != nil {
|
||||
if v, ok := err.(antlr.RecognitionException); ok {
|
||||
localctx.SetException(v)
|
||||
p.GetErrorHandler().ReportError(p, v)
|
||||
p.GetErrorHandler().Recover(p, v)
|
||||
} else {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
p.EnterOuterAlt(localctx, 1)
|
||||
match(p, "map")
|
||||
{
|
||||
p.SetState(226)
|
||||
|
||||
var _m = p.Match(ApiParserParserID)
|
||||
|
||||
localctx.(*MapTypeContext).mapToken = _m
|
||||
}
|
||||
{
|
||||
p.SetState(227)
|
||||
|
||||
var _m = p.Match(ApiParserParserT__7)
|
||||
|
||||
localctx.(*MapTypeContext).lbrack = _m
|
||||
}
|
||||
checkKey(p)
|
||||
{
|
||||
p.SetState(229)
|
||||
|
||||
var _m = p.Match(ApiParserParserID)
|
||||
|
||||
localctx.(*MapTypeContext).key = _m
|
||||
}
|
||||
{
|
||||
p.SetState(230)
|
||||
|
||||
var _m = p.Match(ApiParserParserT__8)
|
||||
|
||||
localctx.(*MapTypeContext).rbrack = _m
|
||||
}
|
||||
{
|
||||
p.SetState(231)
|
||||
|
||||
var _x = p.DataType()
|
||||
|
||||
localctx.(*MapTypeContext).value = _x
|
||||
}
|
||||
|
||||
return localctx
|
||||
}
|
||||
613
tools/goctl/api/parser/g4/gen/api/apiparser_parser6.go
Executable file
613
tools/goctl/api/parser/g4/gen/api/apiparser_parser6.go
Executable file
@@ -0,0 +1,613 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
|
||||
"github.com/zeromicro/antlr"
|
||||
)
|
||||
|
||||
// Part 6
|
||||
// The apiparser_parser.go file was split into multiple files because it
|
||||
// was too large and caused a possible memory overflow during goctl installation.
|
||||
|
||||
// IArrayTypeContext is an interface to support dynamic dispatch.
|
||||
type IArrayTypeContext interface {
|
||||
antlr.ParserRuleContext
|
||||
|
||||
// GetParser returns the parser.
|
||||
GetParser() antlr.Parser
|
||||
|
||||
// GetLbrack returns the lbrack token.
|
||||
GetLbrack() antlr.Token
|
||||
|
||||
// GetRbrack returns the rbrack token.
|
||||
GetRbrack() antlr.Token
|
||||
|
||||
// SetLbrack sets the lbrack token.
|
||||
SetLbrack(antlr.Token)
|
||||
|
||||
// SetRbrack sets the rbrack token.
|
||||
SetRbrack(antlr.Token)
|
||||
|
||||
// IsArrayTypeContext differentiates from other interfaces.
|
||||
IsArrayTypeContext()
|
||||
}
|
||||
|
||||
type ArrayTypeContext struct {
|
||||
*antlr.BaseParserRuleContext
|
||||
parser antlr.Parser
|
||||
lbrack antlr.Token
|
||||
rbrack antlr.Token
|
||||
}
|
||||
|
||||
func NewEmptyArrayTypeContext() *ArrayTypeContext {
|
||||
var p = new(ArrayTypeContext)
|
||||
p.BaseParserRuleContext = antlr.NewBaseParserRuleContext(nil, -1)
|
||||
p.RuleIndex = ApiParserParserRULE_arrayType
|
||||
return p
|
||||
}
|
||||
|
||||
func (*ArrayTypeContext) IsArrayTypeContext() {}
|
||||
|
||||
func NewArrayTypeContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *ArrayTypeContext {
|
||||
var p = new(ArrayTypeContext)
|
||||
|
||||
p.BaseParserRuleContext = antlr.NewBaseParserRuleContext(parent, invokingState)
|
||||
|
||||
p.parser = parser
|
||||
p.RuleIndex = ApiParserParserRULE_arrayType
|
||||
|
||||
return p
|
||||
}
|
||||
|
||||
func (s *ArrayTypeContext) GetParser() antlr.Parser { return s.parser }
|
||||
|
||||
func (s *ArrayTypeContext) GetLbrack() antlr.Token { return s.lbrack }
|
||||
|
||||
func (s *ArrayTypeContext) GetRbrack() antlr.Token { return s.rbrack }
|
||||
|
||||
func (s *ArrayTypeContext) SetLbrack(v antlr.Token) { s.lbrack = v }
|
||||
|
||||
func (s *ArrayTypeContext) SetRbrack(v antlr.Token) { s.rbrack = v }
|
||||
|
||||
func (s *ArrayTypeContext) DataType() IDataTypeContext {
|
||||
var t = s.GetTypedRuleContext(reflect.TypeOf((*IDataTypeContext)(nil)).Elem(), 0)
|
||||
|
||||
if t == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
return t.(IDataTypeContext)
|
||||
}
|
||||
|
||||
func (s *ArrayTypeContext) GetRuleContext() antlr.RuleContext {
|
||||
return s
|
||||
}
|
||||
|
||||
func (s *ArrayTypeContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string {
|
||||
return antlr.TreesStringTree(s, ruleNames, recog)
|
||||
}
|
||||
|
||||
func (s *ArrayTypeContext) Accept(visitor antlr.ParseTreeVisitor) interface{} {
|
||||
switch t := visitor.(type) {
|
||||
case ApiParserVisitor:
|
||||
return t.VisitArrayType(s)
|
||||
|
||||
default:
|
||||
return t.VisitChildren(s)
|
||||
}
|
||||
}
|
||||
|
||||
func (p *ApiParserParser) ArrayType() (localctx IArrayTypeContext) {
|
||||
localctx = NewArrayTypeContext(p, p.GetParserRuleContext(), p.GetState())
|
||||
p.EnterRule(localctx, 48, ApiParserParserRULE_arrayType)
|
||||
|
||||
defer func() {
|
||||
p.ExitRule()
|
||||
}()
|
||||
|
||||
defer func() {
|
||||
if err := recover(); err != nil {
|
||||
if v, ok := err.(antlr.RecognitionException); ok {
|
||||
localctx.SetException(v)
|
||||
p.GetErrorHandler().ReportError(p, v)
|
||||
p.GetErrorHandler().Recover(p, v)
|
||||
} else {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
p.EnterOuterAlt(localctx, 1)
|
||||
{
|
||||
p.SetState(233)
|
||||
|
||||
var _m = p.Match(ApiParserParserT__7)
|
||||
|
||||
localctx.(*ArrayTypeContext).lbrack = _m
|
||||
}
|
||||
{
|
||||
p.SetState(234)
|
||||
|
||||
var _m = p.Match(ApiParserParserT__8)
|
||||
|
||||
localctx.(*ArrayTypeContext).rbrack = _m
|
||||
}
|
||||
{
|
||||
p.SetState(235)
|
||||
p.DataType()
|
||||
}
|
||||
|
||||
return localctx
|
||||
}
|
||||
|
||||
// IServiceSpecContext is an interface to support dynamic dispatch.
|
||||
type IServiceSpecContext interface {
|
||||
antlr.ParserRuleContext
|
||||
|
||||
// GetParser returns the parser.
|
||||
GetParser() antlr.Parser
|
||||
|
||||
// IsServiceSpecContext differentiates from other interfaces.
|
||||
IsServiceSpecContext()
|
||||
}
|
||||
|
||||
type ServiceSpecContext struct {
|
||||
*antlr.BaseParserRuleContext
|
||||
parser antlr.Parser
|
||||
}
|
||||
|
||||
func NewEmptyServiceSpecContext() *ServiceSpecContext {
|
||||
var p = new(ServiceSpecContext)
|
||||
p.BaseParserRuleContext = antlr.NewBaseParserRuleContext(nil, -1)
|
||||
p.RuleIndex = ApiParserParserRULE_serviceSpec
|
||||
return p
|
||||
}
|
||||
|
||||
func (*ServiceSpecContext) IsServiceSpecContext() {}
|
||||
|
||||
func NewServiceSpecContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *ServiceSpecContext {
|
||||
var p = new(ServiceSpecContext)
|
||||
|
||||
p.BaseParserRuleContext = antlr.NewBaseParserRuleContext(parent, invokingState)
|
||||
|
||||
p.parser = parser
|
||||
p.RuleIndex = ApiParserParserRULE_serviceSpec
|
||||
|
||||
return p
|
||||
}
|
||||
|
||||
func (s *ServiceSpecContext) GetParser() antlr.Parser { return s.parser }
|
||||
|
||||
func (s *ServiceSpecContext) ServiceApi() IServiceApiContext {
|
||||
var t = s.GetTypedRuleContext(reflect.TypeOf((*IServiceApiContext)(nil)).Elem(), 0)
|
||||
|
||||
if t == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
return t.(IServiceApiContext)
|
||||
}
|
||||
|
||||
func (s *ServiceSpecContext) AtServer() IAtServerContext {
|
||||
var t = s.GetTypedRuleContext(reflect.TypeOf((*IAtServerContext)(nil)).Elem(), 0)
|
||||
|
||||
if t == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
return t.(IAtServerContext)
|
||||
}
|
||||
|
||||
func (s *ServiceSpecContext) GetRuleContext() antlr.RuleContext {
|
||||
return s
|
||||
}
|
||||
|
||||
func (s *ServiceSpecContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string {
|
||||
return antlr.TreesStringTree(s, ruleNames, recog)
|
||||
}
|
||||
|
||||
func (s *ServiceSpecContext) Accept(visitor antlr.ParseTreeVisitor) interface{} {
|
||||
switch t := visitor.(type) {
|
||||
case ApiParserVisitor:
|
||||
return t.VisitServiceSpec(s)
|
||||
|
||||
default:
|
||||
return t.VisitChildren(s)
|
||||
}
|
||||
}
|
||||
|
||||
func (p *ApiParserParser) ServiceSpec() (localctx IServiceSpecContext) {
|
||||
localctx = NewServiceSpecContext(p, p.GetParserRuleContext(), p.GetState())
|
||||
p.EnterRule(localctx, 50, ApiParserParserRULE_serviceSpec)
|
||||
var _la int
|
||||
|
||||
defer func() {
|
||||
p.ExitRule()
|
||||
}()
|
||||
|
||||
defer func() {
|
||||
if err := recover(); err != nil {
|
||||
if v, ok := err.(antlr.RecognitionException); ok {
|
||||
localctx.SetException(v)
|
||||
p.GetErrorHandler().ReportError(p, v)
|
||||
p.GetErrorHandler().Recover(p, v)
|
||||
} else {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
p.EnterOuterAlt(localctx, 1)
|
||||
p.SetState(238)
|
||||
p.GetErrorHandler().Sync(p)
|
||||
_la = p.GetTokenStream().LA(1)
|
||||
|
||||
if _la == ApiParserParserATSERVER {
|
||||
{
|
||||
p.SetState(237)
|
||||
p.AtServer()
|
||||
}
|
||||
|
||||
}
|
||||
{
|
||||
p.SetState(240)
|
||||
p.ServiceApi()
|
||||
}
|
||||
|
||||
return localctx
|
||||
}
|
||||
|
||||
// IAtServerContext is an interface to support dynamic dispatch.
|
||||
type IAtServerContext interface {
|
||||
antlr.ParserRuleContext
|
||||
|
||||
// GetParser returns the parser.
|
||||
GetParser() antlr.Parser
|
||||
|
||||
// GetLp returns the lp token.
|
||||
GetLp() antlr.Token
|
||||
|
||||
// GetRp returns the rp token.
|
||||
GetRp() antlr.Token
|
||||
|
||||
// SetLp sets the lp token.
|
||||
SetLp(antlr.Token)
|
||||
|
||||
// SetRp sets the rp token.
|
||||
SetRp(antlr.Token)
|
||||
|
||||
// IsAtServerContext differentiates from other interfaces.
|
||||
IsAtServerContext()
|
||||
}
|
||||
|
||||
type AtServerContext struct {
|
||||
*antlr.BaseParserRuleContext
|
||||
parser antlr.Parser
|
||||
lp antlr.Token
|
||||
rp antlr.Token
|
||||
}
|
||||
|
||||
func NewEmptyAtServerContext() *AtServerContext {
|
||||
var p = new(AtServerContext)
|
||||
p.BaseParserRuleContext = antlr.NewBaseParserRuleContext(nil, -1)
|
||||
p.RuleIndex = ApiParserParserRULE_atServer
|
||||
return p
|
||||
}
|
||||
|
||||
func (*AtServerContext) IsAtServerContext() {}
|
||||
|
||||
func NewAtServerContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *AtServerContext {
|
||||
var p = new(AtServerContext)
|
||||
|
||||
p.BaseParserRuleContext = antlr.NewBaseParserRuleContext(parent, invokingState)
|
||||
|
||||
p.parser = parser
|
||||
p.RuleIndex = ApiParserParserRULE_atServer
|
||||
|
||||
return p
|
||||
}
|
||||
|
||||
func (s *AtServerContext) GetParser() antlr.Parser { return s.parser }
|
||||
|
||||
func (s *AtServerContext) GetLp() antlr.Token { return s.lp }
|
||||
|
||||
func (s *AtServerContext) GetRp() antlr.Token { return s.rp }
|
||||
|
||||
func (s *AtServerContext) SetLp(v antlr.Token) { s.lp = v }
|
||||
|
||||
func (s *AtServerContext) SetRp(v antlr.Token) { s.rp = v }
|
||||
|
||||
func (s *AtServerContext) ATSERVER() antlr.TerminalNode {
|
||||
return s.GetToken(ApiParserParserATSERVER, 0)
|
||||
}
|
||||
|
||||
func (s *AtServerContext) AllKvLit() []IKvLitContext {
|
||||
var ts = s.GetTypedRuleContexts(reflect.TypeOf((*IKvLitContext)(nil)).Elem())
|
||||
var tst = make([]IKvLitContext, len(ts))
|
||||
|
||||
for i, t := range ts {
|
||||
if t != nil {
|
||||
tst[i] = t.(IKvLitContext)
|
||||
}
|
||||
}
|
||||
|
||||
return tst
|
||||
}
|
||||
|
||||
func (s *AtServerContext) KvLit(i int) IKvLitContext {
|
||||
var t = s.GetTypedRuleContext(reflect.TypeOf((*IKvLitContext)(nil)).Elem(), i)
|
||||
|
||||
if t == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
return t.(IKvLitContext)
|
||||
}
|
||||
|
||||
func (s *AtServerContext) GetRuleContext() antlr.RuleContext {
|
||||
return s
|
||||
}
|
||||
|
||||
func (s *AtServerContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string {
|
||||
return antlr.TreesStringTree(s, ruleNames, recog)
|
||||
}
|
||||
|
||||
func (s *AtServerContext) Accept(visitor antlr.ParseTreeVisitor) interface{} {
|
||||
switch t := visitor.(type) {
|
||||
case ApiParserVisitor:
|
||||
return t.VisitAtServer(s)
|
||||
|
||||
default:
|
||||
return t.VisitChildren(s)
|
||||
}
|
||||
}
|
||||
|
||||
func (p *ApiParserParser) AtServer() (localctx IAtServerContext) {
|
||||
localctx = NewAtServerContext(p, p.GetParserRuleContext(), p.GetState())
|
||||
p.EnterRule(localctx, 52, ApiParserParserRULE_atServer)
|
||||
var _la int
|
||||
|
||||
defer func() {
|
||||
p.ExitRule()
|
||||
}()
|
||||
|
||||
defer func() {
|
||||
if err := recover(); err != nil {
|
||||
if v, ok := err.(antlr.RecognitionException); ok {
|
||||
localctx.SetException(v)
|
||||
p.GetErrorHandler().ReportError(p, v)
|
||||
p.GetErrorHandler().Recover(p, v)
|
||||
} else {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
p.EnterOuterAlt(localctx, 1)
|
||||
{
|
||||
p.SetState(242)
|
||||
p.Match(ApiParserParserATSERVER)
|
||||
}
|
||||
{
|
||||
p.SetState(243)
|
||||
|
||||
var _m = p.Match(ApiParserParserT__1)
|
||||
|
||||
localctx.(*AtServerContext).lp = _m
|
||||
}
|
||||
p.SetState(245)
|
||||
p.GetErrorHandler().Sync(p)
|
||||
|
||||
for ok := true; ok; ok = _la == ApiParserParserID {
|
||||
{
|
||||
p.SetState(244)
|
||||
p.KvLit()
|
||||
}
|
||||
|
||||
p.SetState(247)
|
||||
p.GetErrorHandler().Sync(p)
|
||||
_la = p.GetTokenStream().LA(1)
|
||||
}
|
||||
{
|
||||
p.SetState(249)
|
||||
|
||||
var _m = p.Match(ApiParserParserT__2)
|
||||
|
||||
localctx.(*AtServerContext).rp = _m
|
||||
}
|
||||
|
||||
return localctx
|
||||
}
|
||||
|
||||
// IServiceApiContext is an interface to support dynamic dispatch.
|
||||
type IServiceApiContext interface {
|
||||
antlr.ParserRuleContext
|
||||
|
||||
// GetParser returns the parser.
|
||||
GetParser() antlr.Parser
|
||||
|
||||
// GetServiceToken returns the serviceToken token.
|
||||
GetServiceToken() antlr.Token
|
||||
|
||||
// GetLbrace returns the lbrace token.
|
||||
GetLbrace() antlr.Token
|
||||
|
||||
// GetRbrace returns the rbrace token.
|
||||
GetRbrace() antlr.Token
|
||||
|
||||
// SetServiceToken sets the serviceToken token.
|
||||
SetServiceToken(antlr.Token)
|
||||
|
||||
// SetLbrace sets the lbrace token.
|
||||
SetLbrace(antlr.Token)
|
||||
|
||||
// SetRbrace sets the rbrace token.
|
||||
SetRbrace(antlr.Token)
|
||||
|
||||
// IsServiceApiContext differentiates from other interfaces.
|
||||
IsServiceApiContext()
|
||||
}
|
||||
|
||||
type ServiceApiContext struct {
|
||||
*antlr.BaseParserRuleContext
|
||||
parser antlr.Parser
|
||||
serviceToken antlr.Token
|
||||
lbrace antlr.Token
|
||||
rbrace antlr.Token
|
||||
}
|
||||
|
||||
func NewEmptyServiceApiContext() *ServiceApiContext {
|
||||
var p = new(ServiceApiContext)
|
||||
p.BaseParserRuleContext = antlr.NewBaseParserRuleContext(nil, -1)
|
||||
p.RuleIndex = ApiParserParserRULE_serviceApi
|
||||
return p
|
||||
}
|
||||
|
||||
func (*ServiceApiContext) IsServiceApiContext() {}
|
||||
|
||||
func NewServiceApiContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *ServiceApiContext {
|
||||
var p = new(ServiceApiContext)
|
||||
|
||||
p.BaseParserRuleContext = antlr.NewBaseParserRuleContext(parent, invokingState)
|
||||
|
||||
p.parser = parser
|
||||
p.RuleIndex = ApiParserParserRULE_serviceApi
|
||||
|
||||
return p
|
||||
}
|
||||
|
||||
func (s *ServiceApiContext) GetParser() antlr.Parser { return s.parser }
|
||||
|
||||
func (s *ServiceApiContext) GetServiceToken() antlr.Token { return s.serviceToken }
|
||||
|
||||
func (s *ServiceApiContext) GetLbrace() antlr.Token { return s.lbrace }
|
||||
|
||||
func (s *ServiceApiContext) GetRbrace() antlr.Token { return s.rbrace }
|
||||
|
||||
func (s *ServiceApiContext) SetServiceToken(v antlr.Token) { s.serviceToken = v }
|
||||
|
||||
func (s *ServiceApiContext) SetLbrace(v antlr.Token) { s.lbrace = v }
|
||||
|
||||
func (s *ServiceApiContext) SetRbrace(v antlr.Token) { s.rbrace = v }
|
||||
|
||||
func (s *ServiceApiContext) ServiceName() IServiceNameContext {
|
||||
var t = s.GetTypedRuleContext(reflect.TypeOf((*IServiceNameContext)(nil)).Elem(), 0)
|
||||
|
||||
if t == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
return t.(IServiceNameContext)
|
||||
}
|
||||
|
||||
func (s *ServiceApiContext) ID() antlr.TerminalNode {
|
||||
return s.GetToken(ApiParserParserID, 0)
|
||||
}
|
||||
|
||||
func (s *ServiceApiContext) AllServiceRoute() []IServiceRouteContext {
|
||||
var ts = s.GetTypedRuleContexts(reflect.TypeOf((*IServiceRouteContext)(nil)).Elem())
|
||||
var tst = make([]IServiceRouteContext, len(ts))
|
||||
|
||||
for i, t := range ts {
|
||||
if t != nil {
|
||||
tst[i] = t.(IServiceRouteContext)
|
||||
}
|
||||
}
|
||||
|
||||
return tst
|
||||
}
|
||||
|
||||
func (s *ServiceApiContext) ServiceRoute(i int) IServiceRouteContext {
|
||||
var t = s.GetTypedRuleContext(reflect.TypeOf((*IServiceRouteContext)(nil)).Elem(), i)
|
||||
|
||||
if t == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
return t.(IServiceRouteContext)
|
||||
}
|
||||
|
||||
func (s *ServiceApiContext) GetRuleContext() antlr.RuleContext {
|
||||
return s
|
||||
}
|
||||
|
||||
func (s *ServiceApiContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string {
|
||||
return antlr.TreesStringTree(s, ruleNames, recog)
|
||||
}
|
||||
|
||||
func (s *ServiceApiContext) Accept(visitor antlr.ParseTreeVisitor) interface{} {
|
||||
switch t := visitor.(type) {
|
||||
case ApiParserVisitor:
|
||||
return t.VisitServiceApi(s)
|
||||
|
||||
default:
|
||||
return t.VisitChildren(s)
|
||||
}
|
||||
}
|
||||
|
||||
func (p *ApiParserParser) ServiceApi() (localctx IServiceApiContext) {
|
||||
localctx = NewServiceApiContext(p, p.GetParserRuleContext(), p.GetState())
|
||||
p.EnterRule(localctx, 54, ApiParserParserRULE_serviceApi)
|
||||
var _la int
|
||||
|
||||
defer func() {
|
||||
p.ExitRule()
|
||||
}()
|
||||
|
||||
defer func() {
|
||||
if err := recover(); err != nil {
|
||||
if v, ok := err.(antlr.RecognitionException); ok {
|
||||
localctx.SetException(v)
|
||||
p.GetErrorHandler().ReportError(p, v)
|
||||
p.GetErrorHandler().Recover(p, v)
|
||||
} else {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
p.EnterOuterAlt(localctx, 1)
|
||||
match(p, "service")
|
||||
{
|
||||
p.SetState(252)
|
||||
|
||||
var _m = p.Match(ApiParserParserID)
|
||||
|
||||
localctx.(*ServiceApiContext).serviceToken = _m
|
||||
}
|
||||
{
|
||||
p.SetState(253)
|
||||
p.ServiceName()
|
||||
}
|
||||
{
|
||||
p.SetState(254)
|
||||
|
||||
var _m = p.Match(ApiParserParserT__3)
|
||||
|
||||
localctx.(*ServiceApiContext).lbrace = _m
|
||||
}
|
||||
p.SetState(258)
|
||||
p.GetErrorHandler().Sync(p)
|
||||
_la = p.GetTokenStream().LA(1)
|
||||
|
||||
for ((_la)&-(0x1f+1)) == 0 && ((1<<uint(_la))&((1<<ApiParserParserATDOC)|(1<<ApiParserParserATHANDLER)|(1<<ApiParserParserATSERVER))) != 0 {
|
||||
{
|
||||
p.SetState(255)
|
||||
p.ServiceRoute()
|
||||
}
|
||||
|
||||
p.SetState(260)
|
||||
p.GetErrorHandler().Sync(p)
|
||||
_la = p.GetTokenStream().LA(1)
|
||||
}
|
||||
{
|
||||
p.SetState(261)
|
||||
|
||||
var _m = p.Match(ApiParserParserT__4)
|
||||
|
||||
localctx.(*ServiceApiContext).rbrace = _m
|
||||
}
|
||||
|
||||
return localctx
|
||||
}
|
||||
676
tools/goctl/api/parser/g4/gen/api/apiparser_parser7.go
Executable file
676
tools/goctl/api/parser/g4/gen/api/apiparser_parser7.go
Executable file
@@ -0,0 +1,676 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
|
||||
"github.com/zeromicro/antlr"
|
||||
)
|
||||
|
||||
// Part 7
|
||||
// The apiparser_parser.go file was split into multiple files because it
|
||||
// was too large and caused a possible memory overflow during goctl installation.
|
||||
|
||||
// IServiceRouteContext is an interface to support dynamic dispatch.
|
||||
type IServiceRouteContext interface {
|
||||
antlr.ParserRuleContext
|
||||
|
||||
// GetParser returns the parser.
|
||||
GetParser() antlr.Parser
|
||||
|
||||
// IsServiceRouteContext differentiates from other interfaces.
|
||||
IsServiceRouteContext()
|
||||
}
|
||||
|
||||
type ServiceRouteContext struct {
|
||||
*antlr.BaseParserRuleContext
|
||||
parser antlr.Parser
|
||||
}
|
||||
|
||||
func NewEmptyServiceRouteContext() *ServiceRouteContext {
|
||||
var p = new(ServiceRouteContext)
|
||||
p.BaseParserRuleContext = antlr.NewBaseParserRuleContext(nil, -1)
|
||||
p.RuleIndex = ApiParserParserRULE_serviceRoute
|
||||
return p
|
||||
}
|
||||
|
||||
func (*ServiceRouteContext) IsServiceRouteContext() {}
|
||||
|
||||
func NewServiceRouteContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *ServiceRouteContext {
|
||||
var p = new(ServiceRouteContext)
|
||||
|
||||
p.BaseParserRuleContext = antlr.NewBaseParserRuleContext(parent, invokingState)
|
||||
|
||||
p.parser = parser
|
||||
p.RuleIndex = ApiParserParserRULE_serviceRoute
|
||||
|
||||
return p
|
||||
}
|
||||
|
||||
func (s *ServiceRouteContext) GetParser() antlr.Parser { return s.parser }
|
||||
|
||||
func (s *ServiceRouteContext) Route() IRouteContext {
|
||||
var t = s.GetTypedRuleContext(reflect.TypeOf((*IRouteContext)(nil)).Elem(), 0)
|
||||
|
||||
if t == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
return t.(IRouteContext)
|
||||
}
|
||||
|
||||
func (s *ServiceRouteContext) AtServer() IAtServerContext {
|
||||
var t = s.GetTypedRuleContext(reflect.TypeOf((*IAtServerContext)(nil)).Elem(), 0)
|
||||
|
||||
if t == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
return t.(IAtServerContext)
|
||||
}
|
||||
|
||||
func (s *ServiceRouteContext) AtHandler() IAtHandlerContext {
|
||||
var t = s.GetTypedRuleContext(reflect.TypeOf((*IAtHandlerContext)(nil)).Elem(), 0)
|
||||
|
||||
if t == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
return t.(IAtHandlerContext)
|
||||
}
|
||||
|
||||
func (s *ServiceRouteContext) AtDoc() IAtDocContext {
|
||||
var t = s.GetTypedRuleContext(reflect.TypeOf((*IAtDocContext)(nil)).Elem(), 0)
|
||||
|
||||
if t == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
return t.(IAtDocContext)
|
||||
}
|
||||
|
||||
func (s *ServiceRouteContext) GetRuleContext() antlr.RuleContext {
|
||||
return s
|
||||
}
|
||||
|
||||
func (s *ServiceRouteContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string {
|
||||
return antlr.TreesStringTree(s, ruleNames, recog)
|
||||
}
|
||||
|
||||
func (s *ServiceRouteContext) Accept(visitor antlr.ParseTreeVisitor) interface{} {
|
||||
switch t := visitor.(type) {
|
||||
case ApiParserVisitor:
|
||||
return t.VisitServiceRoute(s)
|
||||
|
||||
default:
|
||||
return t.VisitChildren(s)
|
||||
}
|
||||
}
|
||||
|
||||
func (p *ApiParserParser) ServiceRoute() (localctx IServiceRouteContext) {
|
||||
localctx = NewServiceRouteContext(p, p.GetParserRuleContext(), p.GetState())
|
||||
p.EnterRule(localctx, 56, ApiParserParserRULE_serviceRoute)
|
||||
var _la int
|
||||
|
||||
defer func() {
|
||||
p.ExitRule()
|
||||
}()
|
||||
|
||||
defer func() {
|
||||
if err := recover(); err != nil {
|
||||
if v, ok := err.(antlr.RecognitionException); ok {
|
||||
localctx.SetException(v)
|
||||
p.GetErrorHandler().ReportError(p, v)
|
||||
p.GetErrorHandler().Recover(p, v)
|
||||
} else {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
p.EnterOuterAlt(localctx, 1)
|
||||
p.SetState(264)
|
||||
p.GetErrorHandler().Sync(p)
|
||||
_la = p.GetTokenStream().LA(1)
|
||||
|
||||
if _la == ApiParserParserATDOC {
|
||||
{
|
||||
p.SetState(263)
|
||||
p.AtDoc()
|
||||
}
|
||||
|
||||
}
|
||||
p.SetState(268)
|
||||
p.GetErrorHandler().Sync(p)
|
||||
|
||||
switch p.GetTokenStream().LA(1) {
|
||||
case ApiParserParserATSERVER:
|
||||
{
|
||||
p.SetState(266)
|
||||
p.AtServer()
|
||||
}
|
||||
|
||||
case ApiParserParserATHANDLER:
|
||||
{
|
||||
p.SetState(267)
|
||||
p.AtHandler()
|
||||
}
|
||||
|
||||
default:
|
||||
panic(antlr.NewNoViableAltException(p, nil, nil, nil, nil, nil))
|
||||
}
|
||||
{
|
||||
p.SetState(270)
|
||||
p.Route()
|
||||
}
|
||||
|
||||
return localctx
|
||||
}
|
||||
|
||||
// IAtDocContext is an interface to support dynamic dispatch.
|
||||
type IAtDocContext interface {
|
||||
antlr.ParserRuleContext
|
||||
|
||||
// GetParser returns the parser.
|
||||
GetParser() antlr.Parser
|
||||
|
||||
// GetLp returns the lp token.
|
||||
GetLp() antlr.Token
|
||||
|
||||
// GetRp returns the rp token.
|
||||
GetRp() antlr.Token
|
||||
|
||||
// SetLp sets the lp token.
|
||||
SetLp(antlr.Token)
|
||||
|
||||
// SetRp sets the rp token.
|
||||
SetRp(antlr.Token)
|
||||
|
||||
// IsAtDocContext differentiates from other interfaces.
|
||||
IsAtDocContext()
|
||||
}
|
||||
|
||||
type AtDocContext struct {
|
||||
*antlr.BaseParserRuleContext
|
||||
parser antlr.Parser
|
||||
lp antlr.Token
|
||||
rp antlr.Token
|
||||
}
|
||||
|
||||
func NewEmptyAtDocContext() *AtDocContext {
|
||||
var p = new(AtDocContext)
|
||||
p.BaseParserRuleContext = antlr.NewBaseParserRuleContext(nil, -1)
|
||||
p.RuleIndex = ApiParserParserRULE_atDoc
|
||||
return p
|
||||
}
|
||||
|
||||
func (*AtDocContext) IsAtDocContext() {}
|
||||
|
||||
func NewAtDocContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *AtDocContext {
|
||||
var p = new(AtDocContext)
|
||||
|
||||
p.BaseParserRuleContext = antlr.NewBaseParserRuleContext(parent, invokingState)
|
||||
|
||||
p.parser = parser
|
||||
p.RuleIndex = ApiParserParserRULE_atDoc
|
||||
|
||||
return p
|
||||
}
|
||||
|
||||
func (s *AtDocContext) GetParser() antlr.Parser { return s.parser }
|
||||
|
||||
func (s *AtDocContext) GetLp() antlr.Token { return s.lp }
|
||||
|
||||
func (s *AtDocContext) GetRp() antlr.Token { return s.rp }
|
||||
|
||||
func (s *AtDocContext) SetLp(v antlr.Token) { s.lp = v }
|
||||
|
||||
func (s *AtDocContext) SetRp(v antlr.Token) { s.rp = v }
|
||||
|
||||
func (s *AtDocContext) ATDOC() antlr.TerminalNode {
|
||||
return s.GetToken(ApiParserParserATDOC, 0)
|
||||
}
|
||||
|
||||
func (s *AtDocContext) STRING() antlr.TerminalNode {
|
||||
return s.GetToken(ApiParserParserSTRING, 0)
|
||||
}
|
||||
|
||||
func (s *AtDocContext) AllKvLit() []IKvLitContext {
|
||||
var ts = s.GetTypedRuleContexts(reflect.TypeOf((*IKvLitContext)(nil)).Elem())
|
||||
var tst = make([]IKvLitContext, len(ts))
|
||||
|
||||
for i, t := range ts {
|
||||
if t != nil {
|
||||
tst[i] = t.(IKvLitContext)
|
||||
}
|
||||
}
|
||||
|
||||
return tst
|
||||
}
|
||||
|
||||
func (s *AtDocContext) KvLit(i int) IKvLitContext {
|
||||
var t = s.GetTypedRuleContext(reflect.TypeOf((*IKvLitContext)(nil)).Elem(), i)
|
||||
|
||||
if t == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
return t.(IKvLitContext)
|
||||
}
|
||||
|
||||
func (s *AtDocContext) GetRuleContext() antlr.RuleContext {
|
||||
return s
|
||||
}
|
||||
|
||||
func (s *AtDocContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string {
|
||||
return antlr.TreesStringTree(s, ruleNames, recog)
|
||||
}
|
||||
|
||||
func (s *AtDocContext) Accept(visitor antlr.ParseTreeVisitor) interface{} {
|
||||
switch t := visitor.(type) {
|
||||
case ApiParserVisitor:
|
||||
return t.VisitAtDoc(s)
|
||||
|
||||
default:
|
||||
return t.VisitChildren(s)
|
||||
}
|
||||
}
|
||||
|
||||
func (p *ApiParserParser) AtDoc() (localctx IAtDocContext) {
|
||||
localctx = NewAtDocContext(p, p.GetParserRuleContext(), p.GetState())
|
||||
p.EnterRule(localctx, 58, ApiParserParserRULE_atDoc)
|
||||
var _la int
|
||||
|
||||
defer func() {
|
||||
p.ExitRule()
|
||||
}()
|
||||
|
||||
defer func() {
|
||||
if err := recover(); err != nil {
|
||||
if v, ok := err.(antlr.RecognitionException); ok {
|
||||
localctx.SetException(v)
|
||||
p.GetErrorHandler().ReportError(p, v)
|
||||
p.GetErrorHandler().Recover(p, v)
|
||||
} else {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
p.EnterOuterAlt(localctx, 1)
|
||||
{
|
||||
p.SetState(272)
|
||||
p.Match(ApiParserParserATDOC)
|
||||
}
|
||||
p.SetState(274)
|
||||
p.GetErrorHandler().Sync(p)
|
||||
_la = p.GetTokenStream().LA(1)
|
||||
|
||||
if _la == ApiParserParserT__1 {
|
||||
{
|
||||
p.SetState(273)
|
||||
|
||||
var _m = p.Match(ApiParserParserT__1)
|
||||
|
||||
localctx.(*AtDocContext).lp = _m
|
||||
}
|
||||
|
||||
}
|
||||
p.SetState(282)
|
||||
p.GetErrorHandler().Sync(p)
|
||||
|
||||
switch p.GetTokenStream().LA(1) {
|
||||
case ApiParserParserID:
|
||||
p.SetState(277)
|
||||
p.GetErrorHandler().Sync(p)
|
||||
|
||||
for ok := true; ok; ok = _la == ApiParserParserID {
|
||||
{
|
||||
p.SetState(276)
|
||||
p.KvLit()
|
||||
}
|
||||
|
||||
p.SetState(279)
|
||||
p.GetErrorHandler().Sync(p)
|
||||
_la = p.GetTokenStream().LA(1)
|
||||
}
|
||||
|
||||
case ApiParserParserSTRING:
|
||||
{
|
||||
p.SetState(281)
|
||||
p.Match(ApiParserParserSTRING)
|
||||
}
|
||||
|
||||
default:
|
||||
panic(antlr.NewNoViableAltException(p, nil, nil, nil, nil, nil))
|
||||
}
|
||||
p.SetState(285)
|
||||
p.GetErrorHandler().Sync(p)
|
||||
_la = p.GetTokenStream().LA(1)
|
||||
|
||||
if _la == ApiParserParserT__2 {
|
||||
{
|
||||
p.SetState(284)
|
||||
|
||||
var _m = p.Match(ApiParserParserT__2)
|
||||
|
||||
localctx.(*AtDocContext).rp = _m
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return localctx
|
||||
}
|
||||
|
||||
// IAtHandlerContext is an interface to support dynamic dispatch.
|
||||
type IAtHandlerContext interface {
|
||||
antlr.ParserRuleContext
|
||||
|
||||
// GetParser returns the parser.
|
||||
GetParser() antlr.Parser
|
||||
|
||||
// IsAtHandlerContext differentiates from other interfaces.
|
||||
IsAtHandlerContext()
|
||||
}
|
||||
|
||||
type AtHandlerContext struct {
|
||||
*antlr.BaseParserRuleContext
|
||||
parser antlr.Parser
|
||||
}
|
||||
|
||||
func NewEmptyAtHandlerContext() *AtHandlerContext {
|
||||
var p = new(AtHandlerContext)
|
||||
p.BaseParserRuleContext = antlr.NewBaseParserRuleContext(nil, -1)
|
||||
p.RuleIndex = ApiParserParserRULE_atHandler
|
||||
return p
|
||||
}
|
||||
|
||||
func (*AtHandlerContext) IsAtHandlerContext() {}
|
||||
|
||||
func NewAtHandlerContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *AtHandlerContext {
|
||||
var p = new(AtHandlerContext)
|
||||
|
||||
p.BaseParserRuleContext = antlr.NewBaseParserRuleContext(parent, invokingState)
|
||||
|
||||
p.parser = parser
|
||||
p.RuleIndex = ApiParserParserRULE_atHandler
|
||||
|
||||
return p
|
||||
}
|
||||
|
||||
func (s *AtHandlerContext) GetParser() antlr.Parser { return s.parser }
|
||||
|
||||
func (s *AtHandlerContext) ATHANDLER() antlr.TerminalNode {
|
||||
return s.GetToken(ApiParserParserATHANDLER, 0)
|
||||
}
|
||||
|
||||
func (s *AtHandlerContext) ID() antlr.TerminalNode {
|
||||
return s.GetToken(ApiParserParserID, 0)
|
||||
}
|
||||
|
||||
func (s *AtHandlerContext) GetRuleContext() antlr.RuleContext {
|
||||
return s
|
||||
}
|
||||
|
||||
func (s *AtHandlerContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string {
|
||||
return antlr.TreesStringTree(s, ruleNames, recog)
|
||||
}
|
||||
|
||||
func (s *AtHandlerContext) Accept(visitor antlr.ParseTreeVisitor) interface{} {
|
||||
switch t := visitor.(type) {
|
||||
case ApiParserVisitor:
|
||||
return t.VisitAtHandler(s)
|
||||
|
||||
default:
|
||||
return t.VisitChildren(s)
|
||||
}
|
||||
}
|
||||
|
||||
func (p *ApiParserParser) AtHandler() (localctx IAtHandlerContext) {
|
||||
localctx = NewAtHandlerContext(p, p.GetParserRuleContext(), p.GetState())
|
||||
p.EnterRule(localctx, 60, ApiParserParserRULE_atHandler)
|
||||
|
||||
defer func() {
|
||||
p.ExitRule()
|
||||
}()
|
||||
|
||||
defer func() {
|
||||
if err := recover(); err != nil {
|
||||
if v, ok := err.(antlr.RecognitionException); ok {
|
||||
localctx.SetException(v)
|
||||
p.GetErrorHandler().ReportError(p, v)
|
||||
p.GetErrorHandler().Recover(p, v)
|
||||
} else {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
p.EnterOuterAlt(localctx, 1)
|
||||
{
|
||||
p.SetState(287)
|
||||
p.Match(ApiParserParserATHANDLER)
|
||||
}
|
||||
{
|
||||
p.SetState(288)
|
||||
p.Match(ApiParserParserID)
|
||||
}
|
||||
|
||||
return localctx
|
||||
}
|
||||
|
||||
// IRouteContext is an interface to support dynamic dispatch.
|
||||
type IRouteContext interface {
|
||||
antlr.ParserRuleContext
|
||||
|
||||
// GetParser returns the parser.
|
||||
GetParser() antlr.Parser
|
||||
|
||||
// GetHttpMethod returns the httpMethod token.
|
||||
GetHttpMethod() antlr.Token
|
||||
|
||||
// GetReturnToken returns the returnToken token.
|
||||
GetReturnToken() antlr.Token
|
||||
|
||||
// SetHttpMethod sets the httpMethod token.
|
||||
SetHttpMethod(antlr.Token)
|
||||
|
||||
// SetReturnToken sets the returnToken token.
|
||||
SetReturnToken(antlr.Token)
|
||||
|
||||
// GetRequest returns the request rule contexts.
|
||||
GetRequest() IBodyContext
|
||||
|
||||
// GetResponse returns the response rule contexts.
|
||||
GetResponse() IReplybodyContext
|
||||
|
||||
// SetRequest sets the request rule contexts.
|
||||
SetRequest(IBodyContext)
|
||||
|
||||
// SetResponse sets the response rule contexts.
|
||||
SetResponse(IReplybodyContext)
|
||||
|
||||
// IsRouteContext differentiates from other interfaces.
|
||||
IsRouteContext()
|
||||
}
|
||||
|
||||
type RouteContext struct {
|
||||
*antlr.BaseParserRuleContext
|
||||
parser antlr.Parser
|
||||
httpMethod antlr.Token
|
||||
request IBodyContext
|
||||
returnToken antlr.Token
|
||||
response IReplybodyContext
|
||||
}
|
||||
|
||||
func NewEmptyRouteContext() *RouteContext {
|
||||
var p = new(RouteContext)
|
||||
p.BaseParserRuleContext = antlr.NewBaseParserRuleContext(nil, -1)
|
||||
p.RuleIndex = ApiParserParserRULE_route
|
||||
return p
|
||||
}
|
||||
|
||||
func (*RouteContext) IsRouteContext() {}
|
||||
|
||||
func NewRouteContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *RouteContext {
|
||||
var p = new(RouteContext)
|
||||
|
||||
p.BaseParserRuleContext = antlr.NewBaseParserRuleContext(parent, invokingState)
|
||||
|
||||
p.parser = parser
|
||||
p.RuleIndex = ApiParserParserRULE_route
|
||||
|
||||
return p
|
||||
}
|
||||
|
||||
func (s *RouteContext) GetParser() antlr.Parser { return s.parser }
|
||||
|
||||
func (s *RouteContext) GetHttpMethod() antlr.Token { return s.httpMethod }
|
||||
|
||||
func (s *RouteContext) GetReturnToken() antlr.Token { return s.returnToken }
|
||||
|
||||
func (s *RouteContext) SetHttpMethod(v antlr.Token) { s.httpMethod = v }
|
||||
|
||||
func (s *RouteContext) SetReturnToken(v antlr.Token) { s.returnToken = v }
|
||||
|
||||
func (s *RouteContext) GetRequest() IBodyContext { return s.request }
|
||||
|
||||
func (s *RouteContext) GetResponse() IReplybodyContext { return s.response }
|
||||
|
||||
func (s *RouteContext) SetRequest(v IBodyContext) { s.request = v }
|
||||
|
||||
func (s *RouteContext) SetResponse(v IReplybodyContext) { s.response = v }
|
||||
|
||||
func (s *RouteContext) Path() IPathContext {
|
||||
var t = s.GetTypedRuleContext(reflect.TypeOf((*IPathContext)(nil)).Elem(), 0)
|
||||
|
||||
if t == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
return t.(IPathContext)
|
||||
}
|
||||
|
||||
func (s *RouteContext) AllID() []antlr.TerminalNode {
|
||||
return s.GetTokens(ApiParserParserID)
|
||||
}
|
||||
|
||||
func (s *RouteContext) ID(i int) antlr.TerminalNode {
|
||||
return s.GetToken(ApiParserParserID, i)
|
||||
}
|
||||
|
||||
func (s *RouteContext) Body() IBodyContext {
|
||||
var t = s.GetTypedRuleContext(reflect.TypeOf((*IBodyContext)(nil)).Elem(), 0)
|
||||
|
||||
if t == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
return t.(IBodyContext)
|
||||
}
|
||||
|
||||
func (s *RouteContext) Replybody() IReplybodyContext {
|
||||
var t = s.GetTypedRuleContext(reflect.TypeOf((*IReplybodyContext)(nil)).Elem(), 0)
|
||||
|
||||
if t == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
return t.(IReplybodyContext)
|
||||
}
|
||||
|
||||
func (s *RouteContext) GetRuleContext() antlr.RuleContext {
|
||||
return s
|
||||
}
|
||||
|
||||
func (s *RouteContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string {
|
||||
return antlr.TreesStringTree(s, ruleNames, recog)
|
||||
}
|
||||
|
||||
func (s *RouteContext) Accept(visitor antlr.ParseTreeVisitor) interface{} {
|
||||
switch t := visitor.(type) {
|
||||
case ApiParserVisitor:
|
||||
return t.VisitRoute(s)
|
||||
|
||||
default:
|
||||
return t.VisitChildren(s)
|
||||
}
|
||||
}
|
||||
|
||||
func (p *ApiParserParser) Route() (localctx IRouteContext) {
|
||||
localctx = NewRouteContext(p, p.GetParserRuleContext(), p.GetState())
|
||||
p.EnterRule(localctx, 62, ApiParserParserRULE_route)
|
||||
var _la int
|
||||
|
||||
defer func() {
|
||||
p.ExitRule()
|
||||
}()
|
||||
|
||||
defer func() {
|
||||
if err := recover(); err != nil {
|
||||
if v, ok := err.(antlr.RecognitionException); ok {
|
||||
localctx.SetException(v)
|
||||
p.GetErrorHandler().ReportError(p, v)
|
||||
p.GetErrorHandler().Recover(p, v)
|
||||
} else {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
p.EnterOuterAlt(localctx, 1)
|
||||
checkHTTPMethod(p)
|
||||
{
|
||||
p.SetState(291)
|
||||
|
||||
var _m = p.Match(ApiParserParserID)
|
||||
|
||||
localctx.(*RouteContext).httpMethod = _m
|
||||
}
|
||||
{
|
||||
p.SetState(292)
|
||||
p.Path()
|
||||
}
|
||||
p.SetState(294)
|
||||
p.GetErrorHandler().Sync(p)
|
||||
|
||||
if p.GetInterpreter().AdaptivePredict(p.GetTokenStream(), 28, p.GetParserRuleContext()) == 1 {
|
||||
{
|
||||
p.SetState(293)
|
||||
|
||||
var _x = p.Body()
|
||||
|
||||
localctx.(*RouteContext).request = _x
|
||||
}
|
||||
|
||||
}
|
||||
p.SetState(297)
|
||||
p.GetErrorHandler().Sync(p)
|
||||
_la = p.GetTokenStream().LA(1)
|
||||
|
||||
if _la == ApiParserParserID {
|
||||
{
|
||||
p.SetState(296)
|
||||
|
||||
var _m = p.Match(ApiParserParserID)
|
||||
|
||||
localctx.(*RouteContext).returnToken = _m
|
||||
}
|
||||
|
||||
}
|
||||
p.SetState(300)
|
||||
p.GetErrorHandler().Sync(p)
|
||||
_la = p.GetTokenStream().LA(1)
|
||||
|
||||
if _la == ApiParserParserT__1 {
|
||||
{
|
||||
p.SetState(299)
|
||||
|
||||
var _x = p.Replybody()
|
||||
|
||||
localctx.(*RouteContext).response = _x
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return localctx
|
||||
}
|
||||
697
tools/goctl/api/parser/g4/gen/api/apiparser_parser8.go
Executable file
697
tools/goctl/api/parser/g4/gen/api/apiparser_parser8.go
Executable file
@@ -0,0 +1,697 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
|
||||
"github.com/zeromicro/antlr"
|
||||
)
|
||||
|
||||
// Part 8
|
||||
// The apiparser_parser.go file was split into multiple files because it
|
||||
// was too large and caused a possible memory overflow during goctl installation.
|
||||
|
||||
// IBodyContext is an interface to support dynamic dispatch.
|
||||
type IBodyContext interface {
|
||||
antlr.ParserRuleContext
|
||||
|
||||
// GetParser returns the parser.
|
||||
GetParser() antlr.Parser
|
||||
|
||||
// GetLp returns the lp token.
|
||||
GetLp() antlr.Token
|
||||
|
||||
// GetRp returns the rp token.
|
||||
GetRp() antlr.Token
|
||||
|
||||
// SetLp sets the lp token.
|
||||
SetLp(antlr.Token)
|
||||
|
||||
// SetRp sets the rp token.
|
||||
SetRp(antlr.Token)
|
||||
|
||||
// IsBodyContext differentiates from other interfaces.
|
||||
IsBodyContext()
|
||||
}
|
||||
|
||||
type BodyContext struct {
|
||||
*antlr.BaseParserRuleContext
|
||||
parser antlr.Parser
|
||||
lp antlr.Token
|
||||
rp antlr.Token
|
||||
}
|
||||
|
||||
func NewEmptyBodyContext() *BodyContext {
|
||||
var p = new(BodyContext)
|
||||
p.BaseParserRuleContext = antlr.NewBaseParserRuleContext(nil, -1)
|
||||
p.RuleIndex = ApiParserParserRULE_body
|
||||
return p
|
||||
}
|
||||
|
||||
func (*BodyContext) IsBodyContext() {}
|
||||
|
||||
func NewBodyContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *BodyContext {
|
||||
var p = new(BodyContext)
|
||||
|
||||
p.BaseParserRuleContext = antlr.NewBaseParserRuleContext(parent, invokingState)
|
||||
|
||||
p.parser = parser
|
||||
p.RuleIndex = ApiParserParserRULE_body
|
||||
|
||||
return p
|
||||
}
|
||||
|
||||
func (s *BodyContext) GetParser() antlr.Parser { return s.parser }
|
||||
|
||||
func (s *BodyContext) GetLp() antlr.Token { return s.lp }
|
||||
|
||||
func (s *BodyContext) GetRp() antlr.Token { return s.rp }
|
||||
|
||||
func (s *BodyContext) SetLp(v antlr.Token) { s.lp = v }
|
||||
|
||||
func (s *BodyContext) SetRp(v antlr.Token) { s.rp = v }
|
||||
|
||||
func (s *BodyContext) ID() antlr.TerminalNode {
|
||||
return s.GetToken(ApiParserParserID, 0)
|
||||
}
|
||||
|
||||
func (s *BodyContext) GetRuleContext() antlr.RuleContext {
|
||||
return s
|
||||
}
|
||||
|
||||
func (s *BodyContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string {
|
||||
return antlr.TreesStringTree(s, ruleNames, recog)
|
||||
}
|
||||
|
||||
func (s *BodyContext) Accept(visitor antlr.ParseTreeVisitor) interface{} {
|
||||
switch t := visitor.(type) {
|
||||
case ApiParserVisitor:
|
||||
return t.VisitBody(s)
|
||||
|
||||
default:
|
||||
return t.VisitChildren(s)
|
||||
}
|
||||
}
|
||||
|
||||
func (p *ApiParserParser) Body() (localctx IBodyContext) {
|
||||
localctx = NewBodyContext(p, p.GetParserRuleContext(), p.GetState())
|
||||
p.EnterRule(localctx, 64, ApiParserParserRULE_body)
|
||||
var _la int
|
||||
|
||||
defer func() {
|
||||
p.ExitRule()
|
||||
}()
|
||||
|
||||
defer func() {
|
||||
if err := recover(); err != nil {
|
||||
if v, ok := err.(antlr.RecognitionException); ok {
|
||||
localctx.SetException(v)
|
||||
p.GetErrorHandler().ReportError(p, v)
|
||||
p.GetErrorHandler().Recover(p, v)
|
||||
} else {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
p.EnterOuterAlt(localctx, 1)
|
||||
{
|
||||
p.SetState(302)
|
||||
|
||||
var _m = p.Match(ApiParserParserT__1)
|
||||
|
||||
localctx.(*BodyContext).lp = _m
|
||||
}
|
||||
p.SetState(304)
|
||||
p.GetErrorHandler().Sync(p)
|
||||
_la = p.GetTokenStream().LA(1)
|
||||
|
||||
if _la == ApiParserParserID {
|
||||
{
|
||||
p.SetState(303)
|
||||
p.Match(ApiParserParserID)
|
||||
}
|
||||
|
||||
}
|
||||
{
|
||||
p.SetState(306)
|
||||
|
||||
var _m = p.Match(ApiParserParserT__2)
|
||||
|
||||
localctx.(*BodyContext).rp = _m
|
||||
}
|
||||
|
||||
return localctx
|
||||
}
|
||||
|
||||
// IReplybodyContext is an interface to support dynamic dispatch.
|
||||
type IReplybodyContext interface {
|
||||
antlr.ParserRuleContext
|
||||
|
||||
// GetParser returns the parser.
|
||||
GetParser() antlr.Parser
|
||||
|
||||
// GetLp returns the lp token.
|
||||
GetLp() antlr.Token
|
||||
|
||||
// GetRp returns the rp token.
|
||||
GetRp() antlr.Token
|
||||
|
||||
// SetLp sets the lp token.
|
||||
SetLp(antlr.Token)
|
||||
|
||||
// SetRp sets the rp token.
|
||||
SetRp(antlr.Token)
|
||||
|
||||
// IsReplybodyContext differentiates from other interfaces.
|
||||
IsReplybodyContext()
|
||||
}
|
||||
|
||||
type ReplybodyContext struct {
|
||||
*antlr.BaseParserRuleContext
|
||||
parser antlr.Parser
|
||||
lp antlr.Token
|
||||
rp antlr.Token
|
||||
}
|
||||
|
||||
func NewEmptyReplybodyContext() *ReplybodyContext {
|
||||
var p = new(ReplybodyContext)
|
||||
p.BaseParserRuleContext = antlr.NewBaseParserRuleContext(nil, -1)
|
||||
p.RuleIndex = ApiParserParserRULE_replybody
|
||||
return p
|
||||
}
|
||||
|
||||
func (*ReplybodyContext) IsReplybodyContext() {}
|
||||
|
||||
func NewReplybodyContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *ReplybodyContext {
|
||||
var p = new(ReplybodyContext)
|
||||
|
||||
p.BaseParserRuleContext = antlr.NewBaseParserRuleContext(parent, invokingState)
|
||||
|
||||
p.parser = parser
|
||||
p.RuleIndex = ApiParserParserRULE_replybody
|
||||
|
||||
return p
|
||||
}
|
||||
|
||||
func (s *ReplybodyContext) GetParser() antlr.Parser { return s.parser }
|
||||
|
||||
func (s *ReplybodyContext) GetLp() antlr.Token { return s.lp }
|
||||
|
||||
func (s *ReplybodyContext) GetRp() antlr.Token { return s.rp }
|
||||
|
||||
func (s *ReplybodyContext) SetLp(v antlr.Token) { s.lp = v }
|
||||
|
||||
func (s *ReplybodyContext) SetRp(v antlr.Token) { s.rp = v }
|
||||
|
||||
func (s *ReplybodyContext) DataType() IDataTypeContext {
|
||||
var t = s.GetTypedRuleContext(reflect.TypeOf((*IDataTypeContext)(nil)).Elem(), 0)
|
||||
|
||||
if t == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
return t.(IDataTypeContext)
|
||||
}
|
||||
|
||||
func (s *ReplybodyContext) GetRuleContext() antlr.RuleContext {
|
||||
return s
|
||||
}
|
||||
|
||||
func (s *ReplybodyContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string {
|
||||
return antlr.TreesStringTree(s, ruleNames, recog)
|
||||
}
|
||||
|
||||
func (s *ReplybodyContext) Accept(visitor antlr.ParseTreeVisitor) interface{} {
|
||||
switch t := visitor.(type) {
|
||||
case ApiParserVisitor:
|
||||
return t.VisitReplybody(s)
|
||||
|
||||
default:
|
||||
return t.VisitChildren(s)
|
||||
}
|
||||
}
|
||||
|
||||
func (p *ApiParserParser) Replybody() (localctx IReplybodyContext) {
|
||||
localctx = NewReplybodyContext(p, p.GetParserRuleContext(), p.GetState())
|
||||
p.EnterRule(localctx, 66, ApiParserParserRULE_replybody)
|
||||
var _la int
|
||||
|
||||
defer func() {
|
||||
p.ExitRule()
|
||||
}()
|
||||
|
||||
defer func() {
|
||||
if err := recover(); err != nil {
|
||||
if v, ok := err.(antlr.RecognitionException); ok {
|
||||
localctx.SetException(v)
|
||||
p.GetErrorHandler().ReportError(p, v)
|
||||
p.GetErrorHandler().Recover(p, v)
|
||||
} else {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
p.EnterOuterAlt(localctx, 1)
|
||||
{
|
||||
p.SetState(308)
|
||||
|
||||
var _m = p.Match(ApiParserParserT__1)
|
||||
|
||||
localctx.(*ReplybodyContext).lp = _m
|
||||
}
|
||||
p.SetState(310)
|
||||
p.GetErrorHandler().Sync(p)
|
||||
_la = p.GetTokenStream().LA(1)
|
||||
|
||||
if ((_la)&-(0x1f+1)) == 0 && ((1<<uint(_la))&((1<<ApiParserParserT__5)|(1<<ApiParserParserT__6)|(1<<ApiParserParserT__7)|(1<<ApiParserParserINTERFACE)|(1<<ApiParserParserID))) != 0 {
|
||||
{
|
||||
p.SetState(309)
|
||||
p.DataType()
|
||||
}
|
||||
|
||||
}
|
||||
{
|
||||
p.SetState(312)
|
||||
|
||||
var _m = p.Match(ApiParserParserT__2)
|
||||
|
||||
localctx.(*ReplybodyContext).rp = _m
|
||||
}
|
||||
|
||||
return localctx
|
||||
}
|
||||
|
||||
// IKvLitContext is an interface to support dynamic dispatch.
|
||||
type IKvLitContext interface {
|
||||
antlr.ParserRuleContext
|
||||
|
||||
// GetParser returns the parser.
|
||||
GetParser() antlr.Parser
|
||||
|
||||
// GetKey returns the key token.
|
||||
GetKey() antlr.Token
|
||||
|
||||
// GetValue returns the value token.
|
||||
GetValue() antlr.Token
|
||||
|
||||
// SetKey sets the key token.
|
||||
SetKey(antlr.Token)
|
||||
|
||||
// SetValue sets the value token.
|
||||
SetValue(antlr.Token)
|
||||
|
||||
// IsKvLitContext differentiates from other interfaces.
|
||||
IsKvLitContext()
|
||||
}
|
||||
|
||||
type KvLitContext struct {
|
||||
*antlr.BaseParserRuleContext
|
||||
parser antlr.Parser
|
||||
key antlr.Token
|
||||
value antlr.Token
|
||||
}
|
||||
|
||||
func NewEmptyKvLitContext() *KvLitContext {
|
||||
var p = new(KvLitContext)
|
||||
p.BaseParserRuleContext = antlr.NewBaseParserRuleContext(nil, -1)
|
||||
p.RuleIndex = ApiParserParserRULE_kvLit
|
||||
return p
|
||||
}
|
||||
|
||||
func (*KvLitContext) IsKvLitContext() {}
|
||||
|
||||
func NewKvLitContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *KvLitContext {
|
||||
var p = new(KvLitContext)
|
||||
|
||||
p.BaseParserRuleContext = antlr.NewBaseParserRuleContext(parent, invokingState)
|
||||
|
||||
p.parser = parser
|
||||
p.RuleIndex = ApiParserParserRULE_kvLit
|
||||
|
||||
return p
|
||||
}
|
||||
|
||||
func (s *KvLitContext) GetParser() antlr.Parser { return s.parser }
|
||||
|
||||
func (s *KvLitContext) GetKey() antlr.Token { return s.key }
|
||||
|
||||
func (s *KvLitContext) GetValue() antlr.Token { return s.value }
|
||||
|
||||
func (s *KvLitContext) SetKey(v antlr.Token) { s.key = v }
|
||||
|
||||
func (s *KvLitContext) SetValue(v antlr.Token) { s.value = v }
|
||||
|
||||
func (s *KvLitContext) ID() antlr.TerminalNode {
|
||||
return s.GetToken(ApiParserParserID, 0)
|
||||
}
|
||||
|
||||
func (s *KvLitContext) LINE_VALUE() antlr.TerminalNode {
|
||||
return s.GetToken(ApiParserParserLINE_VALUE, 0)
|
||||
}
|
||||
|
||||
func (s *KvLitContext) GetRuleContext() antlr.RuleContext {
|
||||
return s
|
||||
}
|
||||
|
||||
func (s *KvLitContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string {
|
||||
return antlr.TreesStringTree(s, ruleNames, recog)
|
||||
}
|
||||
|
||||
func (s *KvLitContext) Accept(visitor antlr.ParseTreeVisitor) interface{} {
|
||||
switch t := visitor.(type) {
|
||||
case ApiParserVisitor:
|
||||
return t.VisitKvLit(s)
|
||||
|
||||
default:
|
||||
return t.VisitChildren(s)
|
||||
}
|
||||
}
|
||||
|
||||
func (p *ApiParserParser) KvLit() (localctx IKvLitContext) {
|
||||
localctx = NewKvLitContext(p, p.GetParserRuleContext(), p.GetState())
|
||||
p.EnterRule(localctx, 68, ApiParserParserRULE_kvLit)
|
||||
|
||||
defer func() {
|
||||
p.ExitRule()
|
||||
}()
|
||||
|
||||
defer func() {
|
||||
if err := recover(); err != nil {
|
||||
if v, ok := err.(antlr.RecognitionException); ok {
|
||||
localctx.SetException(v)
|
||||
p.GetErrorHandler().ReportError(p, v)
|
||||
p.GetErrorHandler().Recover(p, v)
|
||||
} else {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
p.EnterOuterAlt(localctx, 1)
|
||||
{
|
||||
p.SetState(314)
|
||||
|
||||
var _m = p.Match(ApiParserParserID)
|
||||
|
||||
localctx.(*KvLitContext).key = _m
|
||||
}
|
||||
checkKeyValue(p)
|
||||
{
|
||||
p.SetState(316)
|
||||
|
||||
var _m = p.Match(ApiParserParserLINE_VALUE)
|
||||
|
||||
localctx.(*KvLitContext).value = _m
|
||||
}
|
||||
|
||||
return localctx
|
||||
}
|
||||
|
||||
// IServiceNameContext is an interface to support dynamic dispatch.
|
||||
type IServiceNameContext interface {
|
||||
antlr.ParserRuleContext
|
||||
|
||||
// GetParser returns the parser.
|
||||
GetParser() antlr.Parser
|
||||
|
||||
// IsServiceNameContext differentiates from other interfaces.
|
||||
IsServiceNameContext()
|
||||
}
|
||||
|
||||
type ServiceNameContext struct {
|
||||
*antlr.BaseParserRuleContext
|
||||
parser antlr.Parser
|
||||
}
|
||||
|
||||
func NewEmptyServiceNameContext() *ServiceNameContext {
|
||||
var p = new(ServiceNameContext)
|
||||
p.BaseParserRuleContext = antlr.NewBaseParserRuleContext(nil, -1)
|
||||
p.RuleIndex = ApiParserParserRULE_serviceName
|
||||
return p
|
||||
}
|
||||
|
||||
func (*ServiceNameContext) IsServiceNameContext() {}
|
||||
|
||||
func NewServiceNameContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *ServiceNameContext {
|
||||
var p = new(ServiceNameContext)
|
||||
|
||||
p.BaseParserRuleContext = antlr.NewBaseParserRuleContext(parent, invokingState)
|
||||
|
||||
p.parser = parser
|
||||
p.RuleIndex = ApiParserParserRULE_serviceName
|
||||
|
||||
return p
|
||||
}
|
||||
|
||||
func (s *ServiceNameContext) GetParser() antlr.Parser { return s.parser }
|
||||
|
||||
func (s *ServiceNameContext) AllID() []antlr.TerminalNode {
|
||||
return s.GetTokens(ApiParserParserID)
|
||||
}
|
||||
|
||||
func (s *ServiceNameContext) ID(i int) antlr.TerminalNode {
|
||||
return s.GetToken(ApiParserParserID, i)
|
||||
}
|
||||
|
||||
func (s *ServiceNameContext) GetRuleContext() antlr.RuleContext {
|
||||
return s
|
||||
}
|
||||
|
||||
func (s *ServiceNameContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string {
|
||||
return antlr.TreesStringTree(s, ruleNames, recog)
|
||||
}
|
||||
|
||||
func (s *ServiceNameContext) Accept(visitor antlr.ParseTreeVisitor) interface{} {
|
||||
switch t := visitor.(type) {
|
||||
case ApiParserVisitor:
|
||||
return t.VisitServiceName(s)
|
||||
|
||||
default:
|
||||
return t.VisitChildren(s)
|
||||
}
|
||||
}
|
||||
|
||||
func (p *ApiParserParser) ServiceName() (localctx IServiceNameContext) {
|
||||
localctx = NewServiceNameContext(p, p.GetParserRuleContext(), p.GetState())
|
||||
p.EnterRule(localctx, 70, ApiParserParserRULE_serviceName)
|
||||
var _la int
|
||||
|
||||
defer func() {
|
||||
p.ExitRule()
|
||||
}()
|
||||
|
||||
defer func() {
|
||||
if err := recover(); err != nil {
|
||||
if v, ok := err.(antlr.RecognitionException); ok {
|
||||
localctx.SetException(v)
|
||||
p.GetErrorHandler().ReportError(p, v)
|
||||
p.GetErrorHandler().Recover(p, v)
|
||||
} else {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
p.EnterOuterAlt(localctx, 1)
|
||||
p.SetState(322)
|
||||
p.GetErrorHandler().Sync(p)
|
||||
|
||||
for ok := true; ok; ok = _la == ApiParserParserID {
|
||||
{
|
||||
p.SetState(318)
|
||||
p.Match(ApiParserParserID)
|
||||
}
|
||||
p.SetState(320)
|
||||
p.GetErrorHandler().Sync(p)
|
||||
_la = p.GetTokenStream().LA(1)
|
||||
|
||||
if _la == ApiParserParserT__9 {
|
||||
{
|
||||
p.SetState(319)
|
||||
p.Match(ApiParserParserT__9)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
p.SetState(324)
|
||||
p.GetErrorHandler().Sync(p)
|
||||
_la = p.GetTokenStream().LA(1)
|
||||
}
|
||||
|
||||
return localctx
|
||||
}
|
||||
|
||||
// IPathContext is an interface to support dynamic dispatch.
|
||||
type IPathContext interface {
|
||||
antlr.ParserRuleContext
|
||||
|
||||
// GetParser returns the parser.
|
||||
GetParser() antlr.Parser
|
||||
|
||||
// IsPathContext differentiates from other interfaces.
|
||||
IsPathContext()
|
||||
}
|
||||
|
||||
type PathContext struct {
|
||||
*antlr.BaseParserRuleContext
|
||||
parser antlr.Parser
|
||||
}
|
||||
|
||||
func NewEmptyPathContext() *PathContext {
|
||||
var p = new(PathContext)
|
||||
p.BaseParserRuleContext = antlr.NewBaseParserRuleContext(nil, -1)
|
||||
p.RuleIndex = ApiParserParserRULE_path
|
||||
return p
|
||||
}
|
||||
|
||||
func (*PathContext) IsPathContext() {}
|
||||
|
||||
func NewPathContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *PathContext {
|
||||
var p = new(PathContext)
|
||||
|
||||
p.BaseParserRuleContext = antlr.NewBaseParserRuleContext(parent, invokingState)
|
||||
|
||||
p.parser = parser
|
||||
p.RuleIndex = ApiParserParserRULE_path
|
||||
|
||||
return p
|
||||
}
|
||||
|
||||
func (s *PathContext) GetParser() antlr.Parser { return s.parser }
|
||||
|
||||
func (s *PathContext) AllID() []antlr.TerminalNode {
|
||||
return s.GetTokens(ApiParserParserID)
|
||||
}
|
||||
|
||||
func (s *PathContext) ID(i int) antlr.TerminalNode {
|
||||
return s.GetToken(ApiParserParserID, i)
|
||||
}
|
||||
|
||||
func (s *PathContext) GetRuleContext() antlr.RuleContext {
|
||||
return s
|
||||
}
|
||||
|
||||
func (s *PathContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string {
|
||||
return antlr.TreesStringTree(s, ruleNames, recog)
|
||||
}
|
||||
|
||||
func (s *PathContext) Accept(visitor antlr.ParseTreeVisitor) interface{} {
|
||||
switch t := visitor.(type) {
|
||||
case ApiParserVisitor:
|
||||
return t.VisitPath(s)
|
||||
|
||||
default:
|
||||
return t.VisitChildren(s)
|
||||
}
|
||||
}
|
||||
|
||||
func (p *ApiParserParser) Path() (localctx IPathContext) {
|
||||
localctx = NewPathContext(p, p.GetParserRuleContext(), p.GetState())
|
||||
p.EnterRule(localctx, 72, ApiParserParserRULE_path)
|
||||
var _la int
|
||||
|
||||
defer func() {
|
||||
p.ExitRule()
|
||||
}()
|
||||
|
||||
defer func() {
|
||||
if err := recover(); err != nil {
|
||||
if v, ok := err.(antlr.RecognitionException); ok {
|
||||
localctx.SetException(v)
|
||||
p.GetErrorHandler().ReportError(p, v)
|
||||
p.GetErrorHandler().Recover(p, v)
|
||||
} else {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
p.SetState(346)
|
||||
p.GetErrorHandler().Sync(p)
|
||||
switch p.GetInterpreter().AdaptivePredict(p.GetTokenStream(), 39, p.GetParserRuleContext()) {
|
||||
case 1:
|
||||
p.EnterOuterAlt(localctx, 1)
|
||||
p.SetState(341)
|
||||
p.GetErrorHandler().Sync(p)
|
||||
|
||||
for ok := true; ok; ok = _la == ApiParserParserT__10 || _la == ApiParserParserT__11 {
|
||||
p.SetState(341)
|
||||
p.GetErrorHandler().Sync(p)
|
||||
|
||||
switch p.GetTokenStream().LA(1) {
|
||||
case ApiParserParserT__10:
|
||||
{
|
||||
p.SetState(326)
|
||||
p.Match(ApiParserParserT__10)
|
||||
}
|
||||
|
||||
{
|
||||
p.SetState(327)
|
||||
p.Match(ApiParserParserID)
|
||||
}
|
||||
p.SetState(332)
|
||||
p.GetErrorHandler().Sync(p)
|
||||
_la = p.GetTokenStream().LA(1)
|
||||
|
||||
for _la == ApiParserParserT__9 {
|
||||
{
|
||||
p.SetState(328)
|
||||
p.Match(ApiParserParserT__9)
|
||||
}
|
||||
{
|
||||
p.SetState(329)
|
||||
p.Match(ApiParserParserID)
|
||||
}
|
||||
|
||||
p.SetState(334)
|
||||
p.GetErrorHandler().Sync(p)
|
||||
_la = p.GetTokenStream().LA(1)
|
||||
}
|
||||
|
||||
case ApiParserParserT__11:
|
||||
{
|
||||
p.SetState(335)
|
||||
p.Match(ApiParserParserT__11)
|
||||
}
|
||||
|
||||
{
|
||||
p.SetState(336)
|
||||
p.Match(ApiParserParserID)
|
||||
}
|
||||
p.SetState(339)
|
||||
p.GetErrorHandler().Sync(p)
|
||||
_la = p.GetTokenStream().LA(1)
|
||||
|
||||
if _la == ApiParserParserT__9 {
|
||||
{
|
||||
p.SetState(337)
|
||||
p.Match(ApiParserParserT__9)
|
||||
}
|
||||
{
|
||||
p.SetState(338)
|
||||
p.Match(ApiParserParserID)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
default:
|
||||
panic(antlr.NewNoViableAltException(p, nil, nil, nil, nil, nil))
|
||||
}
|
||||
|
||||
p.SetState(343)
|
||||
p.GetErrorHandler().Sync(p)
|
||||
_la = p.GetTokenStream().LA(1)
|
||||
}
|
||||
|
||||
case 2:
|
||||
p.EnterOuterAlt(localctx, 2)
|
||||
{
|
||||
p.SetState(345)
|
||||
p.Match(ApiParserParserT__10)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return localctx
|
||||
}
|
||||
35
tools/goctl/api/parser/g4/gen/api/apiparser_parser9.go
Executable file
35
tools/goctl/api/parser/g4/gen/api/apiparser_parser9.go
Executable file
@@ -0,0 +1,35 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/zeromicro/antlr"
|
||||
)
|
||||
|
||||
// Part 9
|
||||
// The apiparser_parser.go file was split into multiple files because it
|
||||
// was too large and caused a possible memory overflow during goctl installation.
|
||||
|
||||
func (p *ApiParserParser) Sempred(localctx antlr.RuleContext, ruleIndex, predIndex int) bool {
|
||||
switch ruleIndex {
|
||||
case 18:
|
||||
var t *FieldContext = nil
|
||||
if localctx != nil {
|
||||
t = localctx.(*FieldContext)
|
||||
}
|
||||
return p.Field_Sempred(t, predIndex)
|
||||
|
||||
default:
|
||||
panic("No predicate with index: " + fmt.Sprint(ruleIndex))
|
||||
}
|
||||
}
|
||||
|
||||
func (p *ApiParserParser) Field_Sempred(localctx antlr.RuleContext, predIndex int) bool {
|
||||
switch predIndex {
|
||||
case 0:
|
||||
return isNormal(p)
|
||||
|
||||
default:
|
||||
panic("No predicate with index: " + fmt.Sprint(predIndex))
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,3 @@
|
||||
// Code generated from tools/goctl/api/parser/g4/ApiParser.g4 by ANTLR 4.9. DO NOT EDIT.
|
||||
|
||||
package api // ApiParser
|
||||
import "github.com/zeromicro/antlr"
|
||||
|
||||
|
||||
79
tools/goctl/api/parser/g4/gen/api/file_splitor_test.go
Normal file
79
tools/goctl/api/parser/g4/gen/api/file_splitor_test.go
Normal file
@@ -0,0 +1,79 @@
|
||||
// DO NOT EDIT.
|
||||
// Tool: split apiparser_parser.go
|
||||
// The apiparser_parser.go file was split into multiple files because it
|
||||
// was too large and caused a possible memory overflow during goctl installation.
|
||||
package api
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"bytes"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestFileSplitor(t *testing.T) {
|
||||
dir := "."
|
||||
data, err := ioutil.ReadFile(filepath.Join(dir, "apiparser_parser.go"))
|
||||
if err != nil {
|
||||
log.Fatalln(err)
|
||||
}
|
||||
|
||||
r := bytes.NewReader(data)
|
||||
reader := bufio.NewReader(r)
|
||||
var lines, files int
|
||||
buffer := bytes.NewBuffer(nil)
|
||||
|
||||
for {
|
||||
var fn, part = "apiparser_parser0.go", "main"
|
||||
if files > 0 {
|
||||
fn = fmt.Sprintf("apiparser_parser%d.go", files)
|
||||
part = fmt.Sprintf("%d", files)
|
||||
}
|
||||
fp := filepath.Join(dir, fn)
|
||||
buffer.Reset()
|
||||
if files > 0 {
|
||||
buffer.WriteString(fmt.Sprintf(`package api
|
||||
import "github.com/zeromicro/antlr"
|
||||
|
||||
// Part %s
|
||||
// The apiparser_parser.go file was split into multiple files because it
|
||||
// was too large and caused a possible memory overflow during goctl installation.
|
||||
`, part))
|
||||
}
|
||||
|
||||
var exit bool
|
||||
for {
|
||||
line, _, err := reader.ReadLine()
|
||||
buffer.Write(line)
|
||||
buffer.WriteRune('\n')
|
||||
if err != nil {
|
||||
fmt.Printf("%+v\n", err)
|
||||
exit = true
|
||||
break
|
||||
}
|
||||
lines += 1
|
||||
if string(line) == "}" && lines >= 650 {
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
err = ioutil.WriteFile(fp, buffer.Bytes(), os.ModePerm)
|
||||
if err != nil {
|
||||
fmt.Printf("%+v\n", err)
|
||||
}
|
||||
if exit {
|
||||
break
|
||||
}
|
||||
lines = 0
|
||||
files += 1
|
||||
}
|
||||
|
||||
err = os.Rename(filepath.Join(dir, "apiparser_parser0.go"), filepath.Join(dir, "apiparser_parser.go"))
|
||||
if err != nil {
|
||||
log.Fatalln(err)
|
||||
}
|
||||
}
|
||||
@@ -174,7 +174,7 @@ func TestRoute(t *testing.T) {
|
||||
assert.Error(t, err)
|
||||
|
||||
_, err = parser.Accept(fn, ` post /foo/bar returns (int)`)
|
||||
assert.Error(t, err)
|
||||
assert.Nil(t, err)
|
||||
|
||||
_, err = parser.Accept(fn, ` post /foo/bar returns (*int)`)
|
||||
assert.Error(t, err)
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user