42 lines
1021 B
Go
42 lines
1021 B
Go
|
|
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
|
||
|
|
}
|
||
|
|
|