good morning!!!!

Skip to content
Snippets Groups Projects
Verified Commit 1307aee2 authored by a's avatar a
Browse files

reduce dep

parent e4663fef
No related branches found
No related tags found
No related merge requests found
Pipeline #25945 failed
......@@ -4,8 +4,6 @@ import (
"regexp"
"strings"
"unicode"
"github.com/davecgh/go-spew/spew"
)
func SanitizeBackticks(s string) string {
......@@ -21,10 +19,6 @@ func Slice(val []interface{}, index int) interface{} {
return val[index]
}
func Inpect(val interface{}) string {
return spew.Sdump(val)
}
func CamelCase(name string) string {
var in []string
if strings.Contains(name, " ") {
......
......@@ -8,8 +8,6 @@ require (
gfx.cafe/util/go/frand v0.0.0-20230721185457-c559e86c829c
gfx.cafe/util/go/generic v0.0.0-20230721185457-c559e86c829c
github.com/alecthomas/kong v0.8.0
github.com/davecgh/go-spew v1.1.1
github.com/deckarep/golang-set v1.8.0
github.com/go-faster/jx v1.1.0
github.com/goccy/go-json v0.10.2
github.com/iancoleman/strcase v0.3.0
......@@ -20,6 +18,7 @@ require (
require (
github.com/aead/chacha20 v0.0.0-20180709150244-8b13a72661da // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/go-faster/errors v0.6.1 // indirect
github.com/klauspost/compress v1.16.7 // indirect
github.com/kr/pretty v0.3.1 // indirect
......
......@@ -7,10 +7,10 @@ import (
"sync/atomic"
"gfx.cafe/open/jrpc/pkg/codec"
"gfx.cafe/open/jrpc/pkg/util/mapset"
"gfx.cafe/util/go/bufpool"
mapset "github.com/deckarep/golang-set"
"github.com/go-faster/jx"
"github.com/goccy/go-json"
)
......@@ -19,7 +19,7 @@ import (
type Server struct {
services codec.Handler
run int32
codecs mapset.Set
codecs *mapset.Set[codec.ReaderWriter]
Tracing Tracing
}
......@@ -30,7 +30,7 @@ type Tracing struct {
// NewServer creates a new server instance with no registered handlers.
func NewServer(r codec.Handler) *Server {
server := &Server{
codecs: mapset.NewSet(),
codecs: mapset.NewSet[codec.ReaderWriter](),
run: 1,
}
server.services = r
......@@ -175,8 +175,8 @@ func (s *Server) ServeCodec(pctx context.Context, remote codec.ReaderWriter) {
// subscriptions.
func (s *Server) Stop() {
if atomic.CompareAndSwapInt32(&s.run, 1, 0) {
s.codecs.Each(func(c any) bool {
c.(codec.ReaderWriter).Close()
s.codecs.Each(func(c codec.ReaderWriter) bool {
c.Close()
return true
})
}
......
package mapset
import "sync"
type Set[T comparable] struct {
m map[T]struct{}
mu sync.RWMutex
}
func NewSet[T comparable]() *Set[T] {
return &Set[T]{
m: make(map[T]struct{}),
}
}
func (s *Set[T]) Add(x T) {
s.mu.Lock()
defer s.mu.Unlock()
s.m[x] = struct{}{}
}
func (s *Set[T]) Remove(x T) {
s.mu.Lock()
defer s.mu.Unlock()
delete(s.m, x)
}
func (s *Set[T]) Each(fn func(x T) bool) {
for k := range s.m {
if !fn(k) {
return
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment