-
Notifications
You must be signed in to change notification settings - Fork 0
/
column.go
80 lines (65 loc) · 2.02 KB
/
column.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
78
79
80
package hive
import (
"encoding/json"
"fmt"
)
var (
ENDPOINT_COLUMN = `%v:%v/templeton/v1/ddl/database/%v/table/:%v/column?user.name=%v`
ENDPOINT_COLUMN_DETAIL = `%v:%v/templeton/v1/ddl/database/%v/table/:%v/column/%v?user.name=%v`
)
type Column struct {
Name string `json:"name"`
Type string `json:"type"`
Comment string `json:"comment,omitempty"`
}
type ListColumnResponse struct {
Columns []Column `json:"columns"`
Database string `json:"database"`
Table string `json:"table"`
}
type ShowColumnResponse struct {
Database string `json:"database"`
Table string `json:"table"`
Column Column `json:"column"`
}
type CreateColumnResponse struct {
Column Column `json:"column"`
Database string `json:"database"`
Table string `json:"table"`
}
func (this *Client) ListColumn(database, table string) (*ListColumnResponse, 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 := &ListColumnResponse{}
if err := json.NewDecoder(resp.Body).Decode(res); err != nil {
return nil, err
}
return res, nil
}
func (this *Client) ShowColumn(database, table, column string) (*ShowColumnResponse, error) {
endpoint := fmt.Sprintf(ENDPOINT_COLUMN_DETAIL, this.BaseUrl, this.Port, database, table, column, this.User)
resp, err := this.request(HTTP_GET, endpoint, nil)
if err != nil {
return nil, err
}
res := &ShowColumnResponse{}
if err := json.NewDecoder(resp.Body).Decode(res); err != nil {
return nil, err
}
return res, nil
}
func (this *Client) CreateColumn(database, table, column string) (*CreateColumnResponse, error) {
endpoint := fmt.Sprintf(ENDPOINT_COLUMN_DETAIL, this.BaseUrl, this.Port, database, table, column, this.User)
resp, err := this.request(HTTP_PUT, endpoint, nil)
if err != nil {
return nil, err
}
res := &CreateColumnResponse{}
if err := json.NewDecoder(resp.Body).Decode(res); err != nil {
return nil, err
}
return res, nil
}