44 lines
821 B
Go
44 lines
821 B
Go
package go_handler
|
|
|
|
import (
|
|
"bytes"
|
|
"text/template"
|
|
|
|
"git.icechen.cn/pkg/drone_plugin/go_handler/go_handler_template"
|
|
|
|
"git.icechen.cn/pkg/drone_plugin/consts"
|
|
)
|
|
|
|
type GoServiceHandler struct {
|
|
NameSpace string
|
|
Name string
|
|
AliasName string
|
|
Root string
|
|
Port string
|
|
ServiceEnv map[string]string
|
|
DeployEnv consts.Env
|
|
}
|
|
|
|
func (gsh GoServiceHandler) ToDestinationConfig() (string, error) {
|
|
var err error
|
|
t := template.New(gsh.Name)
|
|
|
|
servicePipeline := go_handler_template.ServiceTestPipeline
|
|
if gsh.DeployEnv == consts.EnvProduction {
|
|
servicePipeline = go_handler_template.ServiceProductionPipeline
|
|
}
|
|
|
|
t, err = t.Parse(servicePipeline)
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
|
|
b := bytes.Buffer{}
|
|
err = t.Execute(&b, gsh)
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
|
|
return b.String(), nil
|
|
}
|