Skip to content

Commit 0ffe7cd

Browse files
authored
Merge pull request #55 from RealFax/dev
patch, feature
2 parents 4ca4c35 + 20a6eb9 commit 0ffe7cd

File tree

19 files changed

+95
-199
lines changed

19 files changed

+95
-199
lines changed

cmd/RedQueenUtil/append_cluster.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ func (c *appendCluster) exec() error {
1919
ctx, cancel := context.WithTimeout(context.Background(), time.Second*15)
2020
defer cancel()
2121

22-
call, err := client.New(ctx, endpoints, true)
22+
call, err := client.New(ctx, endpoints)
2323
if err != nil {
2424
return err
2525
}

common/hack/unsafe.go

Lines changed: 0 additions & 21 deletions
This file was deleted.

config.toml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,6 @@ backend = "nuts"
2929
name = "node-1"
3030
peer-addr = "127.0.0.1:4539"
3131

32-
# state options
33-
# new, existing
34-
state = "new"
35-
3632
token = "red-queen-cluster"
3733

3834
[log]

config.toml.exam

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,6 @@ backend = "nuts"
2929
name = "node-1"
3030
peer-addr = "127.0.0.1:4539"
3131

32-
# state options
33-
# new, existing
34-
state = "new"
35-
3632
token = "red-queen-cluster"
3733

3834
[log]

config/config.go

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ package config
33
import (
44
"flag"
55
"fmt"
6-
"os"
7-
86
"github.com/BurntSushi/toml"
97
"github.com/pkg/errors"
8+
"os"
9+
"path"
1010
)
1111

1212
type ServerEnv interface {
@@ -15,7 +15,9 @@ type ServerEnv interface {
1515
}
1616

1717
type env struct {
18-
firstRun bool
18+
firstRun bool
19+
initLockFile string
20+
1921
configFile string
2022
}
2123

@@ -54,8 +56,6 @@ type ClusterBootstrap struct {
5456
}
5557

5658
type Cluster struct {
57-
// State enum: new, existing
58-
State EnumClusterState `toml:"state"`
5959
Token string `toml:"token"`
6060
Bootstrap []ClusterBootstrap `toml:"bootstrap"`
6161
}
@@ -85,7 +85,24 @@ type Config struct {
8585
}
8686

8787
func (c *Config) setupEnv() {
88-
c.env.firstRun = c.Cluster.State == ClusterStateNew
88+
c.env.initLockFile = path.Join(c.Node.DataDir, ".init.lock")
89+
90+
// write init lock
91+
if _, err := os.Stat(c.env.initLockFile); os.IsNotExist(err) {
92+
c.env.firstRun = true
93+
94+
if err = os.MkdirAll(path.Clean(c.Node.DataDir), os.ModePerm); err != nil {
95+
panic("Setup config error:" + err.Error())
96+
}
97+
98+
f, err := os.OpenFile(c.env.initLockFile, os.O_WRONLY|os.O_TRUNC|os.O_CREATE, 0644)
99+
if err != nil {
100+
panic("Setup config error:" + err.Error())
101+
}
102+
defer f.Close()
103+
_, _ = f.WriteString("LOCK")
104+
}
105+
89106
}
90107

91108
func (c *Config) Env() ServerEnv {
@@ -127,7 +144,6 @@ func bindServerFromArgs(cfg *Config, args ...string) error {
127144
fs.Var(newValidatorStringValue[EnumNutsRWMode](DefaultStoreNutsRWMode, &cfg.Store.Nuts.RWMode), "nuts-rw-mode", "select read & write mode, options: fileio, mmap")
128145

129146
// main config::cluster
130-
fs.Var(newValidatorStringValue[EnumClusterState](DefaultClusterState, &cfg.Cluster.State), "cluster-state", "status of the cluster at startup")
131147
fs.StringVar(&cfg.Cluster.Token, "cluster-token", "", "")
132148

133149
// main config::cluster::bootstrap(s)
@@ -168,7 +184,6 @@ func bindServerFromEnv(cfg *Config) {
168184
BindEnvVar(newValidatorStringValue[EnumNutsRWMode](DefaultStoreNutsRWMode, &cfg.Store.Nuts.RWMode), "RQ_NUTS_RW_MODE")
169185

170186
// main config::cluster
171-
BindEnvVar(newValidatorStringValue[EnumClusterState](DefaultClusterState, &cfg.Cluster.State), "RQ_CLUSTER_STATE")
172187
EnvStringVar(&cfg.Cluster.Token, "RQ_CLUSTER_TOKEN", "")
173188

174189
// main config::cluster::bootstrap(s)

config/default.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,6 @@ const (
2323
DefaultStoreNutsRWMode string = "fileio"
2424
)
2525

26-
// -- cluster default value
27-
28-
const (
29-
DefaultClusterState = string(ClusterStateNew)
30-
)
31-
3226
// -- log default value
3327

3428
const (

config/validator.go

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -41,22 +41,6 @@ func (m EnumNutsRWMode) Valid() error {
4141
}
4242
}
4343

44-
type EnumClusterState string
45-
46-
const (
47-
ClusterStateNew EnumClusterState = "new"
48-
ClusterStateExisting EnumClusterState = "existing"
49-
)
50-
51-
func (s EnumClusterState) Valid() error {
52-
switch s {
53-
case ClusterStateNew, ClusterStateExisting:
54-
return nil
55-
default:
56-
return errors.New("unknown cluster state type")
57-
}
58-
}
59-
6044
type EnumLogLogger string
6145

6246
const (
@@ -84,5 +68,5 @@ func (p FilePath) Valid() error {
8468
}
8569

8670
type stringValidator interface {
87-
EnumStoreBackend | EnumNutsRWMode | EnumClusterState | EnumLogLogger | FilePath
71+
EnumStoreBackend | EnumNutsRWMode | EnumLogLogger | FilePath
8872
}

go.mod

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,35 +4,39 @@ go 1.20
44

55
require (
66
github.com/BurntSushi/toml v1.2.1
7-
github.com/OneOfOne/xxhash v1.2.2
87
github.com/RealFax/order-map v0.2.0
98
github.com/cespare/xxhash v1.1.0
109
github.com/google/uuid v1.3.0
1110
github.com/hashicorp/raft v1.5.0
1211
github.com/hashicorp/raft-boltdb/v2 v2.2.2
13-
github.com/nutsdb/nutsdb v0.12.0
12+
github.com/nutsdb/nutsdb v0.14.1
1413
github.com/pkg/errors v0.9.1
1514
google.golang.org/grpc v1.55.0
1615
google.golang.org/protobuf v1.30.0
1716
)
1817

1918
require (
19+
github.com/antlabs/stl v0.0.1 // indirect
20+
github.com/antlabs/timer v0.0.11 // indirect
2021
github.com/armon/go-metrics v0.4.1 // indirect
2122
github.com/boltdb/bolt v1.3.1 // indirect
2223
github.com/bwmarrin/snowflake v0.3.0 // indirect
23-
github.com/fatih/color v1.13.0 // indirect
24+
github.com/emirpasic/gods v1.18.1 // indirect
25+
github.com/fatih/color v1.15.0 // indirect
26+
github.com/gofrs/flock v0.8.1 // indirect
2427
github.com/golang/protobuf v1.5.3 // indirect
2528
github.com/hashicorp/go-hclog v1.5.0 // indirect
2629
github.com/hashicorp/go-immutable-radix v1.0.0 // indirect
2730
github.com/hashicorp/go-msgpack v0.5.5 // indirect
2831
github.com/hashicorp/golang-lru v0.5.0 // indirect
29-
github.com/mattn/go-colorable v0.1.12 // indirect
30-
github.com/mattn/go-isatty v0.0.14 // indirect
32+
github.com/mattn/go-colorable v0.1.13 // indirect
33+
github.com/mattn/go-isatty v0.0.17 // indirect
34+
github.com/tidwall/btree v1.6.0 // indirect
3135
github.com/xujiajun/mmap-go v1.0.1 // indirect
3236
github.com/xujiajun/utils v0.0.0-20220904132955-5f7c5b914235 // indirect
33-
go.etcd.io/bbolt v1.3.5 // indirect
37+
go.etcd.io/bbolt v1.3.7 // indirect
3438
golang.org/x/net v0.8.0 // indirect
35-
golang.org/x/sys v0.7.0 // indirect
39+
golang.org/x/sys v0.10.0 // indirect
3640
golang.org/x/text v0.8.0 // indirect
3741
google.golang.org/genproto v0.0.0-20230306155012-7f2fa6fef1f4 // indirect
3842
)

go.sum

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuy
1010
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
1111
github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=
1212
github.com/alecthomas/units v0.0.0-20190717042225-c3de453c63f4/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=
13+
github.com/antlabs/stl v0.0.1 h1:TRD3csCrjREeLhLoQ/supaoCvFhNLBTNIwuRGrDIs6Q=
14+
github.com/antlabs/stl v0.0.1/go.mod h1:wvVwP1loadLG3cRjxUxK8RL4Co5xujGaZlhbztmUEqQ=
15+
github.com/antlabs/timer v0.0.11 h1:z75oGFLeTqJHMOcWzUPBKsBbQAz4Ske3AfqJ7bsdcwU=
16+
github.com/antlabs/timer v0.0.11/go.mod h1:JNV8J3yGvMKhCavGXgj9HXrVZkfdQyKCcqXBT8RdyuU=
1317
github.com/armon/go-metrics v0.0.0-20190430140413-ec5e00d3c878/go.mod h1:3AMJUQhVx52RsWOnlkpikZr01T/yAVN2gn0861vByNg=
1418
github.com/armon/go-metrics v0.4.1 h1:hR91U9KYmb6bLBYLQjyM+3j+rcd/UhE+G78SFnF8gJA=
1519
github.com/armon/go-metrics v0.4.1/go.mod h1:E6amYzXo6aW1tqzoZGT755KkbgrJsSdpwZ+3JqfkOG4=
@@ -29,13 +33,19 @@ github.com/circonus-labs/circonusllhist v0.1.3/go.mod h1:kMXHVDlOchFAehlya5ePtbp
2933
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
3034
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
3135
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
36+
github.com/emirpasic/gods v1.18.1 h1:FXtiHYKDGKCW2KzwZKx0iC0PQmdlorYgdFG9jPXJ1Bc=
37+
github.com/emirpasic/gods v1.18.1/go.mod h1:8tpGGwCnJ5H4r6BWwaV6OrWmMoPhUl5jm/FMNAnJvWQ=
3238
github.com/fatih/color v1.13.0 h1:8LOYc1KYPPmyKMuN8QV2DNRWNbLo6LZ0iLs8+mlH53w=
3339
github.com/fatih/color v1.13.0/go.mod h1:kLAiJbzzSOZDVNGyDpeOxJ47H46qBXwg5ILebYFFOfk=
40+
github.com/fatih/color v1.15.0 h1:kOqh6YHBtK8aywxGerMG2Eq3H6Qgoqeo13Bk2Mv/nBs=
41+
github.com/fatih/color v1.15.0/go.mod h1:0h5ZqXfHYED7Bhv2ZJamyIOUej9KtShiJESRwBDUSsw=
3442
github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as=
3543
github.com/go-kit/kit v0.9.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as=
3644
github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE=
3745
github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk=
3846
github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY=
47+
github.com/gofrs/flock v0.8.1 h1:+gYjHKf32LDeiEEFhQaotPbLuUXjY5ZqxKgXy7n59aw=
48+
github.com/gofrs/flock v0.8.1/go.mod h1:F1TvTiK9OcQqauNUHlbJvyl9Qa1QvF/gOUDKA14jxHU=
3949
github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ=
4050
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
4151
github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
@@ -81,9 +91,14 @@ github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
8191
github.com/mattn/go-colorable v0.1.9/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc=
8292
github.com/mattn/go-colorable v0.1.12 h1:jF+Du6AlPIjs2BiUiQlKOX0rt3SujHxPnksPKZbaA40=
8393
github.com/mattn/go-colorable v0.1.12/go.mod h1:u5H1YNBxpqRaxsYJYSkiCWKzEfiAb1Gb520KVy5xxl4=
94+
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
95+
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
8496
github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
8597
github.com/mattn/go-isatty v0.0.14 h1:yVuAays6BHfxijgZPzw+3Zlu5yQgKGP2/hcQbHb7S9Y=
8698
github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94=
99+
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
100+
github.com/mattn/go-isatty v0.0.17 h1:BTarxUcIeDqL27Mc+vyvdWYSL28zpIhv3RoTdsLMPng=
101+
github.com/mattn/go-isatty v0.0.17/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
87102
github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0=
88103
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
89104
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
@@ -92,6 +107,8 @@ github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3Rllmb
92107
github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
93108
github.com/nutsdb/nutsdb v0.12.0 h1:6P7EJat2PyVhRu51KMmFu5N851UupfpPBHAqctRm3/4=
94109
github.com/nutsdb/nutsdb v0.12.0/go.mod h1:FSztXVhUSK5YmedmZQ6m37cU/KpVbGaezUEmUBP8DEo=
110+
github.com/nutsdb/nutsdb v0.14.1 h1:z+Kth/kz2oYqKmOMBZho1YK2183xjrcl6KExRtCFl18=
111+
github.com/nutsdb/nutsdb v0.14.1/go.mod h1:6inOji9rFBporXeHDjJny4g50RpQbkjSK5jI1hht0j8=
95112
github.com/pascaldekloe/goe v0.1.0 h1:cBOtyMzM9HTpWjXfbbunk26uA6nG3a8n06Wieeh0MwY=
96113
github.com/pascaldekloe/goe v0.1.0/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc=
97114
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
@@ -125,11 +142,14 @@ github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpE
125142
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
126143
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
127144
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
145+
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
128146
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
129147
github.com/stretchr/testify v1.7.2/go.mod h1:R6va5+xMeoiuVRoj+gSkQ7d3FALtqAAGI1FQKckRals=
130148
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
131149
github.com/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ8=
132150
github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
151+
github.com/tidwall/btree v1.6.0 h1:LDZfKfQIBHGHWSwckhXI0RPSXzlo+KYdjK7FWSqOzzg=
152+
github.com/tidwall/btree v1.6.0/go.mod h1:twD9XRA5jj9VUQGELzDO4HPQTNJsoWWfYEL+EUQ2cKY=
133153
github.com/tv42/httpunix v0.0.0-20150427012821-b75d8614f926/go.mod h1:9ESjWnEqriFuLhtthL60Sar/7RFoluCcXsuvEwTV5KM=
134154
github.com/xujiajun/gorouter v1.2.0/go.mod h1:yJrIta+bTNpBM/2UT8hLOaEAFckO+m/qmR3luMIQygM=
135155
github.com/xujiajun/mmap-go v1.0.1 h1:7Se7ss1fLPPRW+ePgqGpCkfGIZzJV6JPq9Wq9iv/WHc=
@@ -138,6 +158,8 @@ github.com/xujiajun/utils v0.0.0-20220904132955-5f7c5b914235 h1:w0si+uee0iAaCJO9
138158
github.com/xujiajun/utils v0.0.0-20220904132955-5f7c5b914235/go.mod h1:MR4+0R6A9NS5IABnIM3384FfOq8QFVnm7WDrBOhIaMU=
139159
go.etcd.io/bbolt v1.3.5 h1:XAzx9gjCb0Rxj7EoqcClPD1d5ZBxZJk0jbuoPHenBt0=
140160
go.etcd.io/bbolt v1.3.5/go.mod h1:G5EMThwa9y8QZGBClrRx5EY+Yw9kAhnjy3bSjsnlVTQ=
161+
go.etcd.io/bbolt v1.3.7 h1:j+zJOnnEjF/kyHlDDgGnVL/AIqIJPq8UoB2GSNfkUfQ=
162+
go.etcd.io/bbolt v1.3.7/go.mod h1:N9Mkw9X8x5fupy0IKsmuqVtoGDyxsaDlbk4Rd05IAQw=
141163
golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
142164
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
143165
golang.org/x/net v0.0.0-20181114220301-adae6a3d119a/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
@@ -161,8 +183,11 @@ golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBc
161183
golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
162184
golang.org/x/sys v0.0.0-20220405210540-1e041c57c461/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
163185
golang.org/x/sys v0.0.0-20220503163025-988cb79eb6c6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
186+
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
164187
golang.org/x/sys v0.7.0 h1:3jlCCIQZPdOYu1h8BkNvLz8Kgwtae2cagcG/VamtZRU=
165188
golang.org/x/sys v0.7.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
189+
golang.org/x/sys v0.10.0 h1:SqMFp9UcQJZa+pmYuAKjd9xq1f0j5rLcDIk0mj4qAsA=
190+
golang.org/x/sys v0.10.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
166191
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
167192
golang.org/x/text v0.8.0 h1:57P1ETyNKtuIjB4SRd15iJxuhj8Gc416Y78H3qgMh68=
168193
golang.org/x/text v0.8.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=

internal/hack/unsafe.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package hack
2+
3+
import "unsafe"
4+
5+
func Bytes2String(b []byte) string {
6+
return *(*string)(unsafe.Pointer(&b))
7+
}
8+
9+
func String2Bytes(s string) []byte {
10+
return unsafe.Slice(unsafe.StringData(s), len(s))
11+
}

0 commit comments

Comments
 (0)