drone_plugin/go_handler/go_service_handler.go

44 lines
821 B
Go
Raw Normal View History

2021-12-29 19:40:57 +08:00
package go_handler
2021-12-30 00:00:25 +08:00
import (
"bytes"
"text/template"
2021-12-30 20:06:10 +08:00
"git.icechen.cn/pkg/drone_plugin/go_handler/go_handler_template"
2021-12-30 00:00:25 +08:00
2021-12-30 20:06:10 +08:00
"git.icechen.cn/pkg/drone_plugin/consts"
)
2021-12-30 00:00:25 +08:00
2021-12-29 19:40:57 +08:00
type GoServiceHandler struct {
2021-12-30 00:00:25 +08:00
NameSpace string
Name string
2022-01-04 00:21:33 +08:00
AliasName string
2021-12-30 00:00:25 +08:00
Root string
Port string
ServiceEnv map[string]string
2021-12-30 20:06:10 +08:00
DeployEnv consts.Env
2021-12-29 19:40:57 +08:00
}
2021-12-30 00:00:25 +08:00
func (gsh GoServiceHandler) ToDestinationConfig() (string, error) {
var err error
t := template.New(gsh.Name)
2021-12-30 20:06:10 +08:00
servicePipeline := go_handler_template.ServiceTestPipeline
if gsh.DeployEnv == consts.EnvProduction {
servicePipeline = go_handler_template.ServiceProductionPipeline
}
2021-12-30 00:05:19 +08:00
t, err = t.Parse(servicePipeline)
2021-12-30 00:00:25 +08:00
if err != nil {
return "", err
}
b := bytes.Buffer{}
err = t.Execute(&b, gsh)
if err != nil {
return "", err
}
return b.String(), nil
2021-12-29 19:40:57 +08:00
}