drone_plugin/go_handler/go_api_handler.go

55 lines
1.1 KiB
Go

package go_handler
import (
"bytes"
"text/template"
"git.icechen.cn/pkg/drone_plugin/config"
"git.icechen.cn/pkg/drone_plugin/go_handler/go_handler_template"
"git.icechen.cn/pkg/drone_plugin/consts"
)
const TypeGolang = "golang"
type GoApiHandler struct {
NameSpace string
Name string
AliasName string
Root string
Port string
Host string
Path string
DeployEnv consts.Env
Reg config.Registry
Kube config.KubeConfig
}
func (gah GoApiHandler) ToDestinationConfig() (string, error) {
var err error
t := template.New(gah.Name)
gah.Reg = config.GetRegistryConfig()
apiPipeline := go_handler_template.ApiTestPipeline
gah.Kube = config.GetTestKubeConfigByNamespace(gah.NameSpace)
if gah.DeployEnv == consts.EnvProduction {
apiPipeline = go_handler_template.ApiProductionPipeline
gah.Kube = config.GetOnlKubeConfigByNamespace(gah.NameSpace)
}
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
}