48 lines
860 B
Go
48 lines
860 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"
|
|
)
|
|
|
|
const TypeGolang = "golang"
|
|
|
|
type GoApiHandler struct {
|
|
NameSpace string
|
|
Name string
|
|
AliasName string
|
|
Root string
|
|
Port string
|
|
Host string
|
|
Path string
|
|
ServiceEnv map[string]string
|
|
DeployEnv consts.Env
|
|
}
|
|
|
|
func (gah GoApiHandler) ToDestinationConfig() (string, error) {
|
|
var err error
|
|
t := template.New(gah.Name)
|
|
|
|
apiPipeline := go_handler_template.ApiTestPipeline
|
|
if gah.DeployEnv == consts.EnvProduction {
|
|
apiPipeline = go_handler_template.ApiProductionPipeline
|
|
}
|
|
|
|
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
|
|
}
|