large refactor, fixes #2
This commit is contained in:
24
server/internal/utils/array.go
Normal file
24
server/internal/utils/array.go
Normal file
@ -0,0 +1,24 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
)
|
||||
|
||||
func ArrayIn(val interface{}, array interface{}) (exists bool, index int) {
|
||||
exists = false
|
||||
index = -1
|
||||
|
||||
switch reflect.TypeOf(array).Kind() {
|
||||
case reflect.Slice:
|
||||
s := reflect.ValueOf(array)
|
||||
for i := 0; i < s.Len(); i++ {
|
||||
if reflect.DeepEqual(val, s.Index(i).Interface()) == true {
|
||||
index = i
|
||||
exists = true
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return
|
||||
}
|
@ -1,10 +0,0 @@
|
||||
package utils
|
||||
|
||||
const Header = `&34
|
||||
_ __ __
|
||||
/ | / /__ / /______ \ /\
|
||||
/ |/ / _ \/ //_/ __ \ ) ( ')
|
||||
/ /| / __/ ,< / /_/ / ( / )
|
||||
/_/ |_/\___/_/|_|\____/ \(__)|
|
||||
&1&37 nurdism/neko &33%s v%s&0
|
||||
`
|
10
server/internal/utils/json.go
Normal file
10
server/internal/utils/json.go
Normal file
@ -0,0 +1,10 @@
|
||||
package utils
|
||||
|
||||
import "encoding/json"
|
||||
|
||||
func Unmarshal(in interface{}, raw []byte, callback func() error) error {
|
||||
if err := json.Unmarshal(raw, &in); err != nil {
|
||||
return err
|
||||
}
|
||||
return callback()
|
||||
}
|
@ -1,25 +0,0 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
)
|
||||
|
||||
type CountedSyncMap struct {
|
||||
sync.Map
|
||||
len uint64
|
||||
}
|
||||
|
||||
func (m *CountedSyncMap) CountedDelete(key interface{}) {
|
||||
m.Delete(key)
|
||||
atomic.AddUint64(&m.len, ^uint64(0))
|
||||
}
|
||||
|
||||
func (m *CountedSyncMap) CountedStore(key, value interface{}) {
|
||||
m.Store(key, value)
|
||||
atomic.AddUint64(&m.len, uint64(1))
|
||||
}
|
||||
|
||||
func (m *CountedSyncMap) CountedLen() uint64 {
|
||||
return atomic.LoadUint64(&m.len)
|
||||
}
|
Reference in New Issue
Block a user