drone_plugin/config_handler/destination_config.go

60 lines
1.1 KiB
Go
Raw Normal View History

2021-12-28 20:42:51 +08:00
package config_handler
import "git.icechen.cn/pkg/drone_plugin/go_handler"
2021-12-29 19:40:57 +08:00
type Handler interface {
2021-12-28 20:42:51 +08:00
ToDestinationConfig() (string, error)
}
func (al ApiList) toDestinationConfig() (string, error) {
2021-12-29 19:40:57 +08:00
retConfig := ""
for _, api := range al {
config, err := api.toDestinationConfig()
if err != nil {
return "", err
}
retConfig += config + "\n\n---\n\n"
}
return retConfig, nil
2021-12-28 20:42:51 +08:00
}
func (a Api) toDestinationConfig() (string, error) {
2021-12-29 19:40:57 +08:00
var handler Handler
2021-12-28 20:42:51 +08:00
switch a.Type {
case go_handler.TypeGolang:
2021-12-29 19:40:57 +08:00
handler = go_handler.GoApiHandler{
Name: a.Name,
Root: a.Root,
Port: a.Port,
}
2021-12-28 20:42:51 +08:00
}
return handler.ToDestinationConfig()
}
2021-12-29 19:40:57 +08:00
func (sl ServiceList) toDestinationConfig() (string, error) {
retConfig := ""
for _, service := range sl {
config, err := service.toDestinationConfig()
if err != nil {
return "", err
}
retConfig += config + "\n\n---\n\n"
}
return retConfig, nil
2021-12-28 20:42:51 +08:00
}
2021-12-29 19:40:57 +08:00
func (s Service) toDestinationConfig() (string, error) {
var handler Handler
switch s.Type {
case go_handler.TypeGolang:
handler = go_handler.GoApiHandler{
Name: s.Name,
Root: s.Root,
Port: s.Port,
}
}
return handler.ToDestinationConfig()
2021-12-28 20:42:51 +08:00
}