Initial updates server repository commit.
Reinitialize repository history and exclude generated OTA artifact outputs. Made-with: Cursor
This commit is contained in:
22
internal/app/config.go
Normal file
22
internal/app/config.go
Normal file
@@ -0,0 +1,22 @@
|
||||
package app
|
||||
|
||||
import "os"
|
||||
|
||||
func LoadConfig() Config {
|
||||
return Config{
|
||||
Port: envOrDefault("PORT", "3001"),
|
||||
Hostname: envOrDefault("HOSTNAME", "http://localhost:3001"),
|
||||
UpdatesRoot: envOrDefault("UPDATES_ROOT", "updates"),
|
||||
PrivateKey: os.Getenv("PRIVATE_KEY_PATH"),
|
||||
AdminToken: os.Getenv("ADMIN_TOKEN"),
|
||||
}
|
||||
}
|
||||
|
||||
func envOrDefault(key string, fallback string) string {
|
||||
v := os.Getenv(key)
|
||||
if v == "" {
|
||||
return fallback
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
41
internal/app/server.go
Normal file
41
internal/app/server.go
Normal file
@@ -0,0 +1,41 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"expo-updates-server-go/internal/handlers"
|
||||
"expo-updates-server-go/internal/service"
|
||||
"expo-updates-server-go/internal/storage"
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
Port string
|
||||
Hostname string
|
||||
UpdatesRoot string
|
||||
PrivateKey string
|
||||
AdminToken string
|
||||
}
|
||||
|
||||
type Server struct {
|
||||
cfg Config
|
||||
handlers *handlers.Handler
|
||||
}
|
||||
|
||||
func NewServer(cfg Config) *Server {
|
||||
store := storage.NewLocalStore(cfg.UpdatesRoot)
|
||||
svc := service.NewUpdateService(store, cfg.Hostname, cfg.PrivateKey)
|
||||
h := handlers.NewHandler(svc, cfg.AdminToken)
|
||||
return &Server{cfg: cfg, handlers: h}
|
||||
}
|
||||
|
||||
func (s *Server) Routes() http.Handler {
|
||||
mux := http.NewServeMux()
|
||||
mux.HandleFunc("/api/manifest", s.handlers.Manifest)
|
||||
mux.HandleFunc("/api/assets", s.handlers.Asset)
|
||||
mux.HandleFunc("/admin/publish", s.handlers.AdminPublish)
|
||||
mux.HandleFunc("/admin/rollback", s.handlers.AdminRollback)
|
||||
mux.HandleFunc("/admin/releases", s.handlers.AdminReleases)
|
||||
mux.HandleFunc("/healthz", s.handlers.Healthz)
|
||||
return mux
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user