update:wip

This commit is contained in:
2026-04-06 01:39:29 +09:00
parent 09c78206a8
commit ed19e0ba4e
10 changed files with 475 additions and 58 deletions

View File

@@ -3,6 +3,7 @@ package services
import (
"encoding/json"
"errors"
"fmt"
"os"
"path/filepath"
)
@@ -54,3 +55,24 @@ func NewConfigService() (*ConfigService, error) {
func (c *ConfigService) Servers() map[string]Server {
return c.servers
}
func (c *ConfigService) HasServer(name string) bool {
_, ok := c.servers[name]
return ok
}
func (c *ConfigService) AddServer(name string, s Server) error {
if c.HasServer(name) {
return fmt.Errorf("server %q already exists", name)
}
c.servers[name] = s
return c.flush()
}
func (c *ConfigService) flush() error {
data, err := json.MarshalIndent(c.servers, "", " ")
if err != nil {
return err
}
return os.WriteFile(c.path, data, 0o600)
}