drone_plugin/go_handler/go_api_handler.go

55 lines
1.1 KiB
Go
Raw Normal View History

2021-12-28 20:42:51 +08:00
package go_handler
2021-12-29 20:24:21 +08:00
import (
"bytes"
"text/template"
2021-12-28 20:42:51 +08:00
2022-01-10 17:51:52 +08:00
"git.icechen.cn/pkg/drone_plugin/config"
2021-12-30 20:06:10 +08:00
"git.icechen.cn/pkg/drone_plugin/go_handler/go_handler_template"
2021-12-29 20:24:21 +08:00
2021-12-30 20:06:10 +08:00
"git.icechen.cn/pkg/drone_plugin/consts"
)
2021-12-29 20:24:21 +08:00
2021-12-30 20:06:10 +08:00
const TypeGolang = "golang"
2021-12-28 20:42:51 +08:00
2021-12-29 19:40:57 +08:00
type GoApiHandler struct {
2022-01-10 17:51:52 +08:00
NameSpace string
Name string
AliasName string
Root string
Port string
Host string
Path string
DeployEnv consts.Env
Reg config.Registry
Kube config.KubeConfig
2021-12-29 19:40:57 +08:00
}
2021-12-28 20:42:51 +08:00
2021-12-29 20:24:21 +08:00
func (gah GoApiHandler) ToDestinationConfig() (string, error) {
var err error
t := template.New(gah.Name)
2022-01-10 17:51:52 +08:00
gah.Reg = config.GetRegistryConfig()
2021-12-30 20:06:10 +08:00
apiPipeline := go_handler_template.ApiTestPipeline
2022-01-10 17:51:52 +08:00
gah.Kube = config.GetTestKubeConfigByNamespace(gah.NameSpace)
2021-12-30 20:06:10 +08:00
if gah.DeployEnv == consts.EnvProduction {
apiPipeline = go_handler_template.ApiProductionPipeline
2022-01-10 17:51:52 +08:00
gah.Kube = config.GetOnlKubeConfigByNamespace(gah.NameSpace)
2021-12-30 20:06:10 +08:00
}
2021-12-29 20:24:21 +08:00
t, err = t.Parse(apiPipeline)
if err != nil {
return "", err
}
b := bytes.Buffer{}
err = t.Execute(&b, gah)
if err != nil {
return "", err
}
return b.String(), nil
2021-12-28 20:42:51 +08:00
}