-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtest_car.go
85 lines (74 loc) · 1.82 KB
/
test_car.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
81
82
83
84
85
package main
import (
"fmt"
"log"
metav1 "practice_ctl/pkg/apis/meta"
"time"
appsv1 "practice_ctl/pkg/apis/apps/v1"
"practice_ctl/pkg/util/stores"
"practice_ctl/pkg/util/stores/rest"
)
func main() {
// 配置文件
config := &rest.Config{
Host: fmt.Sprintf("http://localhost:8080"),
Timeout: time.Second,
Token: "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdXRob3JpemVkIjp0cnVlLCJleHAiOjE2ODM3Mjg3MzUsInVzZXJuYW1lIjoiYWRtaW4ifQ.if3msVqdo6V8ehDLG2SKBheDjNwmViCio3ZQ1__oy_U",
}
clientSet := stores.NewForConfig(config)
// 创建操作
a := &appsv1.Car{
TypeMeta: metav1.TypeMeta{
ApiVersion: "apps/v1",
Kind: "Car",
},
ObjectMeta: metav1.ObjectMeta{
Name: "car1",
},
Spec: appsv1.CarSpec{
Color: "car1",
Brand: "car1",
Price: "car1",
},
}
c, err := clientSet.AppsV1().Car().Create(a)
if err != nil {
fmt.Println(err)
}
fmt.Println("name:", c.Name, "brand:", c.Spec.Brand, "color:", c.Spec.Color, "price:", c.Spec.Price)
car1, err := clientSet.AppsV1().Car().Get("car1")
if err != nil {
log.Fatalln(err)
}
fmt.Println("get name: ", car1.Name)
aaa := &appsv1.Car{
TypeMeta: metav1.TypeMeta{
ApiVersion: "apps/v1",
Kind: "Car",
},
ObjectMeta: metav1.ObjectMeta{
Name: "car1",
},
Spec: appsv1.CarSpec{
Color: "car12222",
Brand: "car12233",
Price: "car12347934",
},
}
carUpdate, err := clientSet.AppsV1().Car().Update(aaa)
if err != nil {
log.Fatalln(err)
}
fmt.Println("name: ", carUpdate.Name, "color: ", carUpdate.Spec.Color, "brand: ", carUpdate.Spec.Brand, "price: ", carUpdate.Spec.Price)
carList, err := clientSet.AppsV1().Car().List()
if err != nil {
log.Fatalln(err)
}
for _, car := range carList.Item {
fmt.Println(car.Name)
}
//err = clientSet.AppsV1().Car().Delete("car1")
//if err != nil {
// log.Fatalln(err)
//}
}