-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add gin tls and code-generator demo (#95)
- Loading branch information
1 parent
71acc3a
commit 745926c
Showing
6 changed files
with
83 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# code-generator | ||
|
||
- deepcopy-gen: 生成深度拷贝方法,为每个 T 类型生成 func (t* T) DeepCopy() *T 方法,API 类型都需要实现深拷贝 | ||
- client-gen: 为资源生成标准的 clientset | ||
- informer-gen: 生成 informer,提供事件机制来响应资源的事件 | ||
- lister-gen: 生成 Lister,为 get 和 list 请求提供只读缓存层(通过 indexer 获取) | ||
|
||
```shell | ||
git clone https://github.com/kubernetes/code-generator.git | ||
git checkout v0.24.9 | ||
``` | ||
|
||
```shell | ||
# 进行安装 | ||
go install ./cmd/{client-gen,deepcopy-gen,informer-gen,lister-gen} | ||
``` | ||
|
||
```shell | ||
# 验证安装 | ||
client-gen -h | ||
``` | ||
|
||
```shell | ||
代码结构可以参考 | ||
https://github.com/kubernetes/sample-controller | ||
``` | ||
|
||
```shell | ||
$ mkdir test && cd test | ||
$ go mod init test | ||
$ mkdir -p pkg/apis/example.com/v1 | ||
➜ test tree | ||
├── go.mod | ||
├── go.sum | ||
└── pkg | ||
└── apis | ||
└── example.com | ||
└── v1 | ||
├── doc.go | ||
├── register.go | ||
└── types.go | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# How to Test | ||
|
||
## Generate RSA private key and digital certificate | ||
|
||
## Starting server with tls | ||
```shell | ||
go run main.go | ||
``` | ||
|
||
## Curl with cert | ||
```shell | ||
curl --cacert ./cert/tls.crt https://127.0.0.1:443/welcome | ||
|
||
# 正常回显 | ||
{"status":"success"} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
-----BEGIN CERTIFICATE----- | ||
... | ||
-----END CERTIFICATE----- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
-----BEGIN PRIVATE KEY----- | ||
... | ||
-----END PRIVATE KEY----- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package main | ||
|
||
import ( | ||
"net/http" | ||
|
||
"github.com/gin-gonic/gin" | ||
) | ||
|
||
func main() { | ||
r := gin.Default() | ||
r.GET("/welcome", func(c *gin.Context) { | ||
c.JSON(http.StatusOK, gin.H{ | ||
"status": "success", | ||
}) | ||
}) | ||
|
||
r.RunTLS(":443", "./cert/tls.crt", "./cert/tls.key") | ||
} |