-
Notifications
You must be signed in to change notification settings - Fork 2
/
update.go
68 lines (58 loc) · 1.38 KB
/
update.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package servicesInfra
import (
"errors"
"strings"
"github.com/speedianet/os/src/domain/dto"
"github.com/speedianet/os/src/domain/entity"
"github.com/speedianet/os/src/domain/valueObject"
)
func Update(
serviceEntity entity.Service,
updateDto dto.UpdateService,
) error {
err := SupervisordFacade{}.RemoveConf(updateDto.Name)
if err != nil {
return errors.New("RemoveServiceConfError")
}
svcType := serviceEntity.Type
if updateDto.Type != nil {
svcType = *updateDto.Type
}
svcVersion := serviceEntity.Version
if updateDto.Version != nil {
svcVersion = *updateDto.Version
}
svcCommand := serviceEntity.Command
if updateDto.Command != nil {
svcCommand = *updateDto.Command
}
svcStartupFile := serviceEntity.StartupFile
if updateDto.StartupFile != nil {
newCommandStr := strings.Replace(
svcCommand.String(),
serviceEntity.StartupFile.String(),
updateDto.StartupFile.String(),
1,
)
svcCommand = valueObject.UnixCommand(newCommandStr)
svcStartupFile = updateDto.StartupFile
}
svcPortBindings := serviceEntity.PortBindings
if len(updateDto.PortBindings) > 0 {
svcPortBindings = updateDto.PortBindings
}
err = SupervisordFacade{}.CreateConf(
serviceEntity.Name,
serviceEntity.Nature,
svcType,
svcVersion,
svcCommand,
svcStartupFile,
svcPortBindings,
nil,
)
if err != nil {
return errors.New("RecreateServiceConfError")
}
return nil
}