-
Notifications
You must be signed in to change notification settings - Fork 0
/
property.go
77 lines (62 loc) · 1.99 KB
/
property.go
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package hive
import (
"encoding/json"
"fmt"
)
var (
ENDPOINT_PROPERTY = `%v:%v/templeton/v1/ddl/database/%v/table/:%v/property?user.name=%v`
ENDPOINT_PROPERTY_DETAIL = `%v:%v/templeton/v1/ddl/database/%v/table/:%v/property/%v?user.name=%v`
)
type Property interface{}
type ListPropertyResponse struct {
Properties Property `json:"properties"`
Database string `json:"database"`
Table string `json:"table"`
}
type ShowPropertyResponse struct {
Database string `json:"database"`
Table string `json:"table"`
Property Property `json:"property"`
}
type CreatePropertyResponse struct {
Property Property `json:"property"`
Database string `json:"database"`
Table string `json:"table"`
}
func (this *Client) ListProperty(database, table string) (*ListPropertyResponse, error) {
endpoint := fmt.Sprintf(ENDPOINT_COLUMN, this.BaseUrl, this.Port, database, table, this.User)
resp, err := this.request(HTTP_GET, endpoint, nil)
if err != nil {
return nil, err
}
res := &ListPropertyResponse{}
if err := json.NewDecoder(resp.Body).Decode(res); err != nil {
return nil, err
}
return res, nil
}
func (this *Client) ShowProperty(database, table, property string) (*ShowPropertyResponse, error) {
endpoint := fmt.Sprintf(ENDPOINT_COLUMN_DETAIL, this.BaseUrl, this.Port, database, table, property, this.User)
resp, err := this.request(HTTP_GET, endpoint, nil)
if err != nil {
return nil, err
}
res := &ShowPropertyResponse{}
if err := json.NewDecoder(resp.Body).Decode(res); err != nil {
return nil, err
}
return res, nil
}
// TODO
func (this *Client) CreateProperty(database, table, property string) (*CreatePropertyResponse, error) {
endpoint := fmt.Sprintf(ENDPOINT_COLUMN_DETAIL, this.BaseUrl, this.Port, database, table, property, this.User)
resp, err := this.request(HTTP_PUT, endpoint, nil)
if err != nil {
return nil, err
}
res := &CreatePropertyResponse{}
if err := json.NewDecoder(resp.Body).Decode(res); err != nil {
return nil, err
}
return res, nil
}