-
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathconfig.go
More file actions
166 lines (134 loc) · 4.2 KB
/
config.go
File metadata and controls
166 lines (134 loc) · 4.2 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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
package app
import (
"os"
"path/filepath"
)
// Config holds conventional configuration paths for Go projects
// using the root directory as source
type Config struct {
RootDir string // Root directory (default: ".")
logger func(message ...any) // Logging function
AppName string // Application name (directory name)
}
// NewConfig creates a new configuration with conventional paths
func NewConfig(RootDir string, logger func(message ...any)) *Config {
root := "." // Default to current directory
if RootDir != root {
root = RootDir
}
return &Config{
RootDir: root,
logger: logger,
AppName: filepath.Base(root),
}
}
// Name returns the Handler name for Loggable interface
func (c *Config) Name() string {
return "Config"
}
// SetLog implements Loggable interface
func (c *Config) SetLog(f func(message ...any)) {
c.logger = f
}
// GetLog implements Loggable interface
func (c *Config) GetLog() func(message ...any) {
return c.logger
}
// GetAppName returns the detected application name
func (c *Config) GetAppName() string {
if c.AppName == "" {
return filepath.Base(c.RootDir)
}
return c.AppName
}
// === BASE DIRECTORIES ===
// SrcDir returns the relative source directory path
// Returns: "."
func (c *Config) SrcDir() string {
return "."
}
// CmdDir returns the relative command directory path
// Returns: "cmd"
func (c *Config) CmdDir() string {
return filepath.Join(c.SrcDir(), "cmd")
}
// WebDir returns the relative web directory path
// Returns: "web"
func (c *Config) WebDir() string {
return filepath.Join(c.SrcDir(), "web")
}
// DeployDir returns the relative deployment directory path
// Returns: "deploy"
func (c *Config) DeployDir() string {
return "deploy"
}
// === CMD ENTRY POINTS (Source Directories) ===
// CmdAppServerDir returns the relative appserver source directory path
// Returns: "web" (with new structure using build tags)
func (c *Config) CmdAppServerDir() string {
return c.WebDir()
}
// CmdWebClientDir returns the relative webclient source directory path
// Returns: "web" (with new structure using build tags)
func (c *Config) CmdWebClientDir() string {
return c.WebDir()
}
// CmdEdgeWorkerDir returns the relative edgeworker source directory path
// Returns: "cmd/edgeworker" (edge workers remain separate)
func (c *Config) CmdEdgeWorkerDir() string {
return filepath.Join(c.CmdDir(), "edgeworker")
}
// === SOURCE FILE NAMES (Convention Defaults) ===
// ServerFileName returns the default server entry file name
// Returns: "server.go" (convention with //go:build !wasm)
func (c *Config) ServerFileName() string {
return "server.go"
}
// ClientFileName returns the default WASM client entry file name
// Returns: "client.go" (convention with //go:build wasm)
func (c *Config) ClientFileName() string {
return "client.go"
}
// === WEB DIRECTORIES ===
// WebPublicDir returns the relative web public directory path
// Returns: "web/public"
func (c *Config) WebPublicDir() string {
return filepath.Join(c.WebDir(), "public")
}
// WebUIDir returns the relative web UI directory path
// Returns: "web/ui"
func (c *Config) WebUIDir() string {
return filepath.Join(c.WebDir(), "ui")
}
// JsDir returns the relative web JavaScript directory path
// Returns: "web/ui/js"
func (c *Config) JsDir() string {
return filepath.Join(c.WebUIDir(), "js")
}
// === DEPLOY DIRECTORIES ===
// DeployAppServerDir returns the relative appserver deployment directory path
// Returns: "web" (server compiles in same directory as source)
func (c *Config) DeployAppServerDir() string {
return c.WebDir()
}
// DeployEdgeWorkerDir returns the relative edgeworker deployment directory path
// Returns: "deploy/edgeworker"
func (c *Config) DeployEdgeWorkerDir() string {
return filepath.Join(c.DeployDir(), "edgeworker")
}
// === CONFIGURATION ===
// ServerPort returns the default server port or overrides from PORT env var
func (c *Config) ServerPort() string {
if port := os.Getenv("PORT"); port != "" {
return port
}
return "6060" // Default HTTPS development port
}
// SetRootDir updates the root directory path
func (c *Config) SetRootDir(path string) {
c.RootDir = path
}
// SetAppName updates the application name
func (c *Config) SetAppName(name string) {
c.AppName = name
}