From 1810cc07d8ce956830490226659f60697c12706c Mon Sep 17 00:00:00 2001 From: guzeng Date: Mon, 21 Jun 2021 13:51:00 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0getall=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cache.go | 26 ++++++++++++++++---------- go.mod | 6 ++++++ go.sum | 27 +++++++++++++++++++++++++++ 3 files changed, 49 insertions(+), 10 deletions(-) create mode 100644 go.sum diff --git a/cache.go b/cache.go index c4f7a5a..cdf3b58 100644 --- a/cache.go +++ b/cache.go @@ -3,6 +3,7 @@ package site import ( "encoding/json" "errors" + "log" "git.tetele.net/tgo/redisrpc" ) @@ -60,31 +61,36 @@ func SetToRedis(host string, site map[string]string) error { return err } -/* +/**/ func GetAll() ([]map[string]string, error) { list, err := redisrpc.HGetAll(SITE_KEY) if err != nil { return nil, err } + var siteInfo map[string]string var all []map[string]string if len(list) > 0 { - for key, item := range list { - if (key+1)%2 == 0 { //只处理偶数位 - siteInfo = make(map[string]string) - err = json.Unmarshal(item, &siteInfo) + for _, item := range list { + siteInfo = make(map[string]string) + + for key, value := range item { + err = json.Unmarshal([]byte(value), &siteInfo) if err != nil { - continue + log.Println("json unmarshal error", err, value) + break } - siteInfo["domainname"] = string(list[key-1]) - all = append(all, siteInfo) + siteInfo["domainname"] = key } + if len(siteInfo) < 1 { + continue + } + all = append(all, siteInfo) + } } - return all, err } -*/ diff --git a/go.mod b/go.mod index 2d6cfac..72ce59f 100644 --- a/go.mod +++ b/go.mod @@ -1,3 +1,9 @@ module git.tetele.net/tgo/site go 1.14 + +require ( + git.tetele.net/tgo/helper v0.1.0 // indirect + git.tetele.net/tgo/redisrpc v0.3.1 // indirect + golang.org/x/crypto v0.0.0-20210616213533-5ff15b29337e // indirect +) diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..cee9975 --- /dev/null +++ b/go.sum @@ -0,0 +1,27 @@ +git.tetele.net/tgo/conf v0.25.0 h1:fopDch45xw/di5fLvvzwltFiGiXrilMobZwQNO678Wo= +git.tetele.net/tgo/conf v0.25.0/go.mod h1:DogEBvxG2fGdukpoobTVFE2b4Fd5OTE9FJ3Xetyn47E= +git.tetele.net/tgo/helper v0.1.0 h1:ZdsBXUWX3+22ZzHTZRldBfBsQwu+CwUH8qScUvpgimE= +git.tetele.net/tgo/helper v0.1.0/go.mod h1:shYQE/hvMy3fOE8JXKGxvywOXiz3M5Nw4e+u7HR8+NY= +git.tetele.net/tgo/redisrpc v0.3.1 h1:H/5xPeC83noJ7mlBckDXkDxlMS1uCBX+orhf2x6Tp9w= +git.tetele.net/tgo/redisrpc v0.3.1/go.mod h1:cNefHGXYxTY9sliaKKNKVZiZBtY1V26ZtwlTZ6uXVtY= +github.com/chai2010/protorpc v1.0.0 h1:aJ45G9sl1utSKo35EqnBSTs5jqTpdJDJAuZMMYPAtFo= +github.com/chai2010/protorpc v1.0.0/go.mod h1:woR3WwjaQDqFjlzdVsFEKiK5Ur12QL8mYxVPjfr5z54= +github.com/golang/protobuf v1.0.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= +github.com/golang/protobuf v1.5.2 h1:ROPKBNFfQgOUMifHyP+KYbvpjbdoFNs+aK7DXlji0Tw= +github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= +github.com/golang/snappy v0.0.0-20170215233205-553a64147049 h1:K9KHZbXKpGydfDN0aZrsoHpLJlZsBrGMFWbgLDGnPZk= +github.com/golang/snappy v0.0.0-20170215233205-553a64147049/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= +github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +golang.org/x/crypto v0.0.0-20210616213533-5ff15b29337e h1:gsTQYXdTw2Gq7RBsWvlQ91b+aEQ6bXFUngBGuR8sPpI= +golang.org/x/crypto v0.0.0-20210616213533-5ff15b29337e/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= +golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= +golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= +golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= +google.golang.org/protobuf v1.26.0 h1:bxAC2xTBsZGibn2RTntX0oH50xLsqy1OxA9tTL3p/lk= +google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=