first commit! 🎉
port "ari is learning!" assets to live go backend. some prep work for further developments for ari melody LIVE
This commit is contained in:
commit
6927d54cbd
12 changed files with 675 additions and 0 deletions
60
main.go
Normal file
60
main.go
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"log"
|
||||
"math"
|
||||
"os"
|
||||
"os/signal"
|
||||
"strconv"
|
||||
"syscall"
|
||||
|
||||
"codeberg.org/arimelody/ari-stream-utils/learning"
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
var DEFAULT_HOST string = "0.0.0.0"
|
||||
var DEFAULT_PORT int16 = 8080
|
||||
|
||||
func main() {
|
||||
failed := make(chan error)
|
||||
ctx, cancel := signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM)
|
||||
defer cancel()
|
||||
|
||||
gin.SetMode(gin.ReleaseMode)
|
||||
|
||||
host := DEFAULT_HOST
|
||||
port := DEFAULT_PORT
|
||||
|
||||
if len(os.Args) > 1 {
|
||||
_port, err := strconv.Atoi(os.Args[1])
|
||||
if _port > math.MaxUint16 {
|
||||
log.Fatalf("Port must be between 1 and 65535: %d", _port)
|
||||
}
|
||||
port = int16(_port)
|
||||
if err != nil {
|
||||
log.Fatalf("Failed to parse port: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
learningService := learning.New(ctx, learning.ServiceConfig{
|
||||
TitleFilePath: "learning-title.txt",
|
||||
})
|
||||
|
||||
srv := gin.Default()
|
||||
learningService.BindRoutes(srv.Group("/learning"))
|
||||
|
||||
go learningService.Run(ctx)
|
||||
go func() {
|
||||
log.Printf("Now serving at http://%s:%d\n", host, port)
|
||||
failed <- srv.Run(fmt.Sprintf("%s:%d", host, port))
|
||||
}()
|
||||
|
||||
select {
|
||||
case err := <-failed:
|
||||
log.Fatal(err)
|
||||
case <-ctx.Done():
|
||||
log.Print("Shutting down...")
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue