Compare commits
18 Commits
40d025ad4d
...
new_conn
| Author | SHA1 | Date | |
|---|---|---|---|
| ffa3cc881e | |||
| 3e46293efc | |||
| 8cda1aa4c7 | |||
| 17d31f35f3 | |||
| 64d341e307 | |||
| 554bb22f53 | |||
| fa3b0c070a | |||
| 18d284a4ea | |||
| a2ef22d41a | |||
| eaae5a5ccd | |||
| 5352e6ba59 | |||
| f4e6f8a415 | |||
| 324a7225ec | |||
| b549ad06d5 | |||
| 22b63af7fa | |||
| f470966d30 | |||
| 6608784709 | |||
| 6a98802e24 |
@ -1,214 +0,0 @@
|
||||
package apicaller
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"os"
|
||||
"strings"
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
type ApiCaller interface {
|
||||
HasAuthority(authPath string) bool
|
||||
GetMyAuthority() []string
|
||||
}
|
||||
|
||||
type ApiCallerAuths interface {
|
||||
NewApiCaller(user string) ApiCaller
|
||||
NewApiCallerByServer() ApiCaller
|
||||
Update(newusers map[string]*map[string]bool) error
|
||||
Serialize() []byte
|
||||
}
|
||||
|
||||
type apiCallerAuths struct {
|
||||
sync.Mutex
|
||||
serialized unsafe.Pointer // *[]byte
|
||||
users map[string]*map[string]bool // email -> authoriries
|
||||
}
|
||||
|
||||
func (a *apiCallerAuths) Serialize() []byte {
|
||||
btptr := atomic.LoadPointer(&a.serialized)
|
||||
return *(*[]byte)(btptr)
|
||||
}
|
||||
|
||||
func (a *apiCallerAuths) getAuthority(email string) []string {
|
||||
a.Lock()
|
||||
defer a.Unlock()
|
||||
|
||||
auths := a.users[email]
|
||||
if auths == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
var out []string
|
||||
for k, v := range *auths {
|
||||
if v {
|
||||
out = append(out, k)
|
||||
}
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
func (a *apiCallerAuths) Update(newAuths map[string]*map[string]bool) error {
|
||||
src := map[string][]string{}
|
||||
for user, auths := range newAuths {
|
||||
for cat, has := range *auths {
|
||||
if has {
|
||||
arr := append(src[cat], user)
|
||||
src[cat] = arr
|
||||
} else if _, ok := src[cat]; !ok {
|
||||
src[cat] = []string{}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
a.Lock()
|
||||
defer a.Unlock()
|
||||
|
||||
file, err := os.Create(userAuthsFileName)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer file.Close()
|
||||
|
||||
enc := json.NewEncoder(file)
|
||||
err = enc.Encode(src)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
a.users = newAuths
|
||||
bt, _ := json.Marshal(newAuths)
|
||||
atomic.StorePointer(&a.serialized, unsafe.Pointer(&bt))
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (a *apiCallerAuths) hasAuthority(email string, authPath string) bool {
|
||||
a.Lock()
|
||||
defer a.Unlock()
|
||||
|
||||
auths, ok := a.users[email]
|
||||
if !ok {
|
||||
return false
|
||||
}
|
||||
|
||||
if (*auths)[authPath] {
|
||||
return true
|
||||
}
|
||||
|
||||
for k, v := range *auths {
|
||||
if strings.HasPrefix(k, authPath+"/") {
|
||||
return v
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
const userAuthsFileName = "userauths.json"
|
||||
|
||||
func NewApiCallerAuths() ApiCallerAuths {
|
||||
var out apiCallerAuths
|
||||
f, _ := os.Open(userAuthsFileName)
|
||||
if f == nil {
|
||||
emptyAuths := map[string][]string{
|
||||
"/admins": {"enter_first_admin_email@action2quare.com"},
|
||||
}
|
||||
newf, _ := os.Create(userAuthsFileName)
|
||||
if newf != nil {
|
||||
enc := json.NewEncoder(newf)
|
||||
enc.Encode(emptyAuths)
|
||||
newf.Close()
|
||||
|
||||
f, _ = os.Open(userAuthsFileName)
|
||||
}
|
||||
}
|
||||
|
||||
if f != nil {
|
||||
defer f.Close()
|
||||
|
||||
var src map[string][]string
|
||||
dec := json.NewDecoder(f)
|
||||
dec.Decode(&src)
|
||||
|
||||
compiled := make(map[string]*map[string]bool)
|
||||
|
||||
// 전체 유저 목록을 먼저 뽑고나서
|
||||
for _, users := range src {
|
||||
for _, user := range users {
|
||||
if _, ok := compiled[user]; !ok {
|
||||
compiled[user] = &map[string]bool{}
|
||||
}
|
||||
}
|
||||
}
|
||||
// 전체 유저한테 모든 카테고리를 설정한다.
|
||||
for _, auths := range compiled {
|
||||
for cat := range src {
|
||||
(*auths)[cat] = false
|
||||
}
|
||||
}
|
||||
// 이제 유저별 권한을 설정
|
||||
for category, users := range src {
|
||||
for _, user := range users {
|
||||
(*compiled[user])[category] = true
|
||||
}
|
||||
}
|
||||
|
||||
out = apiCallerAuths{
|
||||
users: compiled,
|
||||
}
|
||||
} else {
|
||||
|
||||
out = apiCallerAuths{
|
||||
users: map[string]*map[string]bool{},
|
||||
}
|
||||
}
|
||||
|
||||
marshaled, _ := json.Marshal(out.users)
|
||||
out.serialized = unsafe.Pointer(&marshaled)
|
||||
|
||||
return &out
|
||||
}
|
||||
|
||||
type apiCaller struct {
|
||||
userAuths *apiCallerAuths
|
||||
caller string
|
||||
}
|
||||
|
||||
func (a *apiCallerAuths) NewApiCaller(user string) ApiCaller {
|
||||
if len(user) == 0 {
|
||||
return nil
|
||||
}
|
||||
return &apiCaller{
|
||||
userAuths: a,
|
||||
caller: user,
|
||||
}
|
||||
}
|
||||
|
||||
func (a *apiCallerAuths) NewApiCallerByServer() ApiCaller {
|
||||
return &apiCaller{
|
||||
userAuths: a,
|
||||
caller: "",
|
||||
}
|
||||
}
|
||||
|
||||
func (ac apiCaller) callByServer() bool {
|
||||
return len(ac.caller) == 0
|
||||
}
|
||||
|
||||
func (ac apiCaller) HasAuthority(authPath string) bool {
|
||||
if ac.callByServer() {
|
||||
return true
|
||||
}
|
||||
|
||||
return ac.userAuths.hasAuthority(ac.caller, authPath)
|
||||
}
|
||||
|
||||
func (ac apiCaller) GetMyAuthority() []string {
|
||||
if !ac.callByServer() {
|
||||
return ac.userAuths.getAuthority(ac.caller)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
33
go.mod
33
go.mod
@ -3,22 +3,34 @@ module repositories.action2quare.com/ayo/gocommon
|
||||
go 1.20
|
||||
|
||||
require (
|
||||
github.com/awa/go-iap v1.32.0
|
||||
github.com/go-redis/redis/v8 v8.11.5
|
||||
github.com/golang-jwt/jwt v3.2.2+incompatible
|
||||
github.com/gorilla/websocket v1.5.0
|
||||
github.com/pires/go-proxyproto v0.7.0
|
||||
github.com/prometheus/client_golang v1.17.0
|
||||
go.mongodb.org/mongo-driver v1.11.6
|
||||
golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d
|
||||
golang.org/x/text v0.9.0
|
||||
golang.org/x/crypto v0.18.0
|
||||
golang.org/x/text v0.14.0
|
||||
)
|
||||
|
||||
require (
|
||||
cloud.google.com/go/compute v1.23.3 // indirect
|
||||
cloud.google.com/go/compute/metadata v0.2.3 // indirect
|
||||
github.com/beorn7/perks v1.0.1 // indirect
|
||||
github.com/cespare/xxhash/v2 v2.2.0 // indirect
|
||||
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
|
||||
github.com/felixge/httpsnoop v1.0.4 // indirect
|
||||
github.com/go-logr/logr v1.3.0 // indirect
|
||||
github.com/go-logr/stdr v1.2.2 // indirect
|
||||
github.com/golang-jwt/jwt/v4 v4.3.0 // indirect
|
||||
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
|
||||
github.com/golang/protobuf v1.5.3 // indirect
|
||||
github.com/golang/snappy v0.0.1 // indirect
|
||||
github.com/google/s2a-go v0.1.7 // indirect
|
||||
github.com/google/uuid v1.5.0 // indirect
|
||||
github.com/googleapis/enterprise-certificate-proxy v0.3.2 // indirect
|
||||
github.com/googleapis/gax-go/v2 v2.12.0 // indirect
|
||||
github.com/klauspost/compress v1.13.6 // indirect
|
||||
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
|
||||
github.com/montanaflynn/stats v0.0.0-20171201202039-1bf9dbcd8cbe // indirect
|
||||
@ -30,7 +42,18 @@ require (
|
||||
github.com/xdg-go/scram v1.1.1 // indirect
|
||||
github.com/xdg-go/stringprep v1.0.3 // indirect
|
||||
github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d // indirect
|
||||
golang.org/x/sync v0.3.0 // indirect
|
||||
golang.org/x/sys v0.11.0 // indirect
|
||||
google.golang.org/protobuf v1.31.0 // indirect
|
||||
go.opencensus.io v0.24.0 // indirect
|
||||
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.46.1 // indirect
|
||||
go.opentelemetry.io/otel v1.21.0 // indirect
|
||||
go.opentelemetry.io/otel/metric v1.21.0 // indirect
|
||||
go.opentelemetry.io/otel/trace v1.21.0 // indirect
|
||||
golang.org/x/net v0.20.0 // indirect
|
||||
golang.org/x/oauth2 v0.16.0 // indirect
|
||||
golang.org/x/sync v0.6.0 // indirect
|
||||
golang.org/x/sys v0.16.0 // indirect
|
||||
google.golang.org/api v0.157.0 // indirect
|
||||
google.golang.org/appengine v1.6.8 // indirect
|
||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20240116215550-a9fa1716bcac // indirect
|
||||
google.golang.org/grpc v1.60.1 // indirect
|
||||
google.golang.org/protobuf v1.32.0 // indirect
|
||||
)
|
||||
|
||||
168
go.sum
168
go.sum
@ -1,26 +1,79 @@
|
||||
cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
|
||||
cloud.google.com/go/compute v1.23.3 h1:6sVlXXBmbd7jNX0Ipq0trII3e4n1/MsADLK6a+aiVlk=
|
||||
cloud.google.com/go/compute v1.23.3/go.mod h1:VCgBUoMnIVIR0CscqQiPJLAG25E3ZRZMzcFZeQ+h8CI=
|
||||
cloud.google.com/go/compute/metadata v0.2.3 h1:mg4jlk7mCAj6xXp9UJ4fjI9VUI5rubuGBW5aJ7UnBMY=
|
||||
cloud.google.com/go/compute/metadata v0.2.3/go.mod h1:VAV5nSsACxMJvgaAuX6Pk2AawlZn8kiOGuCv6gTkwuA=
|
||||
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
|
||||
github.com/awa/go-iap v1.32.0 h1:1rm/iz/gqU5sOQTTEwCD8IV2dRnjxeqPt+4aKr31sVg=
|
||||
github.com/awa/go-iap v1.32.0/go.mod h1:roSGnO9xHwxg8BKKnDY2gsjO9XskLZVay6+0+RY59Lg=
|
||||
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
|
||||
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
|
||||
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
|
||||
github.com/cespare/xxhash/v2 v2.2.0 h1:DC2CZ1Ep5Y4k3ZQ899DldepgrayRUGE6BBZ/cd9Cj44=
|
||||
github.com/cespare/xxhash/v2 v2.2.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
|
||||
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
|
||||
github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc=
|
||||
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=
|
||||
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f h1:lO4WD4F/rVNCu3HqELle0jiPLLBs70cWOduZpkS1E78=
|
||||
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f/go.mod h1:cuUVRXasLTGF7a8hSLbxyZXjz+1KgoB3wDUb6vlszIc=
|
||||
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=
|
||||
github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
|
||||
github.com/felixge/httpsnoop v1.0.4 h1:NFTV2Zj1bL4mc9sqWACXbQFVBBg2W3GPvqp8/ESS2Wg=
|
||||
github.com/felixge/httpsnoop v1.0.4/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U=
|
||||
github.com/fsnotify/fsnotify v1.4.9 h1:hsms1Qyu0jgnwNXIxa+/V/PDsU6CfLf6CNO8H7IWoS4=
|
||||
github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
|
||||
github.com/go-logr/logr v1.3.0 h1:2y3SDp0ZXuc6/cjLSZ+Q3ir+QB9T/iG5yYRXqsagWSY=
|
||||
github.com/go-logr/logr v1.3.0/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
|
||||
github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag=
|
||||
github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE=
|
||||
github.com/go-redis/redis/v8 v8.11.5 h1:AcZZR7igkdvfVmQTPnu9WE37LRrO/YrBH5zWyjDC0oI=
|
||||
github.com/go-redis/redis/v8 v8.11.5/go.mod h1:gREzHqY1hg6oD9ngVRbLStwAWKhA0FEgq8Jd4h5lpwo=
|
||||
github.com/golang-jwt/jwt v3.2.2+incompatible h1:IfV12K8xAKAnZqdXVzCZ+TOjboZ2keLg81eXfW3O+oY=
|
||||
github.com/golang-jwt/jwt v3.2.2+incompatible/go.mod h1:8pz2t5EyA70fFQQSrl6XZXzqecmYZeUEB8OUGHkxJ+I=
|
||||
github.com/golang-jwt/jwt/v4 v4.3.0 h1:kHL1vqdqWNfATmA0FNMdmZNMyZI1U6O31X4rlIPoBog=
|
||||
github.com/golang-jwt/jwt/v4 v4.3.0/go.mod h1:/xlHOz8bRuivTWchD4jCa+NbatV+wEUSzwAxVc6locg=
|
||||
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
|
||||
github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
|
||||
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da h1:oI5xCqsCo564l8iNU+DwB5epxmsaqB+rhGL0m5jtYqE=
|
||||
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
|
||||
github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A=
|
||||
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
|
||||
github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
|
||||
github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8=
|
||||
github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:xKAWHe0F5eneWXFV3EuXVDTCmh+JuBKY0li0aMyXATA=
|
||||
github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrUpVNzEA03Pprs=
|
||||
github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w=
|
||||
github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0=
|
||||
github.com/golang/protobuf v1.4.1/go.mod h1:U8fpvMrcmy5pZrNK1lt4xCsGvpyWQ/VVv6QDs8UjoX8=
|
||||
github.com/golang/protobuf v1.4.3/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI=
|
||||
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
|
||||
github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
|
||||
github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg=
|
||||
github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
|
||||
github.com/golang/snappy v0.0.1 h1:Qgr9rKW7uDUkrbSmQeiDsGa8SjGyCOGtuasMWwvp2P4=
|
||||
github.com/golang/snappy v0.0.1/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
|
||||
github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
|
||||
github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
|
||||
github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
|
||||
github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||
github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||
github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||
github.com/google/go-cmp v0.5.3/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
|
||||
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
|
||||
github.com/google/s2a-go v0.1.7 h1:60BLSyTrOV4/haCDW4zb1guZItoSq8foHCXrAnjBo/o=
|
||||
github.com/google/s2a-go v0.1.7/go.mod h1:50CgR4k1jNlWBu4UfS4AcfhVe1r6pdZPygJ3R8F0Qdw=
|
||||
github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||
github.com/google/uuid v1.5.0 h1:1p67kYwdtXjb0gL0BPiP1Av9wiZPo5A8z2cWkTZ+eyU=
|
||||
github.com/google/uuid v1.5.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||
github.com/googleapis/enterprise-certificate-proxy v0.3.2 h1:Vie5ybvEvT75RniqhfFxPRy3Bf7vr3h0cechB90XaQs=
|
||||
github.com/googleapis/enterprise-certificate-proxy v0.3.2/go.mod h1:VLSiSSBs/ksPL8kq3OBOQ6WRI2QnaFynd1DCjZ62+V0=
|
||||
github.com/googleapis/gax-go/v2 v2.12.0 h1:A+gCJKdRfqXkr+BIRGtZLibNXf0m1f9E4HG56etFpas=
|
||||
github.com/googleapis/gax-go/v2 v2.12.0/go.mod h1:y+aIqrI5eb1YGMVJfuV3185Ts/D7qKpsEkdD5+I6QGU=
|
||||
github.com/gorilla/websocket v1.5.0 h1:PPwGk2jz7EePpoHN/+ClbZu8SPxiqlu12wZP/3sWmnc=
|
||||
github.com/gorilla/websocket v1.5.0/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
|
||||
github.com/klauspost/compress v1.13.6 h1:P76CopJELS0TiO2mebmnzgWaajssP/EszplttgQxcgc=
|
||||
@ -45,6 +98,7 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/prometheus/client_golang v1.17.0 h1:rl2sfwZMtSthVU752MqfjQozy7blglC+1SOtjMAMh+Q=
|
||||
github.com/prometheus/client_golang v1.17.0/go.mod h1:VeL+gMmOAxkS2IqfCq0ZmHSL+LjWfWDUmp1mBz9JgUY=
|
||||
github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
|
||||
github.com/prometheus/client_model v0.4.1-0.20230718164431-9a2bf3000d16 h1:v7DLqVdK4VrYkVD5diGdl4sxJurKJEMnODWRJlxV9oM=
|
||||
github.com/prometheus/client_model v0.4.1-0.20230718164431-9a2bf3000d16/go.mod h1:oMQmHW1/JoDwqLtg57MGgP/Fb1CJEYF2imWWhWtMkYU=
|
||||
github.com/prometheus/common v0.44.0 h1:+5BrQJwiBB9xsMygAB3TNvpQKOwlkc25LbISbrdOOfY=
|
||||
@ -53,8 +107,13 @@ github.com/prometheus/procfs v0.11.1 h1:xRC8Iq1yyca5ypa9n1EZnWZkt7dwcoRPQwX/5gwa
|
||||
github.com/prometheus/procfs v0.11.1/go.mod h1:eesXgaPo1q7lBpVMoMy0ZOFTth9hBn4W/y0/p/ScXhY=
|
||||
github.com/rogpeppe/go-internal v1.10.0 h1:TMyTOH3F/DB16zRVcYyreMH6GnZZrwQVAoYjRBZyWFQ=
|
||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0=
|
||||
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
|
||||
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
|
||||
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
|
||||
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
|
||||
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
|
||||
github.com/tidwall/pretty v1.0.0 h1:HsD+QiTn7sK6flMKIvNmpqz1qrpP3Ps6jOKIKMooyg4=
|
||||
github.com/tidwall/pretty v1.0.0/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk=
|
||||
github.com/xdg-go/pbkdf2 v1.0.0 h1:Su7DPu48wXMwC3bs7MCNG+z4FhcyEuz5dlvchbq0B0c=
|
||||
@ -65,32 +124,115 @@ github.com/xdg-go/stringprep v1.0.3 h1:kdwGpVNwPFtjs98xCGkHjQtGKh86rDcRZN17QEMCO
|
||||
github.com/xdg-go/stringprep v1.0.3/go.mod h1:W3f5j4i+9rC0kuIEJL0ky1VpHXQU3ocBgklLGvcBnW8=
|
||||
github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d h1:splanxYIlg+5LfHAM6xpdFEAYOk8iySO56hMFq6uLyA=
|
||||
github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d/go.mod h1:rHwXgn7JulP+udvsHwJoVG1YGAP6VLg4y9I5dyZdqmA=
|
||||
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
|
||||
go.mongodb.org/mongo-driver v1.11.6 h1:XM7G6PjiGAO5betLF13BIa5TlLUUE3uJ/2Ox3Lz1K+o=
|
||||
go.mongodb.org/mongo-driver v1.11.6/go.mod h1:G9TgswdsWjX4tmDA5zfs2+6AEPpYJwqblyjsfuh8oXY=
|
||||
golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d h1:sK3txAijHtOK88l68nt020reeT1ZdKLIYetKl95FzVY=
|
||||
go.opencensus.io v0.24.0 h1:y73uSU6J157QMP2kn2r30vwW1A2W2WFwSCGnAVxeaD0=
|
||||
go.opencensus.io v0.24.0/go.mod h1:vNK8G9p7aAivkbmorf4v+7Hgx+Zs0yY+0fOtgBfjQKo=
|
||||
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.46.1 h1:aFJWCqJMNjENlcleuuOkGAPH82y0yULBScfXcIEdS24=
|
||||
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.46.1/go.mod h1:sEGXWArGqc3tVa+ekntsN65DmVbVeW+7lTKTjZF3/Fo=
|
||||
go.opentelemetry.io/otel v1.21.0 h1:hzLeKBZEL7Okw2mGzZ0cc4k/A7Fta0uoPgaJCr8fsFc=
|
||||
go.opentelemetry.io/otel v1.21.0/go.mod h1:QZzNPQPm1zLX4gZK4cMi+71eaorMSGT3A4znnUvNNEo=
|
||||
go.opentelemetry.io/otel/metric v1.21.0 h1:tlYWfeo+Bocx5kLEloTjbcDwBuELRrIFxwdQ36PlJu4=
|
||||
go.opentelemetry.io/otel/metric v1.21.0/go.mod h1:o1p3CA8nNHW8j5yuQLdc1eeqEaPfzug24uvsyIEJRWM=
|
||||
go.opentelemetry.io/otel/trace v1.21.0 h1:WD9i5gzvoUPuXIXH24ZNBudiarZDKuekPqi/E8fpfLc=
|
||||
go.opentelemetry.io/otel/trace v1.21.0/go.mod h1:LGbsEB0f9LGjN+OZaQQ26sohbOmiMR+BaslueVtS/qQ=
|
||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
||||
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
|
||||
golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
|
||||
golang.org/x/crypto v0.18.0 h1:PGVlW0xEltQnzFZ55hkuX5+KLyrMYhHld1YHO4AKcdc=
|
||||
golang.org/x/crypto v0.18.0/go.mod h1:R0j02AL6hcrfOiy9T4ZYp/rcWeMxM3L6QYxlOuEG1mg=
|
||||
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
|
||||
golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
|
||||
golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU=
|
||||
golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
|
||||
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
|
||||
golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||
golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||
golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||
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-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
|
||||
golang.org/x/net v0.10.0 h1:X2//UzNDwYmtCLn7To6G58Wr6f5ahEAQgKNzv9Y951M=
|
||||
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
|
||||
golang.org/x/net v0.20.0 h1:aCL9BSgETF1k+blQaYUBx9hJ9LOGP3gAVemcZlf1Kpo=
|
||||
golang.org/x/net v0.20.0/go.mod h1:z8BVo6PvndSri0LbOE3hAn0apkU+1YvI6E70E9jsnvY=
|
||||
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
|
||||
golang.org/x/oauth2 v0.16.0 h1:aDkGMBSYxElaoP81NpoUoz2oo2R2wHdZpGToUxfyQrQ=
|
||||
golang.org/x/oauth2 v0.16.0/go.mod h1:hqZ+0LWXsiVoZpeld6jVt06P3adbS2Uu911W1SsJv2o=
|
||||
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.3.0 h1:ftCYgMx6zT/asHUrPw8BLLscYtGznsLAnjq5RH9P66E=
|
||||
golang.org/x/sync v0.3.0/go.mod h1:FU7BRWz2tNW+3quACPkgCx/L+uEAv1htQ0V83Z9Rj+Y=
|
||||
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.6.0 h1:5BMeUDZ7vkXGfEr1x9B4bRcTH4lpkTkpdh0T/J+qjbQ=
|
||||
golang.org/x/sync v0.6.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
|
||||
golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.11.0 h1:eG7RXZHdqOJ1i+0lgLgCpSXAp6M3LYlAo6osgSi0xOM=
|
||||
golang.org/x/sys v0.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.16.0 h1:xWw16ngr6ZMtmxDyKyIgsE93KNKz5HKmMa3b8ALHidU=
|
||||
golang.org/x/sys v0.16.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
||||
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
|
||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
|
||||
golang.org/x/text v0.9.0 h1:2sjJmO8cDvYveuX97RDLsxlyUxLl+GHoLxBiRdHllBE=
|
||||
golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
|
||||
golang.org/x/text v0.3.8/go.mod h1:E6s5w1FMmriuDzIBO73fBruAKo1PCIq6d2Q6DHfQ8WQ=
|
||||
golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=
|
||||
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
|
||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||
golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||
golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY=
|
||||
golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
|
||||
golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q=
|
||||
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
||||
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
|
||||
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
google.golang.org/api v0.157.0 h1:ORAeqmbrrozeyw5NjnMxh7peHO0UzV4wWYSwZeCUb20=
|
||||
google.golang.org/api v0.157.0/go.mod h1:+z4v4ufbZ1WEpld6yMGHyggs+PmAHiaLNj5ytP3N01g=
|
||||
google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM=
|
||||
google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
|
||||
google.golang.org/appengine v1.6.8 h1:IhEN5q69dyKagZPYMSdIjS2HqprW324FRQZJcGqPAsM=
|
||||
google.golang.org/appengine v1.6.8/go.mod h1:1jJ3jBArFh5pcgW8gCtRJnepW8FzD1V44FJffLiz/Ds=
|
||||
google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc=
|
||||
google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc=
|
||||
google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013/go.mod h1:NbSheEEYHJ7i3ixzK3sjbqSGDJWnxyFXZblF3eUsNvo=
|
||||
google.golang.org/genproto v0.0.0-20240102182953-50ed04b92917 h1:nz5NESFLZbJGPFxDT/HCn+V1mZ8JGNoY4nUpmW/Y2eg=
|
||||
google.golang.org/genproto/googleapis/api v0.0.0-20240102182953-50ed04b92917 h1:rcS6EyEaoCO52hQDupoSfrxI3R6C2Tq741is7X8OvnM=
|
||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20240116215550-a9fa1716bcac h1:nUQEQmH/csSvFECKYRv6HWEyypysidKl2I6Qpsglq/0=
|
||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20240116215550-a9fa1716bcac/go.mod h1:daQN87bsDqDoe316QbbvX60nMoJQa4r6Ds0ZuoAe5yA=
|
||||
google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c=
|
||||
google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg=
|
||||
google.golang.org/grpc v1.25.1/go.mod h1:c3i+UQWmh7LiEpx4sFZnkU36qjEYZ0imhYfXVyQciAY=
|
||||
google.golang.org/grpc v1.27.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk=
|
||||
google.golang.org/grpc v1.33.2/go.mod h1:JMHMWHQWaTccqQQlmk3MJZS+GWXOdAesneDmEnv2fbc=
|
||||
google.golang.org/grpc v1.60.1 h1:26+wFr+cNqSGFcOXcabYC0lUVJVRa2Sb2ortSK7VrEU=
|
||||
google.golang.org/grpc v1.60.1/go.mod h1:OlCHIeLYqSSsLi6i49B5QGdzaMZK9+M7LXN2FKz4eGM=
|
||||
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=
|
||||
google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE=
|
||||
google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo=
|
||||
google.golang.org/protobuf v1.22.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
|
||||
google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
|
||||
google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
|
||||
google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c=
|
||||
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
|
||||
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
|
||||
google.golang.org/protobuf v1.31.0 h1:g0LDEJHgrBl9N9r17Ru3sqWhkIx2NB67okBHPwC7hs8=
|
||||
google.golang.org/protobuf v1.31.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
|
||||
google.golang.org/protobuf v1.32.0 h1:pPC6BG5ex8PDFnkbrGU3EixyhKcQ2aDuBS36lqK/C7I=
|
||||
google.golang.org/protobuf v1.32.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
|
||||
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/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ=
|
||||
@ -98,3 +240,5 @@ gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
|
||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
||||
honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
||||
|
||||
@ -4,12 +4,13 @@ import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"go-ayo/logger"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"repositories.action2quare.com/ayo/gocommon/logger"
|
||||
)
|
||||
|
||||
// Ref https://onestore-dev.gitbook.io/dev/tools/tools/v21/06.-api-api-v7#accesstoken
|
||||
|
||||
@ -1,7 +1,6 @@
|
||||
package logger
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"io"
|
||||
"log"
|
||||
@ -10,10 +9,12 @@ import (
|
||||
"runtime"
|
||||
"runtime/debug"
|
||||
"strings"
|
||||
|
||||
"repositories.action2quare.com/ayo/gocommon/flagx"
|
||||
)
|
||||
|
||||
var stdlogger *log.Logger
|
||||
var _ = flag.Bool("logfile", false, "")
|
||||
var UseLogFile = flagx.Bool("logfile", false, "")
|
||||
|
||||
func init() {
|
||||
binpath, _ := os.Executable()
|
||||
@ -22,16 +23,7 @@ func init() {
|
||||
var outWriter io.Writer
|
||||
outWriter = os.Stdout
|
||||
|
||||
args := os.Args
|
||||
useLogFile := false
|
||||
for _, arg := range args {
|
||||
if arg == "-logfile" {
|
||||
useLogFile = true
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if useLogFile {
|
||||
if *UseLogFile {
|
||||
ext := path.Ext(binname)
|
||||
if len(ext) > 0 {
|
||||
binname = binname[:len(binname)-len(ext)]
|
||||
|
||||
86
misc.go
86
misc.go
@ -20,15 +20,17 @@ var devflag = flagx.Bool("dev", false, "")
|
||||
|
||||
var sequenceStart = rand.Uint32()
|
||||
|
||||
func MakeHttpHandlerPattern(n ...string) string {
|
||||
r := "/" + path.Join(n...)
|
||||
if strings.HasSuffix(n[len(n)-1], "/") {
|
||||
return r + "/"
|
||||
}
|
||||
|
||||
func MakeHttpHandlerPattern(n ...string) (r string) {
|
||||
r = "/" + path.Join(n...)
|
||||
defer func() {
|
||||
for strings.Contains(r, "//") {
|
||||
r = strings.ReplaceAll(r, "//", "/")
|
||||
}
|
||||
}()
|
||||
|
||||
if strings.HasSuffix(n[len(n)-1], "/") {
|
||||
return r + "/"
|
||||
}
|
||||
|
||||
return r
|
||||
}
|
||||
@ -145,3 +147,75 @@ func FindOneInSlice[T any](in []T, compare func(elem *T) bool) (int, bool) {
|
||||
}
|
||||
return -1, false
|
||||
}
|
||||
|
||||
// RotateRight rotates the bits in the byte array to the right by n positions
|
||||
func rotateBitsRight(data []byte, n int) {
|
||||
// Normalize n to avoid unnecessary rotations
|
||||
n = n % (len(data) * 8)
|
||||
if n == 0 {
|
||||
return
|
||||
}
|
||||
|
||||
// To hold the final rotated result
|
||||
inlen := len(data)
|
||||
for k := 0; k < n/8; k++ {
|
||||
last := data[inlen-1]
|
||||
for i := 0; i < inlen-1; i++ {
|
||||
data[inlen-1-i] = data[inlen-2-i]
|
||||
}
|
||||
data[0] = last
|
||||
}
|
||||
|
||||
n = n % 8
|
||||
if n == 0 {
|
||||
return
|
||||
}
|
||||
|
||||
mask := byte(1<<n) - 1
|
||||
carry := data[0] & mask
|
||||
for i := 1; i < inlen; i++ {
|
||||
nextcarry := data[i] & mask
|
||||
data[i] = (data[i] >> n) | (carry << (8 - n))
|
||||
carry = nextcarry
|
||||
}
|
||||
data[0] = (data[0] >> n) | (carry << (8 - n))
|
||||
}
|
||||
|
||||
func rotateBitsLeft(data []byte, n int) {
|
||||
// Normalize n to avoid unnecessary rotations
|
||||
n = n % (len(data) * 8)
|
||||
if n == 0 {
|
||||
return
|
||||
}
|
||||
|
||||
// To hold the final rotated result
|
||||
inlen := len(data)
|
||||
for k := 0; k < n/8; k++ {
|
||||
last := data[0]
|
||||
for i := 0; i < inlen-1; i++ {
|
||||
data[i] = data[i+1]
|
||||
}
|
||||
data[inlen-1] = last
|
||||
}
|
||||
|
||||
n = n % 8
|
||||
if n == 0 {
|
||||
return
|
||||
}
|
||||
|
||||
mask := (byte(1<<n) - 1) << (8 - n)
|
||||
carry := data[0] & mask
|
||||
for i := inlen - 1; i >= 0; i-- {
|
||||
nextcarry := data[i] & mask
|
||||
data[i] = (data[i] << n) | (carry >> (8 - n))
|
||||
carry = nextcarry
|
||||
}
|
||||
}
|
||||
|
||||
func RotateBits(data []byte, n int) {
|
||||
if n > 0 {
|
||||
rotateBitsRight(data, n)
|
||||
} else {
|
||||
rotateBitsLeft(data, -n)
|
||||
}
|
||||
}
|
||||
|
||||
131
mongo.go
131
mongo.go
@ -21,6 +21,7 @@ import (
|
||||
type MongoClient struct {
|
||||
db *mongo.Database
|
||||
c *mongo.Client
|
||||
ctx context.Context
|
||||
}
|
||||
|
||||
type ConnectionInfo struct {
|
||||
@ -123,22 +124,26 @@ func newMongoClient(ctx context.Context, ci *ConnectionInfo) (MongoClient, error
|
||||
// }()
|
||||
|
||||
mdb := client.Database(ci.Database, nil)
|
||||
return MongoClient{c: client, db: mdb}, nil
|
||||
return MongoClient{c: client, db: mdb, ctx: ctx}, nil
|
||||
}
|
||||
|
||||
func (mc MongoClient) Connected() bool {
|
||||
func (mc *MongoClient) Connected() bool {
|
||||
return mc.db != nil && mc.c != nil
|
||||
}
|
||||
|
||||
func (mc MongoClient) Close() {
|
||||
func (mc *MongoClient) Close() {
|
||||
if mc.c != nil {
|
||||
mc.c.Disconnect(context.Background())
|
||||
mc.c.Disconnect(mc.ctx)
|
||||
}
|
||||
}
|
||||
|
||||
func (mc MongoClient) DropIndex(coll CollectionName, name string) error {
|
||||
func (mc *MongoClient) Drop() error {
|
||||
return mc.db.Drop(mc.ctx)
|
||||
}
|
||||
|
||||
func (mc *MongoClient) DropIndex(coll CollectionName, name string) error {
|
||||
matchcoll := mc.Collection(coll)
|
||||
_, err := matchcoll.Indexes().DropOne(context.Background(), name)
|
||||
_, err := matchcoll.Indexes().DropOne(mc.ctx, name)
|
||||
if commanderr, ok := err.(mongo.CommandError); ok {
|
||||
if commanderr.Code == 27 {
|
||||
// 인덱스가 없는 것이므로 그냥 성공
|
||||
@ -148,25 +153,25 @@ func (mc MongoClient) DropIndex(coll CollectionName, name string) error {
|
||||
return err
|
||||
}
|
||||
|
||||
func (mc MongoClient) Watch(coll CollectionName, pipeline mongo.Pipeline, opts ...*options.ChangeStreamOptions) (*mongo.ChangeStream, error) {
|
||||
func (mc *MongoClient) Watch(coll CollectionName, pipeline mongo.Pipeline, opts ...*options.ChangeStreamOptions) (*mongo.ChangeStream, error) {
|
||||
if len(opts) == 0 {
|
||||
opts = []*options.ChangeStreamOptions{options.ChangeStream().SetFullDocument(options.UpdateLookup).SetMaxAwaitTime(0)}
|
||||
}
|
||||
return mc.Collection(coll).Watch(context.Background(), pipeline, opts...)
|
||||
return mc.Collection(coll).Watch(mc.ctx, pipeline, opts...)
|
||||
}
|
||||
|
||||
func (mc MongoClient) Collection(collname CollectionName) *mongo.Collection {
|
||||
func (mc *MongoClient) Collection(collname CollectionName) *mongo.Collection {
|
||||
return mc.db.Collection(string(collname))
|
||||
}
|
||||
|
||||
func (mc MongoClient) AllAs(coll CollectionName, output any, opts ...*options.FindOptions) error {
|
||||
cursor, err := mc.Collection(coll).Find(context.Background(), bson.D{}, opts...)
|
||||
func (mc *MongoClient) AllAs(coll CollectionName, output any, opts ...*options.FindOptions) error {
|
||||
cursor, err := mc.Collection(coll).Find(mc.ctx, bson.D{}, opts...)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer cursor.Close(context.Background())
|
||||
defer cursor.Close(mc.ctx)
|
||||
|
||||
err = cursor.All(context.Background(), output)
|
||||
err = cursor.All(mc.ctx, output)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -174,14 +179,14 @@ func (mc MongoClient) AllAs(coll CollectionName, output any, opts ...*options.Fi
|
||||
return nil
|
||||
}
|
||||
|
||||
func (mc MongoClient) All(coll CollectionName, opts ...*options.FindOptions) ([]bson.M, error) {
|
||||
func (mc *MongoClient) All(coll CollectionName, opts ...*options.FindOptions) ([]bson.M, error) {
|
||||
var all []bson.M
|
||||
err := mc.AllAs(coll, &all, opts...)
|
||||
return all, err
|
||||
}
|
||||
|
||||
func (mc MongoClient) FindOneAndDelete(coll CollectionName, filter bson.M, opts ...*options.FindOneAndDeleteOptions) (bson.M, error) {
|
||||
result := mc.Collection(coll).FindOneAndDelete(context.Background(), filter, opts...)
|
||||
func (mc *MongoClient) FindOneAndDelete(coll CollectionName, filter bson.M, opts ...*options.FindOneAndDeleteOptions) (bson.M, error) {
|
||||
result := mc.Collection(coll).FindOneAndDelete(mc.ctx, filter, opts...)
|
||||
err := result.Err()
|
||||
if err != nil {
|
||||
if err == mongo.ErrNoDocuments {
|
||||
@ -199,8 +204,8 @@ func (mc MongoClient) FindOneAndDelete(coll CollectionName, filter bson.M, opts
|
||||
return bson.M(tmp), nil
|
||||
}
|
||||
|
||||
func (mc MongoClient) Delete(coll CollectionName, filter bson.M, opts ...*options.DeleteOptions) (bool, error) {
|
||||
r, err := mc.Collection(coll).DeleteOne(context.Background(), filter, opts...)
|
||||
func (mc *MongoClient) Delete(coll CollectionName, filter bson.M, opts ...*options.DeleteOptions) (bool, error) {
|
||||
r, err := mc.Collection(coll).DeleteOne(mc.ctx, filter, opts...)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
@ -208,20 +213,20 @@ func (mc MongoClient) Delete(coll CollectionName, filter bson.M, opts ...*option
|
||||
return r.DeletedCount > 0, nil
|
||||
}
|
||||
|
||||
func (mc MongoClient) UnsetField(coll CollectionName, filter bson.M, doc bson.M) error {
|
||||
_, err := mc.Collection(coll).UpdateOne(context.Background(), filter, bson.M{
|
||||
func (mc *MongoClient) UnsetField(coll CollectionName, filter bson.M, doc bson.M) error {
|
||||
_, err := mc.Collection(coll).UpdateOne(mc.ctx, filter, bson.M{
|
||||
"$unset": doc,
|
||||
})
|
||||
return err
|
||||
}
|
||||
|
||||
func (mc MongoClient) DeleteMany(coll CollectionName, filters bson.D, opts ...*options.DeleteOptions) (int, error) {
|
||||
func (mc *MongoClient) DeleteMany(coll CollectionName, filters bson.D, opts ...*options.DeleteOptions) (int, error) {
|
||||
if len(filters) == 0 {
|
||||
// 큰일난다
|
||||
return 0, nil
|
||||
}
|
||||
|
||||
result, err := mc.Collection(coll).DeleteMany(context.Background(), filters, opts...)
|
||||
result, err := mc.Collection(coll).DeleteMany(mc.ctx, filters, opts...)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
@ -243,8 +248,8 @@ func (c *CommandInsertMany[T]) Exec(opts ...*options.InsertManyOptions) (int, er
|
||||
return c.InsertMany(c.Collection, conv, opts...)
|
||||
}
|
||||
|
||||
func (mc MongoClient) InsertMany(coll CollectionName, documents []interface{}, opts ...*options.InsertManyOptions) (int, error) {
|
||||
result, err := mc.Collection(coll).InsertMany(context.Background(), documents, opts...)
|
||||
func (mc *MongoClient) InsertMany(coll CollectionName, documents []interface{}, opts ...*options.InsertManyOptions) (int, error) {
|
||||
result, err := mc.Collection(coll).InsertMany(mc.ctx, documents, opts...)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
@ -252,8 +257,8 @@ func (mc MongoClient) InsertMany(coll CollectionName, documents []interface{}, o
|
||||
return len(result.InsertedIDs), nil
|
||||
}
|
||||
|
||||
func (mc MongoClient) UpdateMany(coll CollectionName, filter bson.M, doc bson.M, opts ...*options.UpdateOptions) (count int, err error) {
|
||||
result, e := mc.Collection(coll).UpdateMany(context.Background(), filter, doc, opts...)
|
||||
func (mc *MongoClient) UpdateMany(coll CollectionName, filter bson.M, doc bson.M, opts ...*options.UpdateOptions) (count int, err error) {
|
||||
result, e := mc.Collection(coll).UpdateMany(mc.ctx, filter, doc, opts...)
|
||||
|
||||
if e != nil {
|
||||
return 0, e
|
||||
@ -276,8 +281,8 @@ func (m *JsonDefaultMashaller) MarshalBSON() ([]byte, error) {
|
||||
return json.Marshal(m.doc)
|
||||
}
|
||||
|
||||
func (mc MongoClient) Update(coll CollectionName, filter bson.M, doc interface{}, opts ...*options.UpdateOptions) (worked bool, newid interface{}, err error) {
|
||||
result, e := mc.Collection(coll).UpdateOne(context.Background(), filter, doc, opts...)
|
||||
func (mc *MongoClient) Update(coll CollectionName, filter bson.M, doc interface{}, opts ...*options.UpdateOptions) (worked bool, newid interface{}, err error) {
|
||||
result, e := mc.Collection(coll).UpdateOne(mc.ctx, filter, doc, opts...)
|
||||
|
||||
if e != nil {
|
||||
return false, "", e
|
||||
@ -289,7 +294,7 @@ func (mc MongoClient) Update(coll CollectionName, filter bson.M, doc interface{}
|
||||
return
|
||||
}
|
||||
|
||||
func (mc MongoClient) UpsertOne(coll CollectionName, filter bson.M, doc interface{}) (worked bool, newid interface{}, err error) {
|
||||
func (mc *MongoClient) UpsertOne(coll CollectionName, filter bson.M, doc interface{}) (worked bool, newid interface{}, err error) {
|
||||
return mc.Update(coll, filter, bson.M{
|
||||
"$set": doc,
|
||||
}, options.Update().SetUpsert(true))
|
||||
@ -299,16 +304,16 @@ func (mc MongoClient) UpsertOne(coll CollectionName, filter bson.M, doc interfac
|
||||
// }}, options.Update().SetUpsert(true))
|
||||
}
|
||||
|
||||
func (mc MongoClient) FindOneAs(coll CollectionName, filter bson.M, out interface{}, opts ...*options.FindOneOptions) error {
|
||||
err := mc.Collection(coll).FindOne(context.Background(), filter, opts...).Decode(out)
|
||||
func (mc *MongoClient) FindOneAs(coll CollectionName, filter bson.M, out interface{}, opts ...*options.FindOneOptions) error {
|
||||
err := mc.Collection(coll).FindOne(mc.ctx, filter, opts...).Decode(out)
|
||||
if err == mongo.ErrNoDocuments {
|
||||
err = nil
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func (mc MongoClient) FindOne(coll CollectionName, filter bson.M, opts ...*options.FindOneOptions) (doc bson.M, err error) {
|
||||
result := mc.Collection(coll).FindOne(context.Background(), filter, opts...)
|
||||
func (mc *MongoClient) FindOne(coll CollectionName, filter bson.M, opts ...*options.FindOneOptions) (doc bson.M, err error) {
|
||||
result := mc.Collection(coll).FindOne(mc.ctx, filter, opts...)
|
||||
tmp := make(map[string]interface{})
|
||||
err = result.Decode(&tmp)
|
||||
if err == nil {
|
||||
@ -320,8 +325,8 @@ func (mc MongoClient) FindOne(coll CollectionName, filter bson.M, opts ...*optio
|
||||
return
|
||||
}
|
||||
|
||||
func (mc MongoClient) FindOneAndUpdateAs(coll CollectionName, filter bson.M, doc bson.M, out interface{}, opts ...*options.FindOneAndUpdateOptions) error {
|
||||
result := mc.Collection(coll).FindOneAndUpdate(context.Background(), filter, doc, opts...)
|
||||
func (mc *MongoClient) FindOneAndUpdateAs(coll CollectionName, filter bson.M, doc bson.M, out interface{}, opts ...*options.FindOneAndUpdateOptions) error {
|
||||
result := mc.Collection(coll).FindOneAndUpdate(mc.ctx, filter, doc, opts...)
|
||||
err := result.Decode(out)
|
||||
if err == nil {
|
||||
return nil
|
||||
@ -334,8 +339,8 @@ func (mc MongoClient) FindOneAndUpdateAs(coll CollectionName, filter bson.M, doc
|
||||
return err
|
||||
}
|
||||
|
||||
func (mc MongoClient) FindOneAndUpdate(coll CollectionName, filter bson.M, doc bson.M, opts ...*options.FindOneAndUpdateOptions) (olddoc bson.M, err error) {
|
||||
result := mc.Collection(coll).FindOneAndUpdate(context.Background(), filter, doc, opts...)
|
||||
func (mc *MongoClient) FindOneAndUpdate(coll CollectionName, filter bson.M, doc bson.M, opts ...*options.FindOneAndUpdateOptions) (olddoc bson.M, err error) {
|
||||
result := mc.Collection(coll).FindOneAndUpdate(mc.ctx, filter, doc, opts...)
|
||||
tmp := make(map[string]interface{})
|
||||
err = result.Decode(&tmp)
|
||||
if err == nil {
|
||||
@ -347,23 +352,23 @@ func (mc MongoClient) FindOneAndUpdate(coll CollectionName, filter bson.M, doc b
|
||||
return
|
||||
}
|
||||
|
||||
func (mc MongoClient) Exists(coll CollectionName, filter bson.M) (bool, error) {
|
||||
cnt, err := mc.Collection(coll).CountDocuments(context.Background(), filter, options.Count().SetLimit(1))
|
||||
func (mc *MongoClient) Exists(coll CollectionName, filter bson.M) (bool, error) {
|
||||
cnt, err := mc.Collection(coll).CountDocuments(mc.ctx, filter, options.Count().SetLimit(1))
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
return cnt > 0, nil
|
||||
}
|
||||
|
||||
func (mc MongoClient) SearchText(coll CollectionName, text string, opts ...*options.FindOptions) ([]bson.M, error) {
|
||||
cursor, err := mc.Collection(coll).Find(context.Background(), bson.M{"$text": bson.M{"$search": text}}, opts...)
|
||||
func (mc *MongoClient) SearchText(coll CollectionName, text string, opts ...*options.FindOptions) ([]bson.M, error) {
|
||||
cursor, err := mc.Collection(coll).Find(mc.ctx, bson.M{"$text": bson.M{"$search": text}}, opts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer cursor.Close(context.Background())
|
||||
defer cursor.Close(mc.ctx)
|
||||
|
||||
var output []bson.M
|
||||
err = cursor.All(context.Background(), &output)
|
||||
err = cursor.All(mc.ctx, &output)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -371,15 +376,15 @@ func (mc MongoClient) SearchText(coll CollectionName, text string, opts ...*opti
|
||||
return output, nil
|
||||
}
|
||||
|
||||
func (mc MongoClient) FindAll(coll CollectionName, filter bson.M, opts ...*options.FindOptions) ([]bson.M, error) {
|
||||
cursor, err := mc.Collection(coll).Find(context.Background(), filter, opts...)
|
||||
func (mc *MongoClient) FindAll(coll CollectionName, filter bson.M, opts ...*options.FindOptions) ([]bson.M, error) {
|
||||
cursor, err := mc.Collection(coll).Find(mc.ctx, filter, opts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer cursor.Close(context.Background())
|
||||
defer cursor.Close(mc.ctx)
|
||||
|
||||
var output []bson.M
|
||||
err = cursor.All(context.Background(), &output)
|
||||
err = cursor.All(mc.ctx, &output)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -387,29 +392,29 @@ func (mc MongoClient) FindAll(coll CollectionName, filter bson.M, opts ...*optio
|
||||
return output, nil
|
||||
}
|
||||
|
||||
func (mc MongoClient) FindAllAs(coll CollectionName, filter bson.M, output interface{}, opts ...*options.FindOptions) error {
|
||||
cursor, err := mc.Collection(coll).Find(context.Background(), filter, opts...)
|
||||
func (mc *MongoClient) FindAllAs(coll CollectionName, filter bson.M, output interface{}, opts ...*options.FindOptions) error {
|
||||
cursor, err := mc.Collection(coll).Find(mc.ctx, filter, opts...)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer cursor.Close(context.Background())
|
||||
defer cursor.Close(mc.ctx)
|
||||
|
||||
err = cursor.All(context.Background(), output)
|
||||
err = cursor.All(mc.ctx, output)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (mc MongoClient) MakeExpireIndex(coll CollectionName, expireSeconds int32) error {
|
||||
func (mc *MongoClient) MakeExpireIndex(coll CollectionName, expireSeconds int32) error {
|
||||
matchcoll := mc.Collection(coll)
|
||||
indices, err := matchcoll.Indexes().List(context.Background(), options.ListIndexes().SetMaxTime(time.Second))
|
||||
indices, err := matchcoll.Indexes().List(mc.ctx, options.ListIndexes().SetMaxTime(time.Second))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
allindices := make([]interface{}, 0)
|
||||
err = indices.All(context.Background(), &allindices)
|
||||
err = indices.All(mc.ctx, &allindices)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -441,7 +446,7 @@ IndexSearchLabel:
|
||||
if exp == expireSeconds {
|
||||
return nil
|
||||
}
|
||||
_, err = matchcoll.Indexes().DropOne(context.Background(), tsname)
|
||||
_, err = matchcoll.Indexes().DropOne(mc.ctx, tsname)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -452,24 +457,24 @@ IndexSearchLabel:
|
||||
Options: options.Index().SetExpireAfterSeconds(expireSeconds),
|
||||
}
|
||||
|
||||
_, err = matchcoll.Indexes().CreateOne(context.Background(), mod)
|
||||
_, err = matchcoll.Indexes().CreateOne(mc.ctx, mod)
|
||||
return err
|
||||
}
|
||||
|
||||
func (mc MongoClient) makeIndicesWithOption(coll CollectionName, indices map[string]bson.D, opts ...*options.IndexOptions) error {
|
||||
func (mc *MongoClient) makeIndicesWithOption(coll CollectionName, indices map[string]bson.D, opts ...*options.IndexOptions) error {
|
||||
collection := mc.Collection(coll)
|
||||
cursor, err := collection.Indexes().List(context.Background(), options.ListIndexes().SetMaxTime(time.Second))
|
||||
cursor, err := collection.Indexes().List(mc.ctx, options.ListIndexes().SetMaxTime(time.Second))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer cursor.Close(context.Background())
|
||||
defer cursor.Close(mc.ctx)
|
||||
|
||||
found := make(map[string]bool)
|
||||
for k := range indices {
|
||||
found[k] = false
|
||||
}
|
||||
|
||||
for cursor.TryNext(context.Background()) {
|
||||
for cursor.TryNext(mc.ctx) {
|
||||
rawval := cursor.Current
|
||||
name := rawval.Lookup("name").StringValue()
|
||||
if _, ok := indices[name]; ok {
|
||||
@ -493,7 +498,7 @@ func (mc MongoClient) makeIndicesWithOption(coll CollectionName, indices map[str
|
||||
}
|
||||
}
|
||||
|
||||
_, err = collection.Indexes().CreateOne(context.Background(), mod)
|
||||
_, err = collection.Indexes().CreateOne(mc.ctx, mod)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -502,10 +507,10 @@ func (mc MongoClient) makeIndicesWithOption(coll CollectionName, indices map[str
|
||||
return nil
|
||||
}
|
||||
|
||||
func (mc MongoClient) MakeUniqueIndices(coll CollectionName, indices map[string]bson.D, opts ...*options.IndexOptions) error {
|
||||
func (mc *MongoClient) MakeUniqueIndices(coll CollectionName, indices map[string]bson.D, opts ...*options.IndexOptions) error {
|
||||
return mc.makeIndicesWithOption(coll, indices, append(opts, options.Index().SetUnique(true))...)
|
||||
}
|
||||
|
||||
func (mc MongoClient) MakeIndices(coll CollectionName, indices map[string]bson.D, opts ...*options.IndexOptions) error {
|
||||
func (mc *MongoClient) MakeIndices(coll CollectionName, indices map[string]bson.D, opts ...*options.IndexOptions) error {
|
||||
return mc.makeIndicesWithOption(coll, indices, opts...)
|
||||
}
|
||||
|
||||
@ -1,8 +1,15 @@
|
||||
package gocommon
|
||||
|
||||
import (
|
||||
"crypto/md5"
|
||||
"encoding/hex"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"os"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"repositories.action2quare.com/ayo/gocommon/flagx"
|
||||
@ -58,14 +65,58 @@ func MonitorConfig[T any](onChanged func(newconf *T)) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func LoadConfig[T any](outptr *T) error {
|
||||
configfilepath := configFilePath()
|
||||
content, err := os.ReadFile(configfilepath)
|
||||
if os.IsNotExist(err) {
|
||||
return os.WriteFile(configfilepath, []byte("{}"), 0666)
|
||||
var configContents []byte
|
||||
|
||||
func splitURL(inputURL string) (string, string, error) {
|
||||
parsedURL, err := url.Parse(inputURL)
|
||||
if err != nil {
|
||||
return "", "", err
|
||||
}
|
||||
|
||||
return json.Unmarshal(content, outptr)
|
||||
base := fmt.Sprintf("%s://%s", parsedURL.Scheme, parsedURL.Host)
|
||||
path := parsedURL.Path
|
||||
|
||||
return base, path, nil
|
||||
}
|
||||
|
||||
func LoadConfig[T any](outptr *T) error {
|
||||
configfilepath := configFilePath()
|
||||
if len(configContents) == 0 {
|
||||
if strings.HasPrefix(configfilepath, "http") {
|
||||
// 여기서 다운받음
|
||||
_, subpath, err := splitURL(configfilepath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
h := md5.New()
|
||||
h.Write([]byte(subpath))
|
||||
at := hex.EncodeToString(h.Sum(nil))
|
||||
|
||||
req, _ := http.NewRequest("GET", configfilepath, nil)
|
||||
req.Header.Add("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/111.0.0.0 Safari/537.36 Edg/111.0.1661.51")
|
||||
req.Header.Add("As-X-UrlHash", at)
|
||||
|
||||
resp, err := http.DefaultClient.Do(req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
configContents, err = io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
content, _ := os.ReadFile(configfilepath)
|
||||
if len(content) == 0 {
|
||||
content = []byte("{}")
|
||||
}
|
||||
|
||||
configContents = content
|
||||
}
|
||||
}
|
||||
|
||||
return json.Unmarshal([]byte(os.ExpandEnv(string(configContents))), outptr)
|
||||
}
|
||||
|
||||
type StorageAddr struct {
|
||||
|
||||
51
server.go
51
server.go
@ -106,12 +106,42 @@ func welcomeHandler(w http.ResponseWriter, r *http.Request) {
|
||||
w.Write([]byte("welcome"))
|
||||
}
|
||||
|
||||
var tls = flagx.String("tls", "", "")
|
||||
var tlsflag = flagx.String("tls", "", "")
|
||||
var portptr = flagx.Int("port", 80, "")
|
||||
|
||||
func isTlsEnabled(fileout ...*string) bool {
|
||||
if len(*tlsflag) == 0 {
|
||||
return false
|
||||
}
|
||||
|
||||
if strings.HasSuffix(*tlsflag, "/") {
|
||||
return false
|
||||
}
|
||||
|
||||
crtfile := *tlsflag + ".crt"
|
||||
if _, err := os.Stat(crtfile); os.IsNotExist(err) {
|
||||
return false
|
||||
}
|
||||
|
||||
keyfile := *tlsflag + ".key"
|
||||
if _, err := os.Stat(keyfile); os.IsNotExist(err) {
|
||||
return false
|
||||
}
|
||||
|
||||
if len(fileout) > 0 {
|
||||
*fileout[0] = crtfile
|
||||
}
|
||||
|
||||
if len(fileout) > 1 {
|
||||
*fileout[1] = keyfile
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
// NewHTTPServer :
|
||||
func NewHTTPServerWithPort(serveMux *http.ServeMux, port int) *Server {
|
||||
if len(*tls) > 0 && port == 80 {
|
||||
if isTlsEnabled() && port == 80 {
|
||||
port = 443
|
||||
}
|
||||
addr := fmt.Sprintf(":%d", port)
|
||||
@ -130,7 +160,7 @@ func NewHTTPServerWithPort(serveMux *http.ServeMux, port int) *Server {
|
||||
func NewHTTPServer(serveMux *http.ServeMux) *Server {
|
||||
|
||||
// 시작시 자동으로 enable됨
|
||||
if len(*tls) > 0 && *portptr == 80 {
|
||||
if isTlsEnabled() && *portptr == 80 {
|
||||
*portptr = 443
|
||||
}
|
||||
return NewHTTPServerWithPort(serveMux, *portptr)
|
||||
@ -198,12 +228,13 @@ func (server *Server) Start() error {
|
||||
defer proxyListener.Close()
|
||||
|
||||
var err error
|
||||
if len(*tls) > 0 {
|
||||
crtfile := *tls + ".crt"
|
||||
keyfile := *tls + ".key"
|
||||
var crtfile string
|
||||
var keyfile string
|
||||
if isTlsEnabled(&crtfile, &keyfile) {
|
||||
logger.Println("tls enabled :", crtfile, keyfile)
|
||||
err = server.httpserver.ServeTLS(proxyListener, crtfile, keyfile)
|
||||
} else {
|
||||
logger.Println("tls disabled")
|
||||
err = server.httpserver.Serve(proxyListener)
|
||||
}
|
||||
|
||||
@ -795,6 +826,14 @@ func (hc *HttpApiBroker) AddHandler(receiver HttpApiHandler) {
|
||||
}
|
||||
}
|
||||
|
||||
func (hc *HttpApiBroker) AllMethodNames() (out []string) {
|
||||
out = make([]string, 0, len(hc.methods))
|
||||
for name := range hc.methods {
|
||||
out = append(out, name)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (hc *HttpApiBroker) CallByHeader(w http.ResponseWriter, r *http.Request) {
|
||||
funcname := r.Header.Get("AS-X-CALL")
|
||||
if len(funcname) == 0 {
|
||||
|
||||
@ -74,6 +74,10 @@ func make_storagekey(acc primitive.ObjectID) storagekey {
|
||||
return storagekey(acc.Hex() + hex.EncodeToString(bs[2:]))
|
||||
}
|
||||
|
||||
func AccountToSessionKey(acc primitive.ObjectID) string {
|
||||
return string(make_storagekey(acc))
|
||||
}
|
||||
|
||||
func storagekey_to_publickey(sk storagekey) publickey {
|
||||
bs, _ := hex.DecodeString(string(sk))
|
||||
|
||||
|
||||
@ -7,7 +7,6 @@ import (
|
||||
"strings"
|
||||
"unsafe"
|
||||
|
||||
"github.com/gorilla/websocket"
|
||||
"repositories.action2quare.com/ayo/gocommon/logger"
|
||||
)
|
||||
|
||||
@ -17,7 +16,7 @@ const (
|
||||
)
|
||||
|
||||
type apiFuncType func(ApiCallContext)
|
||||
type connFuncType func(*websocket.Conn, *Sender)
|
||||
type connFuncType func(*Conn, *Sender)
|
||||
type disconnFuncType func(string, *Sender)
|
||||
|
||||
type WebsocketApiHandler struct {
|
||||
@ -53,7 +52,7 @@ func MakeWebsocketApiHandler[T any](receiver *T, receiverName string) WebsocketA
|
||||
if method.Type.NumIn() != 3 {
|
||||
continue
|
||||
}
|
||||
if method.Type.In(1) != reflect.TypeOf((*websocket.Conn)(nil)) {
|
||||
if method.Type.In(1) != reflect.TypeOf((*Conn)(nil)) {
|
||||
continue
|
||||
}
|
||||
if method.Type.In(2) != reflect.TypeOf((*Sender)(nil)) {
|
||||
@ -62,9 +61,9 @@ func MakeWebsocketApiHandler[T any](receiver *T, receiverName string) WebsocketA
|
||||
funcptr := method.Func.Pointer()
|
||||
p1 := unsafe.Pointer(&funcptr)
|
||||
p2 := unsafe.Pointer(&p1)
|
||||
connfuncptr := (*func(*T, *websocket.Conn, *Sender))(p2)
|
||||
connfuncptr := (*func(*T, *Conn, *Sender))(p2)
|
||||
|
||||
connfunc = func(c *websocket.Conn, s *Sender) {
|
||||
connfunc = func(c *Conn, s *Sender) {
|
||||
(*connfuncptr)(receiver, c, s)
|
||||
}
|
||||
} else if method.Name == ClientDisconnected {
|
||||
|
||||
@ -10,9 +10,11 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"net"
|
||||
"net/http"
|
||||
"strings"
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
"time"
|
||||
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
@ -27,12 +29,94 @@ import (
|
||||
|
||||
var noAuthFlag = flagx.Bool("noauth", false, "")
|
||||
|
||||
type Conn struct {
|
||||
innerConn *websocket.Conn
|
||||
spinLock int32
|
||||
}
|
||||
|
||||
func makeConn(conn *websocket.Conn) *Conn {
|
||||
return &Conn{
|
||||
innerConn: conn,
|
||||
spinLock: 0,
|
||||
}
|
||||
}
|
||||
|
||||
type wsconn struct {
|
||||
*websocket.Conn
|
||||
*Conn
|
||||
sender *Sender
|
||||
closeMessage string
|
||||
}
|
||||
|
||||
type noCopy struct{}
|
||||
type websocketWriter struct {
|
||||
_ noCopy
|
||||
innerConn *websocket.Conn
|
||||
spinLock *int32
|
||||
fingerprint int32
|
||||
}
|
||||
|
||||
func (c websocketWriter) writeImpl(vf func() error) error {
|
||||
defer atomic.StoreInt32(c.spinLock, 0)
|
||||
|
||||
for i := int64(0); ; i++ {
|
||||
if atomic.CompareAndSwapInt32(c.spinLock, 0, c.fingerprint) {
|
||||
return vf()
|
||||
}
|
||||
|
||||
time.Sleep(time.Microsecond)
|
||||
if i >= int64(time.Second/time.Microsecond) && i&int64(time.Second/time.Microsecond) == 0 {
|
||||
// 1초동안 락 실패
|
||||
logger.Println("websocket write lock failed : ", i/int64(time.Second/time.Microsecond))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (c websocketWriter) WriteJSON(v interface{}) error {
|
||||
return c.writeImpl(func() error { return c.innerConn.WriteJSON(v) })
|
||||
}
|
||||
|
||||
func (c websocketWriter) WriteMessage(messageType int, data []byte) error {
|
||||
return c.writeImpl(func() error { return c.innerConn.WriteMessage(messageType, data) })
|
||||
}
|
||||
|
||||
func (c websocketWriter) WritePreparedMessage(pm *websocket.PreparedMessage) error {
|
||||
return c.writeImpl(func() error { return c.innerConn.WritePreparedMessage(pm) })
|
||||
}
|
||||
|
||||
func (c websocketWriter) WriteControl(messageType int, data []byte, deadline time.Time) error {
|
||||
return c.writeImpl(func() error { return c.innerConn.WriteControl(messageType, data, deadline) })
|
||||
}
|
||||
|
||||
func (c *Conn) SetReadDeadline(t time.Time) error {
|
||||
return c.innerConn.SetReadDeadline(t)
|
||||
}
|
||||
|
||||
func (c *Conn) Close() error {
|
||||
return c.innerConn.Close()
|
||||
}
|
||||
|
||||
func (c *Conn) ReadMessage() (messageType int, p []byte, err error) {
|
||||
return c.innerConn.ReadMessage()
|
||||
}
|
||||
|
||||
func (c *Conn) RemoteAddr() net.Addr {
|
||||
return c.innerConn.RemoteAddr()
|
||||
}
|
||||
|
||||
func (c *Conn) NextReader() (messageType int, r io.Reader, err error) {
|
||||
return c.innerConn.NextReader()
|
||||
}
|
||||
|
||||
var websocketWriterSeq = int32(1)
|
||||
|
||||
func (c *Conn) MakeWriter() websocketWriter {
|
||||
return websocketWriter{
|
||||
innerConn: c.innerConn,
|
||||
spinLock: &c.spinLock,
|
||||
fingerprint: atomic.AddInt32(&websocketWriterSeq, 1),
|
||||
}
|
||||
}
|
||||
|
||||
type UpstreamMessage struct {
|
||||
Alias string
|
||||
Accid primitive.ObjectID
|
||||
@ -82,7 +166,7 @@ type EventReceiver interface {
|
||||
}
|
||||
|
||||
type send_msg_queue_elem struct {
|
||||
to *websocket.Conn
|
||||
to *Conn
|
||||
pmsg *websocket.PreparedMessage
|
||||
//msg []byte
|
||||
}
|
||||
@ -148,7 +232,7 @@ func NewWebsocketHandler(consumer session.Consumer, redisUrl string) (*Websocket
|
||||
return
|
||||
}
|
||||
|
||||
elem.to.WritePreparedMessage(elem.pmsg)
|
||||
elem.to.MakeWriter().WritePreparedMessage(elem.pmsg)
|
||||
}
|
||||
|
||||
for elem := range sendchan {
|
||||
@ -197,7 +281,7 @@ func (ws *WebsocketHandler) SendUpstreamMessage(msg *UpstreamMessage) {
|
||||
ws.localDeliveryChan <- msg
|
||||
}
|
||||
|
||||
func (ws *WebsocketHandler) WriteDirectMessage(c *websocket.Conn, messageType int, data []byte) {
|
||||
func (ws *WebsocketHandler) WriteDirectMessage(c *Conn, messageType int, data []byte) {
|
||||
pmsg, _ := websocket.NewPreparedMessage(messageType, data)
|
||||
ws.sendMsgChan <- send_msg_queue_elem{
|
||||
to: c,
|
||||
@ -479,13 +563,13 @@ func (ws *WebsocketHandler) mainLoop(ctx context.Context) {
|
||||
|
||||
case accid := <-ws.forceCloseChan:
|
||||
if conn := entireConns[accid.Hex()]; conn != nil {
|
||||
conn.WriteControl(websocket.CloseMessage, unauthdata, time.Time{})
|
||||
conn.MakeWriter().WriteControl(websocket.CloseMessage, unauthdata, time.Time{})
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func upgrade_core(ws *WebsocketHandler, conn *websocket.Conn, accid primitive.ObjectID, alias string) {
|
||||
func upgrade_core(ws *WebsocketHandler, conn *Conn, accid primitive.ObjectID, alias string) {
|
||||
newconn := &wsconn{
|
||||
Conn: conn,
|
||||
sender: &Sender{
|
||||
@ -503,7 +587,7 @@ func upgrade_core(ws *WebsocketHandler, conn *websocket.Conn, accid primitive.Ob
|
||||
}()
|
||||
|
||||
for {
|
||||
messageType, r, err := c.NextReader()
|
||||
messageType, r, err := c.innerConn.NextReader()
|
||||
if err != nil {
|
||||
if ce, ok := err.(*websocket.CloseError); ok {
|
||||
c.closeMessage = ce.Text
|
||||
@ -596,7 +680,7 @@ func (ws *WebsocketHandler) upgrade_nosession(w http.ResponseWriter, r *http.Req
|
||||
alias = accid.Hex()
|
||||
}
|
||||
|
||||
upgrade_core(ws, conn, accid, alias)
|
||||
upgrade_core(ws, makeConn(conn), accid, alias)
|
||||
}
|
||||
|
||||
func (ws *WebsocketHandler) upgrade(w http.ResponseWriter, r *http.Request) {
|
||||
@ -643,5 +727,5 @@ func (ws *WebsocketHandler) upgrade(w http.ResponseWriter, r *http.Request) {
|
||||
alias = authinfo.Account.Hex()
|
||||
}
|
||||
|
||||
upgrade_core(ws, conn, authinfo.Account, alias)
|
||||
upgrade_core(ws, makeConn(conn), authinfo.Account, alias)
|
||||
}
|
||||
|
||||
@ -23,7 +23,7 @@ type WebsocketPeerHandler interface {
|
||||
|
||||
type peerCtorChannelValue struct {
|
||||
accid primitive.ObjectID
|
||||
conn *websocket.Conn
|
||||
conn *Conn
|
||||
}
|
||||
|
||||
type peerDtorChannelValue struct {
|
||||
@ -42,7 +42,7 @@ type websocketPeerHandler[T PeerInterface] struct {
|
||||
|
||||
type PeerInterface interface {
|
||||
ClientDisconnected(string)
|
||||
ClientConnected(*websocket.Conn)
|
||||
ClientConnected(*Conn)
|
||||
}
|
||||
type peerApiFuncType[T PeerInterface] func(T, io.Reader) (any, error)
|
||||
|
||||
@ -182,7 +182,7 @@ func (ws *websocketPeerHandler[T]) onSessionInvalidated(accid primitive.ObjectID
|
||||
}
|
||||
|
||||
func (ws *websocketPeerHandler[T]) sessionMonitoring() {
|
||||
all := make(map[primitive.ObjectID]*websocket.Conn)
|
||||
all := make(map[primitive.ObjectID]*Conn)
|
||||
unauthdata := []byte{0x03, 0xec}
|
||||
unauthdata = append(unauthdata, []byte("unauthorized")...)
|
||||
for {
|
||||
@ -191,7 +191,7 @@ func (ws *websocketPeerHandler[T]) sessionMonitoring() {
|
||||
all[estVal.accid] = estVal.conn
|
||||
case disVal := <-ws.peerDtorChannel:
|
||||
if c := all[disVal.accid]; c != nil {
|
||||
c.WriteControl(websocket.CloseMessage, unauthdata, time.Time{})
|
||||
c.MakeWriter().WriteControl(websocket.CloseMessage, unauthdata, time.Time{})
|
||||
delete(all, disVal.accid)
|
||||
}
|
||||
|
||||
@ -203,8 +203,8 @@ func (ws *websocketPeerHandler[T]) sessionMonitoring() {
|
||||
}
|
||||
}
|
||||
|
||||
func (ws *websocketPeerHandler[T]) upgrade_core(conn *websocket.Conn, accid primitive.ObjectID, sk string) {
|
||||
go func(c *websocket.Conn, accid primitive.ObjectID, sk string) {
|
||||
func (ws *websocketPeerHandler[T]) upgrade_core(conn *Conn, accid primitive.ObjectID, sk string) {
|
||||
go func(c *Conn, accid primitive.ObjectID, sk string) {
|
||||
peer := ws.createPeer(accid)
|
||||
var closeReason string
|
||||
|
||||
@ -217,6 +217,7 @@ func (ws *websocketPeerHandler[T]) upgrade_core(conn *websocket.Conn, accid prim
|
||||
}()
|
||||
|
||||
response := make([]byte, 255)
|
||||
writer := c.MakeWriter()
|
||||
for {
|
||||
response = response[:5]
|
||||
messageType, r, err := c.NextReader()
|
||||
@ -277,7 +278,7 @@ func (ws *websocketPeerHandler[T]) upgrade_core(conn *websocket.Conn, accid prim
|
||||
if err != nil {
|
||||
logger.Println("websocket.NewPreparedMessage failed :", err)
|
||||
} else {
|
||||
c.WritePreparedMessage(pmsg)
|
||||
writer.WritePreparedMessage(pmsg)
|
||||
}
|
||||
} else {
|
||||
cmd := make([]byte, flag[0])
|
||||
@ -346,7 +347,7 @@ func (ws *websocketPeerHandler[T]) upgrade_noauth(w http.ResponseWriter, r *http
|
||||
// alias = accid.Hex()
|
||||
// }
|
||||
|
||||
ws.upgrade_core(conn, accid, sk)
|
||||
ws.upgrade_core(&Conn{innerConn: conn}, accid, sk)
|
||||
}
|
||||
|
||||
func (ws *websocketPeerHandler[T]) upgrade(w http.ResponseWriter, r *http.Request) {
|
||||
@ -387,5 +388,5 @@ func (ws *websocketPeerHandler[T]) upgrade(w http.ResponseWriter, r *http.Reques
|
||||
// } else {
|
||||
// alias = authinfo.Account.Hex()
|
||||
// }
|
||||
ws.upgrade_core(conn, authinfo.Account, sk)
|
||||
ws.upgrade_core(makeConn(conn), authinfo.Account, sk)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user