]> 127.0.0.1 Git - part/.git/commitdiff
1 (#52) v0.28.20250509205808
authorqydysky <qydysky@foxmail.com>
Fri, 9 May 2025 20:57:59 +0000 (04:57 +0800)
committerGitHub <noreply@github.com>
Fri, 9 May 2025 20:57:59 +0000 (04:57 +0800)
map/map.go
reqf/cookie.go
sync/Map.go

index 5af80bea82444eaba0b96b02ff71cbb1d0aef46d..209e278b4eb19568e0ae0a0ee56deaa57a7a6c16 100644 (file)
@@ -1,24 +1,10 @@
 package part
 
-import (
-       "sync"
-)
-
-type Map struct{
-       m sync.Map
-       New func()interface{}
-}
-
-func (t *Map) Get(key interface{})interface{}{
-       if val,ok := t.m.Load(key);ok{return val}
-       return t.Set(key, t.New())
+func Contains[T comparable, S any](s map[T]S, keys ...T) (missKey []T) {
+       for _, tk := range keys {
+               if _, ok := s[tk]; !ok {
+                       missKey = append(missKey, tk)
+               }
+       }
+       return
 }
-
-func (t *Map) Del(key interface{}){
-       t.m.Delete(key)
-}
-
-func (t *Map) Set(key interface{},val interface{})interface{}{
-       t.m.Store(key, val)
-       return val
-}
\ No newline at end of file
index 7e8cf1e9cecf7d87a5bfc5a1f9602a7810821b45..fb06caeeb25ef3f936b86b145307a16bf9ca76b5 100644 (file)
@@ -2,6 +2,7 @@ package part
 
 import (
        "encoding/json"
+       "iter"
        "net"
        "net/http"
        "strings"
@@ -91,6 +92,15 @@ func Cookies_String_2_Map(Cookies string) (o map[string]string) {
        return
 }
 
+func Iter_2_Cookies_String(Cookies iter.Seq2[string, string]) (o string) {
+       for k, v := range Cookies {
+               o += k + `=` + v + `; `
+       }
+       t := []rune(o)
+       o = string(t[:len(t)-2])
+       return
+}
+
 func Map_2_Cookies_String(Cookies map[string]string) (o string) {
        if len(Cookies) == 0 {
                return ""
index 10eb6d4316bedef9f6b5b922b2c0c2d5ea684e5c..88fc369c8ede8359acac32a7d700e438bdcd6464 100644 (file)
@@ -122,3 +122,18 @@ func Copy[T comparable, S any](s map[T]S) map[T]S {
        }
        return t
 }
+
+func StoreAll[T comparable, S any, A, B any](d MapFunc[A, B], s map[T]S) {
+       for k, v := range s {
+               d.Store(any(k).(A), any(v).(B))
+       }
+}
+
+func Contains[A, B any](m MapFunc[A, B], keys ...A) (missKey []A) {
+       for _, tk := range keys {
+               if _, ok := m.Load(tk); !ok {
+                       missKey = append(missKey, tk)
+               }
+       }
+       return
+}