sqlite的api,便于内部使用
liuxiaolong
2019-05-22 5133036e9f297019771d4aeac7f961cbb57406ec
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package dbapi
 
import (
    "dbapi/protomsg"
    "encoding/json"
    "fmt"
)
 
type CameraApi struct{}
 
//通过cameraId获取摄像机信息
func (api CameraApi) GetCameraById(cameraId string) (result protomsg.Camera, err error) {
    url := BASIC_URL + DATA_URL_PREFIX + "/camera/show/" + cameraId
    client := NewClient()
 
    body, err := client.DoGetRequest(url, nil, nil)
    if err != nil {
        return result, err
    }
 
    var res Result
    if err = json.Unmarshal(body, &res); err != nil {
        fmt.Println(err)
        return result,err
    }
 
    bytes, _ := json.Marshal(res.Data)
    err = json.Unmarshal(bytes, &result)
 
    return result, err
}
 
func (api CameraApi) FindAll() (cameras []protomsg.Camera) {
    url := BASIC_URL + DATA_URL_PREFIX + "/camera/showAll"
    client := NewClient()
 
    body, err := client.DoGetRequest(url, nil, nil)
    if err != nil {
        return nil
    }
 
    var res Result
    if err = json.Unmarshal(body, &res); err != nil {
        fmt.Println(err)
        return nil
    }
 
    bytes, _ := json.Marshal(res.Data)
    err = json.Unmarshal(bytes, &cameras)
 
    return cameras
}