drone_plugin/go_handler/go_api_handler.go

45 lines
803 B
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
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 {
2021-12-29 23:23:35 +08:00
NameSpace string
Name string
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-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)
2021-12-30 20:06:10 +08:00
apiPipeline := go_handler_template.ApiTestPipeline
if gah.DeployEnv == consts.EnvProduction {
apiPipeline = go_handler_template.ApiProductionPipeline
}
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
}