feat: 设备编号从 00000001 顺序分配
This commit is contained in:
@@ -46,13 +46,13 @@ type Endpoint struct {
|
||||
Found bool
|
||||
}
|
||||
|
||||
func (c *Client) CreateEndpoint(ctx context.Context, name string) (Endpoint, error) {
|
||||
func (c *Client) CreateEndpoint(ctx context.Context, id, name string) (Endpoint, error) {
|
||||
var out struct {
|
||||
ID string `json:"id"`
|
||||
LoginPassword string `json:"login_password"`
|
||||
}
|
||||
err := c.call(ctx, http.MethodPost, "/api/admin/endpoints", map[string]any{
|
||||
"id": "",
|
||||
"id": id,
|
||||
"name": name,
|
||||
"remark": "",
|
||||
"login_password": "",
|
||||
|
||||
@@ -40,9 +40,9 @@ func TestClientCreatesAndReadsEndpoint(t *testing.T) {
|
||||
}
|
||||
mu.Lock()
|
||||
sawCSRF = true
|
||||
online["e_abc"] = true
|
||||
online["00000001"] = true
|
||||
mu.Unlock()
|
||||
_ = json.NewEncoder(w).Encode(map[string]any{"ok": true, "data": map[string]any{"id": "e_abc", "login_password": "OnceFromNix12345"}})
|
||||
_ = json.NewEncoder(w).Encode(map[string]any{"ok": true, "data": map[string]any{"id": "00000001", "login_password": "OnceFromNix12345"}})
|
||||
})
|
||||
mux.HandleFunc("GET /api/admin/endpoints/{id}", func(w http.ResponseWriter, r *http.Request) {
|
||||
mu.Lock()
|
||||
@@ -63,14 +63,14 @@ func TestClientCreatesAndReadsEndpoint(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
ep, err := client.CreateEndpoint(context.Background(), "客厅")
|
||||
ep, err := client.CreateEndpoint(context.Background(), "00000001", "客厅")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if ep.ID != "e_abc" || ep.LoginPassword != "OnceFromNix12345" {
|
||||
if ep.ID != "00000001" || ep.LoginPassword != "OnceFromNix12345" {
|
||||
t.Fatalf("endpoint %+v", ep)
|
||||
}
|
||||
got, err := client.Lookup(context.Background(), "e_abc")
|
||||
got, err := client.Lookup(context.Background(), "00000001")
|
||||
if err != nil || !got.Found || !got.Online {
|
||||
t.Fatalf("lookup %+v %v", got, err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user