From 37b3f0694ca3882f04e09b48315dd86ed29c7710 Mon Sep 17 00:00:00 2001 From: sincos Date: Sun, 18 Feb 2024 18:08:08 +0800 Subject: [PATCH] chore(clients): embed mock clients config --- clients/clients | 77 +++++++++++++++++++++++++++++++++++++++++ clients/manager.go | 86 ++++++---------------------------------------- 2 files changed, 87 insertions(+), 76 deletions(-) create mode 100644 clients/clients diff --git a/clients/clients b/clients/clients new file mode 100644 index 00000000..450360ae --- /dev/null +++ b/clients/clients @@ -0,0 +1,77 @@ +[ + { + "clientDID": "did:ethr:0x9d9250fb4e08ba7a858fe7196a6ba946c6083ff0", + "projects": [ + 1, + 2, + 3, + 4, + 5, + 6, + 7, + 8, + 9, + 10, + 11, + 12, + 13, + 14, + 15, + 16, + 17, + 18, + 19, + 20 + ] + }, + { + "clientDID": "did:key:z6MkeeChrUs1EoKkNNzoy9FwJJb9gNQ92UT8kcXZHMbwj67B", + "projects": [ + 1, + 2, + 3, + 4, + 5, + 6, + 7, + 8, + 9, + 10, + 11, + 12, + 13, + 14, + 15, + 16, + 17, + 18, + 19, + 20 + ] + }, + { + "clientDID": "did:example:d23dd687a7dc6787646f2eb98d0", + "projects": [ + 1, + 2, + 3, + 4, + 5, + 6, + 7, + 8, + 9, + 10, + 11, + 12, + 13, + 14, + 15, + 16, + 17, + 18, + 19, + 20 + ] + } +] \ No newline at end of file diff --git a/clients/manager.go b/clients/manager.go index a8f388a9..84d0cb41 100644 --- a/clients/manager.go +++ b/clients/manager.go @@ -1,9 +1,16 @@ package clients import ( + _ "embed" // embed mock clients configuration + "encoding/json" "sync" ) +var ( + //go:embed clients + mockClientsConfig []byte +) + type Client struct { ClientDID string `json:"clientDID"` Projects []uint64 `json:"projects"` @@ -48,82 +55,9 @@ func (mgr *Manager) AddClient(c *Client) { func (mgr *Manager) syncFromContract() {} func (mgr *Manager) fillByMockClients() { - clients := []*Client{ - { - ClientDID: "did:ethr:0x9d9250fb4e08ba7a858fe7196a6ba946c6083ff0", - Projects: []uint64{ - 1, - 2, - 3, - 4, - 5, - 6, - 7, - 8, - 9, - 10, - 11, - 12, - 13, - 14, - 15, - 16, - 17, - 18, - 19, - 20, - }, - }, - { - ClientDID: "did:key:z6MkeeChrUs1EoKkNNzoy9FwJJb9gNQ92UT8kcXZHMbwj67B", - Projects: []uint64{ - 1, - 2, - 3, - 4, - 5, - 6, - 7, - 8, - 9, - 10, - 11, - 12, - 13, - 14, - 15, - 16, - 17, - 18, - 19, - 20, - }, - }, - { - ClientDID: "did:example:d23dd687a7dc6787646f2eb98d0", - Projects: []uint64{ - 1, - 2, - 3, - 4, - 5, - 6, - 7, - 8, - 9, - 10, - 11, - 12, - 13, - 14, - 15, - 16, - 17, - 18, - 19, - 20, - }, - }, + clients := make([]*Client, 0) + if err := json.Unmarshal(mockClientsConfig, &clients); err != nil { + panic(err) } for _, c := range clients { c.projects = make(map[uint64]struct{})