move common static files, 503 on unavailable services
This commit is contained in:
parent
7b92f97b24
commit
b2485eda79
47 changed files with 36 additions and 9 deletions
|
|
@ -5,13 +5,16 @@ import (
|
|||
"fmt"
|
||||
"log"
|
||||
"math"
|
||||
"net/http"
|
||||
"os"
|
||||
"os/signal"
|
||||
"strconv"
|
||||
"strings"
|
||||
"syscall"
|
||||
|
||||
"codeberg.org/arimelody/ari-stream-tools/learning"
|
||||
"codeberg.org/arimelody/ari-stream-tools/music"
|
||||
"codeberg.org/arimelody/ari-stream-tools/static"
|
||||
"codeberg.org/arimelody/ari-stream-tools/twitch"
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
|
@ -41,6 +44,7 @@ func main() {
|
|||
}
|
||||
|
||||
srv := gin.New()
|
||||
// srv.Use(gin.Logger())
|
||||
srv.SetTrustedProxies([]string{"127.0.0.1", "::1"})
|
||||
|
||||
learningService, err := learning.New(ctx, learning.ServiceConfig{
|
||||
|
|
@ -48,26 +52,41 @@ func main() {
|
|||
})
|
||||
if err != nil {
|
||||
log.Printf("Failed to create learning service: %v", err)
|
||||
srv.Group("learning").Any("/*any", func(ctx *gin.Context) {
|
||||
ctx.String(http.StatusServiceUnavailable, http.StatusText(http.StatusServiceUnavailable))
|
||||
})
|
||||
} else {
|
||||
learningService.BindRoutes(srv.Group("/learning"))
|
||||
learningService.BindRoutes(srv.Group("learning"))
|
||||
}
|
||||
|
||||
musicService, err := music.New(ctx)
|
||||
if err != nil {
|
||||
log.Printf("Failed to create music service: %v", err)
|
||||
srv.Group("music").Any("/*any", func(ctx *gin.Context) {
|
||||
ctx.String(http.StatusServiceUnavailable, http.StatusText(http.StatusServiceUnavailable))
|
||||
})
|
||||
} else {
|
||||
musicService.BindRoutes(srv.Group("/music"))
|
||||
musicService.BindRoutes(srv.Group("music"))
|
||||
go musicService.Run(ctx)
|
||||
}
|
||||
|
||||
twitchService, err := twitch.New(ctx, twitch.ServiceOptions{ Port: port })
|
||||
if err != nil {
|
||||
log.Printf("Failed to create Twitch service: %v", err)
|
||||
srv.Group("twitch").Any("/*any", func(ctx *gin.Context) {
|
||||
ctx.String(http.StatusServiceUnavailable, http.StatusText(http.StatusServiceUnavailable))
|
||||
})
|
||||
} else {
|
||||
twitchService.BindRoutes(srv.Group("/twitch"))
|
||||
twitchService.BindRoutes(srv.Group("twitch"))
|
||||
go twitchService.Run(ctx)
|
||||
}
|
||||
|
||||
public := srv.Group("/public")
|
||||
public.GET("/*path", func(ctx *gin.Context) {
|
||||
filepath := strings.TrimPrefix(ctx.Request.URL.Path, "/public/")
|
||||
http.ServeFileFS(ctx.Writer, ctx.Request, static.PublicFS, filepath)
|
||||
})
|
||||
|
||||
go func() {
|
||||
log.Printf("Now serving at http://%s:%d\n", host, port)
|
||||
failed <- srv.Run(fmt.Sprintf("%s:%d", host, port))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue