Added API Endpoint and Admin Dashboard Endpoint

This commit is contained in:
2026-05-26 15:52:59 +02:00
parent 48f62500d5
commit 8ec5472355
7 changed files with 368 additions and 8 deletions
+24 -4
View File
@@ -8,15 +8,20 @@ import (
// Config is the application configuration loaded from JSON.
type Config struct {
Host string `json:"host"`
Port int `json:"port"`
Host string `json:"host"`
APIPort int `json:"api_port"`
AdminPort int `json:"admin_port"`
// Port is deprecated; mapped to APIPort when api_port is unset.
Port int `json:"port"`
}
// Default returns sensible defaults when no config file is used.
func Default() *Config {
return &Config{
Host: "127.0.0.1",
Port: 8080,
Host: "127.0.0.1",
APIPort: 8080,
AdminPort: 8081,
}
}
@@ -32,5 +37,20 @@ func Load(path string) (*Config, error) {
return nil, fmt.Errorf("parse config: %w", err)
}
cfg.applyLegacyPort()
return cfg, nil
}
func (c *Config) applyLegacyPort() {
if c.Port != 0 && c.APIPort == 8080 {
c.APIPort = c.Port
}
}
func (c *Config) APIAddr() string {
return fmt.Sprintf("%s:%d", c.Host, c.APIPort)
}
func (c *Config) AdminAddr() string {
return fmt.Sprintf("%s:%d", c.Host, c.AdminPort)
}