-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprovider.go
More file actions
87 lines (79 loc) · 2.01 KB
/
provider.go
File metadata and controls
87 lines (79 loc) · 2.01 KB
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
package configprovider
import "runtime"
// 1. Definisikan Interface
type ConfigProvider interface {
GetServiceConfigs() []ServiceConfig
GetServiceName(displayName string) string
}
// 2. Definisikan Struct Konkret (Implementasi Nyata)
type DefaultConfigProvider struct{}
// 3. Buat Constructor
func NewConfigProvider() *DefaultConfigProvider {
return &DefaultConfigProvider{}
}
// 4. Definisikan Struktur Data Config
type ServiceConfig struct {
DisplayName string
Linux string
Darwin string
Windows string
}
// GetServiceConfigs returns all available service configurations
func (p *DefaultConfigProvider) GetServiceConfigs() []ServiceConfig {
return []ServiceConfig{
{
DisplayName: "Apache",
Linux: "apache2",
Darwin: "httpd",
Windows: "Apache2.4",
},
{
DisplayName: "MySQL",
Linux: "mysql",
Darwin: "mysql",
Windows: "MySQL80",
},
{
DisplayName: "PostgreSQL",
Linux: "postgresql",
Darwin: "postgresql",
Windows: "PostgreSQL",
},
{
DisplayName: "Redis",
Linux: "redis-server",
Darwin: "redis",
Windows: "Redis",
},
{
DisplayName: "Nginx",
Linux: "nginx",
Darwin: "nginx",
Windows: "nginx",
},
{
DisplayName: "PHP-FPM",
Linux: "php8.1-fpm", // or php7.4-fpm, adjust version
Darwin: "php",
Windows: "php-cgi",
},
}
}
// 6. Implementasi Method Interface: GetServiceName
// Logika ini dipindah ke sini agar App.go tidak pusing mikirin OS logic
func (p *DefaultConfigProvider) GetServiceName(displayName string) string {
configs := p.GetServiceConfigs()
for _, config := range configs {
if config.DisplayName == displayName {
switch runtime.GOOS {
case "linux":
return config.Linux
case "darwin":
return config.Darwin
case "windows":
return config.Windows
}
}
}
return displayName
}