Moved to the v2 version of the fulgens library
Signed-off-by: Arzumify <jliwin98@danwin1210.de>
This commit is contained in:
parent
518232d853
commit
02372cb9ed
4
go.mod
4
go.mod
|
@ -3,7 +3,7 @@ module git.ailur.dev/ailur/fulgens
|
|||
go 1.23.1
|
||||
|
||||
require (
|
||||
git.ailur.dev/ailur/fg-library v1.0.1
|
||||
git.ailur.dev/ailur/fg-library/v2 v2.0.0
|
||||
git.ailur.dev/ailur/fg-nucleus-library v1.0.0
|
||||
git.ailur.dev/ailur/pow v1.0.0
|
||||
github.com/cespare/xxhash/v2 v2.3.0
|
||||
|
@ -19,7 +19,7 @@ require (
|
|||
|
||||
require (
|
||||
github.com/dustin/go-humanize v1.0.1 // indirect
|
||||
github.com/gabriel-vasile/mimetype v1.4.5 // indirect
|
||||
github.com/gabriel-vasile/mimetype v1.4.6 // indirect
|
||||
github.com/go-playground/locales v0.14.1 // indirect
|
||||
github.com/go-playground/universal-translator v0.18.1 // indirect
|
||||
github.com/hashicorp/golang-lru/v2 v2.0.7 // indirect
|
||||
|
|
8
go.sum
8
go.sum
|
@ -1,5 +1,5 @@
|
|||
git.ailur.dev/ailur/fg-library v1.0.1 h1:7TY2shmYNfKPzCTeYC80uj+sFZPbBWeOlqKT6ZsKFmc=
|
||||
git.ailur.dev/ailur/fg-library v1.0.1/go.mod h1:hOUkxs2rRouSwNnNZlo7CsFVH12kmjqheyzPQ4to1N8=
|
||||
git.ailur.dev/ailur/fg-library/v2 v2.0.0 h1:NanDV52W+NBu96v/HPDPGqH8NOxLp6MRrRdXLPEsgYw=
|
||||
git.ailur.dev/ailur/fg-library/v2 v2.0.0/go.mod h1:1jYbWhabGcIwp7CkhHqvRwC8eP+nHv5BrXPe9NX2HE8=
|
||||
git.ailur.dev/ailur/fg-nucleus-library v1.0.0 h1:TT1V4cfka+uUpvV1zU7bc4KXFkgnsI/sIvaZDDxXk+k=
|
||||
git.ailur.dev/ailur/fg-nucleus-library v1.0.0/go.mod h1:m4gNSEypfgrUV8bXaR8NLB8zchUM59y0ellV1wp/C+I=
|
||||
git.ailur.dev/ailur/pow v1.0.0 h1:eCJiZSbskcmzmwR4Nv4YrYpsZci5kfoGM9ihkXAHHoU=
|
||||
|
@ -10,8 +10,8 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c
|
|||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY=
|
||||
github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto=
|
||||
github.com/gabriel-vasile/mimetype v1.4.5 h1:J7wGKdGu33ocBOhGy0z653k/lFKLFDPJMG8Gql0kxn4=
|
||||
github.com/gabriel-vasile/mimetype v1.4.5/go.mod h1:ibHel+/kbxn9x2407k1izTA1S81ku1z/DlgOW2QE0M4=
|
||||
github.com/gabriel-vasile/mimetype v1.4.6 h1:3+PzJTKLkvgjeTbts6msPJt4DixhT4YtFNf1gtGe3zc=
|
||||
github.com/gabriel-vasile/mimetype v1.4.6/go.mod h1:JX1qVKqZd40hUPpAfiNTe0Sne7hdfKSbOqqmkq8GCXc=
|
||||
github.com/go-chi/chi/v5 v5.0.0/go.mod h1:BBug9lr0cqtdAhsu6R4AAdvufI0/XBzAQSsUqJpoZOs=
|
||||
github.com/go-chi/chi/v5 v5.1.0 h1:acVI1TYaD+hhedDJ3r54HyA6sExp3HfXq7QWEEY/xMw=
|
||||
github.com/go-chi/chi/v5 v5.1.0/go.mod h1:DslCQbL2OYiznFReuXYUmQ2hGd1aDpCnlMNITLSKoi8=
|
||||
|
|
59
main.go
59
main.go
|
@ -2,7 +2,8 @@ package main
|
|||
|
||||
import (
|
||||
"errors"
|
||||
library "git.ailur.dev/ailur/fg-library"
|
||||
"fmt"
|
||||
library "git.ailur.dev/ailur/fg-library/v2"
|
||||
"io"
|
||||
"log"
|
||||
"os"
|
||||
|
@ -60,9 +61,10 @@ var (
|
|||
slog.Info(r.Method + " " + r.URL.Path)
|
||||
})
|
||||
}
|
||||
validate *validator.Validate
|
||||
services = make(map[uuid.UUID]Service)
|
||||
lock sync.RWMutex
|
||||
validate *validator.Validate
|
||||
services = make(map[uuid.UUID]Service)
|
||||
lock sync.RWMutex
|
||||
hostRouter = hostrouter.New()
|
||||
)
|
||||
|
||||
func processInterServiceMessage(channel chan library.InterServiceMessage, config Config) {
|
||||
|
@ -90,6 +92,23 @@ func processInterServiceMessage(channel chan library.InterServiceMessage, config
|
|||
ServiceMetadata: services[message.ServiceID].ServiceMetadata,
|
||||
}
|
||||
lock.Unlock()
|
||||
|
||||
if message.Message != nil {
|
||||
// Add its router to the host router
|
||||
serviceConfig, ok := config.Services[strings.ToLower(services[message.ServiceID].ServiceMetadata.Name)]
|
||||
if !ok {
|
||||
slog.Error("Service configuration not found for service: " + services[message.ServiceID].ServiceMetadata.Name)
|
||||
os.Exit(1)
|
||||
}
|
||||
if serviceConfig.(map[string]interface{})["subdomain"] != nil {
|
||||
hostRouter.Map(serviceConfig.(map[string]interface{})["subdomain"].(string), message.Message.(*chi.Mux))
|
||||
fmt.Println("Mapped subdomain " + serviceConfig.(map[string]interface{})["subdomain"].(string) + " to service " + services[message.ServiceID].ServiceMetadata.Name)
|
||||
} else {
|
||||
hostRouter.Map("*", message.Message.(*chi.Mux))
|
||||
fmt.Println("Mapped service " + services[message.ServiceID].ServiceMetadata.Name)
|
||||
}
|
||||
}
|
||||
|
||||
// Report a successful activation
|
||||
inbox <- library.InterServiceMessage{
|
||||
ServiceID: uuid.MustParse("00000000-0000-0000-0000-000000000001"),
|
||||
|
@ -478,7 +497,6 @@ func main() {
|
|||
// Create the router
|
||||
router := chi.NewRouter()
|
||||
router.Use(logger)
|
||||
hostRouter := hostrouter.New()
|
||||
|
||||
var globalOutbox = make(chan library.InterServiceMessage)
|
||||
|
||||
|
@ -564,20 +582,6 @@ func main() {
|
|||
}
|
||||
lock.Unlock()
|
||||
|
||||
// Check if they want a subdomain
|
||||
var finalRouter *chi.Mux
|
||||
serviceConfig, ok := config.Services[strings.ToLower(serviceInformation.Name)]
|
||||
if !ok {
|
||||
slog.Error("Service configuration not found for service: ", serviceInformation.Name)
|
||||
os.Exit(1)
|
||||
}
|
||||
if serviceConfig.(map[string]interface{})["subdomain"] != nil {
|
||||
finalRouter = chi.NewRouter()
|
||||
hostRouter.Map(serviceConfig.(map[string]interface{})["subdomain"].(string), finalRouter)
|
||||
} else {
|
||||
finalRouter = router
|
||||
}
|
||||
|
||||
slog.Info("Activating service " + serviceInformation.Name + " with ID " + serviceInformation.ServiceID.String())
|
||||
|
||||
// Check if they want a resource directory
|
||||
|
@ -588,7 +592,6 @@ func main() {
|
|||
Outbox: globalOutbox,
|
||||
Inbox: inbox,
|
||||
ResourceDir: os.DirFS(filepath.Join(config.Global.ResourceDirectory, serviceInformation.ServiceID.String())),
|
||||
Router: finalRouter,
|
||||
})
|
||||
} else {
|
||||
main.(func(library.ServiceInitializationInformation))(library.ServiceInitializationInformation{
|
||||
|
@ -596,7 +599,6 @@ func main() {
|
|||
Configuration: config.Services[strings.ToLower(serviceInformation.Name)].(map[string]interface{}),
|
||||
Outbox: globalOutbox,
|
||||
Inbox: inbox,
|
||||
Router: finalRouter,
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -604,6 +606,21 @@ func main() {
|
|||
slog.Info("Service " + serviceInformation.Name + " activated with ID " + serviceInformation.ServiceID.String())
|
||||
}
|
||||
|
||||
// Wait for all the services to have their activations confirmed
|
||||
var allActivated bool
|
||||
for !allActivated {
|
||||
lock.RLock()
|
||||
allActivated = true
|
||||
for _, service := range services {
|
||||
if !service.ActivationConfirmed {
|
||||
allActivated = false
|
||||
break
|
||||
}
|
||||
}
|
||||
lock.RUnlock()
|
||||
time.Sleep(500 * time.Millisecond)
|
||||
}
|
||||
|
||||
// Start the server
|
||||
slog.Info("Starting server on " + config.Global.IP + ":" + config.Global.Port)
|
||||
router.Mount("/", hostRouter)
|
||||
|
|
|
@ -2,7 +2,7 @@ package main
|
|||
|
||||
import (
|
||||
// Fulgens libraries
|
||||
library "git.ailur.dev/ailur/fg-library"
|
||||
library "git.ailur.dev/ailur/fg-library/v2"
|
||||
authLibrary "git.ailur.dev/ailur/fg-nucleus-library"
|
||||
"git.ailur.dev/ailur/pow"
|
||||
|
||||
|
@ -30,6 +30,7 @@ import (
|
|||
|
||||
// External libraries
|
||||
"github.com/cespare/xxhash/v2"
|
||||
"github.com/go-chi/chi/v5"
|
||||
"github.com/golang-jwt/jwt/v5"
|
||||
"github.com/google/uuid"
|
||||
_ "modernc.org/sqlite"
|
||||
|
@ -341,7 +342,7 @@ func Main(information library.ServiceInitializationInformation) {
|
|||
}
|
||||
|
||||
// Set up the router
|
||||
router := information.Router
|
||||
router := chi.NewRouter()
|
||||
|
||||
// Set up the static routes
|
||||
staticDir, err := fs.Sub(information.ResourceDir, "static")
|
||||
|
@ -1781,6 +1782,6 @@ func Main(information library.ServiceInitializationInformation) {
|
|||
ForServiceID: uuid.MustParse("00000000-0000-0000-0000-000000000001"), // Activation service
|
||||
MessageType: 0,
|
||||
SentAt: time.Now(),
|
||||
Message: true,
|
||||
Message: router,
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,7 +3,7 @@ package main
|
|||
import (
|
||||
"database/sql"
|
||||
"errors"
|
||||
library "git.ailur.dev/ailur/fg-library"
|
||||
library "git.ailur.dev/ailur/fg-library/v2"
|
||||
"path/filepath"
|
||||
|
||||
"io"
|
||||
|
@ -426,6 +426,6 @@ func Main(information library.ServiceInitializationInformation) {
|
|||
ForServiceID: uuid.MustParse("00000000-0000-0000-0000-000000000001"), // Activation service
|
||||
MessageType: 0,
|
||||
SentAt: time.Now(),
|
||||
Message: true,
|
||||
Message: nil,
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue