Skip to content

Commit 1ba743c

Browse files
committed
add 添加antlr的类sql的规则
1 parent 27b24b9 commit 1ba743c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+4067
-323
lines changed

go-learn

11.5 MB
Binary file not shown.

go.mod

+33-23
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,47 @@
11
module go-learn
22

3-
go 1.18
3+
go 1.22
4+
5+
toolchain go1.22.4
46

57
require (
8+
github.com/antlr4-go/antlr/v4 v4.13.1
69
github.com/eclipse/paho.mqtt.golang v1.3.5
7-
github.com/gin-gonic/gin v1.7.7
10+
github.com/gin-gonic/gin v1.8.1
811
github.com/go-eden/routine v0.0.3
9-
github.com/go-redis/redis/v8 v8.11.4
12+
github.com/go-redis/redis/v8 v8.11.5
1013
github.com/go-sql-driver/mysql v1.6.0
1114
github.com/go-xorm/xorm v0.7.9
1215
github.com/goburrow/cache v0.1.4
16+
github.com/isyscore/isc-gobase v1.4.13
1317
github.com/lunny/log v0.0.0-20160921050905-7887c61bf0de
1418
github.com/magiconair/properties v1.8.5
15-
github.com/nats-io/nats.go v1.13.1-0.20211122170419-d7c1d78a50fc
19+
github.com/nats-io/nats.go v1.36.0
1620
github.com/nsqio/go-nsq v1.1.0
1721
github.com/robfig/cron v1.2.0
1822
github.com/satori/go.uuid v1.2.0
1923
github.com/simonalong/gole v1.0.2
2024
github.com/simonalong/mikilin-go v1.0.2-0.20211208074724-b25f05b74f31
2125
github.com/sirupsen/logrus v1.8.1
22-
go.etcd.io/etcd/client/v3 v3.5.3
26+
go.etcd.io/etcd/client/v3 v3.5.5
27+
google.golang.org/grpc v1.47.0
28+
google.golang.org/protobuf v1.28.1
2329
gopkg.in/yaml.v2 v2.4.0
30+
gorm.io/driver/mysql v1.4.1
31+
gorm.io/gorm v1.24.0
2432
)
2533

2634
require (
27-
github.com/gomodule/redigo v1.8.8 // indirect
35+
github.com/dlclark/regexp2 v1.4.0 // indirect
36+
github.com/goccy/go-json v0.9.7 // indirect
37+
github.com/iris-contrib/go.uuid v2.0.0+incompatible // indirect
2838
github.com/jinzhu/inflection v1.0.0 // indirect
2939
github.com/jinzhu/now v1.1.5 // indirect
30-
google.golang.org/grpc v1.39.1 // indirect
31-
gorm.io/driver/mysql v1.3.3 // indirect
32-
gorm.io/gorm v1.23.5 // indirect
40+
github.com/klauspost/compress v1.17.2 // indirect
41+
github.com/orcaman/concurrent-map v1.0.0 // indirect
42+
github.com/pelletier/go-toml/v2 v2.0.1 // indirect
43+
github.com/rs/zerolog v1.26.1 // indirect
44+
golang.org/x/exp v0.0.0-20240506185415-9bf2ced13842 // indirect
3345
)
3446

3547
require (
@@ -45,7 +57,7 @@ require (
4557
github.com/go-playground/validator/v10 v10.10.1 // indirect
4658
github.com/gogo/protobuf v1.3.2 // indirect
4759
github.com/golang/protobuf v1.5.2 // indirect
48-
github.com/golang/snappy v0.0.3 // indirect
60+
github.com/golang/snappy v0.0.4 // indirect
4961
github.com/gorilla/websocket v1.5.0 // indirect
5062
github.com/json-iterator/go v1.1.12 // indirect
5163
github.com/leodido/go-urn v1.2.1 // indirect
@@ -54,24 +66,22 @@ require (
5466
github.com/mattn/go-isatty v0.0.14 // indirect; indirect¬¬¬
5567
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
5668
github.com/modern-go/reflect2 v1.0.2 // indirect
57-
github.com/nats-io/nats-server/v2 v2.6.6 // indirect
58-
github.com/nats-io/nkeys v0.3.0 // indirect
69+
github.com/nats-io/nkeys v0.4.7 // indirect
5970
github.com/nats-io/nuid v1.0.1 // indirect
6071
github.com/pkg/errors v0.9.1 // indirect
6172
github.com/rifflock/lfshook v0.0.0-20180920164130-b9218ef580f5 // indirect
6273
github.com/ugorji/go/codec v1.2.7 // indirect
63-
go.etcd.io/etcd/api/v3 v3.5.3 // indirect
64-
go.etcd.io/etcd/client/pkg/v3 v3.5.3 // indirect
65-
go.uber.org/atomic v1.7.0 // indirect
74+
go.etcd.io/etcd/api/v3 v3.5.5 // indirect
75+
go.etcd.io/etcd/client/pkg/v3 v3.5.5 // indirect
76+
go.uber.org/atomic v1.7.0
6677
go.uber.org/multierr v1.6.0 // indirect
6778
go.uber.org/zap v1.17.0 // indirect
68-
golang.org/x/crypto v0.0.0-20220411220226-7b82a4e95df4 // indirect
69-
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2 // indirect
70-
golang.org/x/sys v0.0.0-20220422013727-9388b58f7150 // indirect
71-
golang.org/x/text v0.3.7 // indirect
72-
golang.org/x/time v0.0.0-20210220033141-f8bda1e9f3ba // indirect
73-
google.golang.org/genproto v0.0.0-20210813162853-db860fec028c // indirect
74-
google.golang.org/protobuf v1.28.0 // indirect
75-
xorm.io/builder v0.3.6 // indirect
79+
golang.org/x/crypto v0.18.0 // indirect
80+
golang.org/x/net v0.10.0 // indirect
81+
golang.org/x/sys v0.16.0 // indirect
82+
golang.org/x/text v0.14.0 // indirect
83+
golang.org/x/time v0.0.0-20210220033141-f8bda1e9f3ba
84+
google.golang.org/genproto v0.0.0-20220630174209-ad1d48641aa7 // indirect
85+
xorm.io/builder v0.3.11-0.20220531020008-1bd24a7dc978 // indirect
7686
xorm.io/core v0.7.2-0.20190928055935-90aeac8d08eb
7787
)

go.sum

+86-75
Large diffs are not rendered by default.

src/etcd/etcdDemo_test.go

+188-25
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,13 @@ package test
22

33
import (
44
"context"
5-
"encoding/json"
65
"fmt"
6+
mik "go-learn/src/mk"
7+
"go.etcd.io/etcd/client/v3/concurrency"
8+
"reflect"
79
"testing"
810
"time"
11+
"unsafe"
912

1013
"github.com/simonalong/gole/util"
1114
clientv3 "go.etcd.io/etcd/client/v3"
@@ -22,7 +25,7 @@ var Ctx = context.Background()
2225
func init() {
2326
// 客户端配置
2427
config = clientv3.Config{
25-
Endpoints: []string{"10.30.30.78:22379"},
28+
Endpoints: []string{"10.30.30.78:52379"},
2629
DialTimeout: 5 * time.Second,
2730
Username: "root",
2831
Password: "ZljIsysc0re123",
@@ -36,24 +39,24 @@ func init() {
3639
}
3740

3841
func TestEtcd1(t *testing.T) {
39-
authRsp, _ := etcdClient.AuthStatus(Ctx)
40-
fmt.Println(authRsp)
42+
//authRsp, _ := etcdClient.AuthStatus(Ctx)
43+
//fmt.Println(authRsp)
4144

42-
//res, err := etcdClient.Put(Ctx, "key4", "v1")
43-
//if err != nil {
44-
// fmt.Println(err)
45-
// return
46-
//}
47-
//
48-
//fmt.Println(res)
49-
//
50-
//res1, err := etcdClient.Get(Ctx, "key4")
51-
//if err != nil {
52-
// fmt.Println(err)
53-
// return
54-
//}
55-
//
56-
//fmt.Println(string(res1.Kvs[0].Value))
45+
res, err := etcdClient.Put(Ctx, "key4", "v1")
46+
if err != nil {
47+
fmt.Println(err)
48+
return
49+
}
50+
51+
fmt.Println(res)
52+
53+
res1, err := etcdClient.Get(Ctx, "key4")
54+
if err != nil {
55+
fmt.Println(err)
56+
return
57+
}
58+
59+
fmt.Println(string(res1.Kvs[0].Value))
5760
}
5861

5962
func TestKeys(t *testing.T) {
@@ -173,13 +176,173 @@ func write(index int) {
173176

174177
func TestName(t *testing.T) {
175178

176-
dataMap := map[string]string{}
177-
dataMap["a"] = "a"
178-
dataMap["b"] = "b"
179+
//dataMap := map[string]string{}
180+
//dataMap["a"] = "a"
181+
//dataMap["b"] = "b"
182+
//
183+
//bytes, err := json.Marshal(12)
184+
//if err != nil {
185+
// fmt.Printf("%v", err.Error())
186+
//}
187+
//fmt.Println(string(bytes))
188+
189+
//fmt.Println(*flag.String("a", "b","c"))
190+
}
191+
192+
func TestLock1(t *testing.T) {
193+
194+
//为锁生成session
195+
s1, err := concurrency.NewSession(etcdClient, concurrency.WithTTL(5))
196+
if err != nil {
197+
t.Log(err.Error())
198+
return
199+
}
200+
defer s1.Close()
201+
202+
ctx := context.Background()
203+
locker := concurrency.NewMutex(s1, "test/name")
204+
fmt.Println("acquiring lock")
205+
if err := locker.TryLock(ctx); err != nil {
206+
fmt.Println("尝试失败", err.Error())
207+
return
208+
}
209+
210+
// 请求锁
211+
212+
fmt.Println("acquired lock")
213+
214+
time.Sleep(time.Second * 10)
179215

180-
bytes, err := json.Marshal(12)
216+
//time.Sleep(time.Duration(rand.Intn(30))*time.Second)
217+
locker.Unlock(ctx) //释放锁
218+
fmt.Println("released lock")
219+
}
220+
221+
func TestLock2(t *testing.T) {
222+
223+
//为锁生成session
224+
s1, err := concurrency.NewSession(etcdClient, concurrency.WithTTL(5))
181225
if err != nil {
182-
fmt.Printf("%v", err.Error())
226+
t.Log(err.Error())
227+
return
183228
}
184-
fmt.Println(string(bytes))
229+
defer s1.Close()
230+
fmt.Println("acquiring lock")
231+
ctx := context.Background()
232+
locker := concurrency.NewMutex(s1, "test/name")
233+
if err := locker.TryLock(ctx); err != nil {
234+
fmt.Println("尝试失败", err.Error())
235+
return
236+
}
237+
238+
// 请求锁
239+
fmt.Println("acquired lock")
240+
241+
time.Sleep(time.Second * 10)
242+
243+
//time.Sleep(time.Duration(rand.Intn(30))*time.Second)
244+
locker.Unlock(ctx) //释放锁
245+
fmt.Println("released lock")
246+
}
247+
248+
type Demo struct {
249+
private string
250+
youCannotSeeMe int
251+
Trick bool
252+
}
253+
254+
func TestPrivate(t *testing.T) {
255+
//d := Demo{private: "hahaha", youCannotSeeMe: 110, Trick: true}
256+
257+
//type Header struct {
258+
// NotPrivate string
259+
// YouCanSeeMe int
260+
//}
261+
//
262+
//h := *(*Header)(uintptr(unsafe.Pointer(&d)))
263+
//h.YouCanSeeMe = 32
264+
//
265+
//fmt.Printf("%+v", h)
266+
//fmt.Printf("%+v", d)
267+
268+
//priV := reflect.ValueOf(d).FieldByName("private")
269+
//priV = reflect.NewAt(priV.Type(), unsafe.Pointer(priV.UnsafeAddr())).Elem()
270+
//v := priV.Interface()
271+
//pvv := v.(string)
272+
//pvv = "sdfsdf"
273+
}
274+
275+
type TestPointer struct {
276+
A int
277+
b int // 私有变量
278+
}
279+
280+
func (T *TestPointer) OouPut() {
281+
fmt.Println("TestPointer OouPut:", T.A, T.b)
282+
}
283+
284+
func TestPrivate2(t *testing.T) {
285+
T := TestPointer{A: 1}
286+
pb := (*int)(unsafe.Pointer(uintptr(unsafe.Pointer(&T)) + 8))
287+
/*
288+
Tmp := uintptr(unsafe.Pointer(&T)) + 8)
289+
pb := (*int)(unsafe.Pointer(Tmp)
290+
千万不能出现这种用临时变量中转一下的情况。因为GC可能因为优化内存碎片的原因移动了这个对象。只保留了指针的地址是没有意义的。
291+
*/
292+
*pb = 2
293+
T.OouPut() //1 2
294+
}
295+
296+
//// Index 获取首页信息
297+
//func (receiver *Home) Index(req *controllers.HomeRequest, ctx *gin.Context) (*controllers.HomeResponse, error) {
298+
// value := reflect.ValueOf(ctx).Elem()
299+
//
300+
// engine := value.FieldByName("engine")
301+
// // rf can't be read or set.
302+
// engine = reflect.NewAt(engine.Type(), unsafe.Pointer(engine.UnsafeAddr())).Elem()
303+
// v := engine.Interface()
304+
// context := v.(*gin.Engine)
305+
// help.Dump(context)
306+
//
307+
// return &controllers.HomeResponse{}, nil
308+
//}
309+
310+
type TestStruct struct {
311+
mik.TestStruct33
312+
testField int
313+
}
314+
315+
func (pt TestStruct) Namess() []string {
316+
return pt.TestStruct33.Namess()
317+
}
318+
319+
func TestPrivate3(t *testing.T) {
320+
//var s = TestStruct{testField: 100, name: []string{"z", "haha"}}
321+
//
322+
//// 获取旧数据
323+
//ov := GetPrivateFieldValue(reflect.ValueOf(&s), "name")
324+
//// 100
325+
//fmt.Println(ov)
326+
//
327+
//ovV := ov.([]string)
328+
//newDatas := append(ovV, "kkk")
329+
//// 修改为新数据
330+
//var data []string
331+
//data = newDatas
332+
//SetFieldPrivateValue(reflect.ValueOf(&s), "name", reflect.ValueOf(&data))
333+
//// 21
334+
//fmt.Println(s)
335+
}
336+
337+
// 获取对象的私有属性
338+
func GetPrivateFieldValue(objPtrValue reflect.Value, fieldName string) interface{} {
339+
fieldValue := objPtrValue.Elem().FieldByName(fieldName)
340+
return reflect.NewAt(fieldValue.Type(), unsafe.Pointer(fieldValue.UnsafeAddr())).Elem().Interface()
341+
}
342+
343+
// 给对象的属性设置值
344+
func SetFieldPrivateValue(objPtrValue reflect.Value, fieldName string, fieldNewValue reflect.Value) {
345+
fieldValue := objPtrValue.Elem().FieldByName(fieldName)
346+
fieldValue = reflect.NewAt(fieldValue.Type(), unsafe.Pointer(fieldValue.UnsafeAddr())).Elem()
347+
fieldValue.Set(fieldNewValue.Elem())
185348
}

0 commit comments

Comments
 (0)