mirror of
https://github.com/elyby/chrly.git
synced 2025-01-03 18:51:49 +05:30
Implemented event dispatcher
This commit is contained in:
parent
2abe2db469
commit
db728451f8
9
Gopkg.lock
generated
9
Gopkg.lock
generated
@ -14,6 +14,14 @@
|
|||||||
revision = "f6df55f235c24f236d11dbcf665249a59ac2021f"
|
revision = "f6df55f235c24f236d11dbcf665249a59ac2021f"
|
||||||
version = "1.1"
|
version = "1.1"
|
||||||
|
|
||||||
|
[[projects]]
|
||||||
|
branch = "master"
|
||||||
|
digest = "1:33c6f6a0ee7d594d07ad9b67e93266f8a859ab2ddd882f8be19207162f40cce8"
|
||||||
|
name = "github.com/asaskevich/EventBus"
|
||||||
|
packages = ["."]
|
||||||
|
pruneopts = ""
|
||||||
|
revision = "d46933a94f05c6657d7b923fcf5ac563ee37ec79"
|
||||||
|
|
||||||
[[projects]]
|
[[projects]]
|
||||||
digest = "1:c7b11da9bf0707e6920e1b361fbbbbe9b277ef3a198377baa4527f6e31049be0"
|
digest = "1:c7b11da9bf0707e6920e1b361fbbbbe9b277ef3a198377baa4527f6e31049be0"
|
||||||
name = "github.com/certifi/gocertifi"
|
name = "github.com/certifi/gocertifi"
|
||||||
@ -301,6 +309,7 @@
|
|||||||
input-imports = [
|
input-imports = [
|
||||||
"github.com/SermoDigital/jose/crypto",
|
"github.com/SermoDigital/jose/crypto",
|
||||||
"github.com/SermoDigital/jose/jws",
|
"github.com/SermoDigital/jose/jws",
|
||||||
|
"github.com/asaskevich/EventBus",
|
||||||
"github.com/getsentry/raven-go",
|
"github.com/getsentry/raven-go",
|
||||||
"github.com/gorilla/mux",
|
"github.com/gorilla/mux",
|
||||||
"github.com/h2non/gock",
|
"github.com/h2non/gock",
|
||||||
|
@ -36,6 +36,10 @@ ignored = ["github.com/elyby/chrly"]
|
|||||||
name = "github.com/tevino/abool"
|
name = "github.com/tevino/abool"
|
||||||
branch = "master"
|
branch = "master"
|
||||||
|
|
||||||
|
[[constraint]]
|
||||||
|
branch = "master"
|
||||||
|
name = "github.com/asaskevich/EventBus"
|
||||||
|
|
||||||
# Testing dependencies
|
# Testing dependencies
|
||||||
|
|
||||||
[[constraint]]
|
[[constraint]]
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
package bootstrap
|
package bootstrap
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/elyby/chrly/http"
|
|
||||||
"net/url"
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
"time"
|
"time"
|
||||||
@ -14,6 +13,8 @@ import (
|
|||||||
"github.com/mono83/slf/wd"
|
"github.com/mono83/slf/wd"
|
||||||
"github.com/spf13/viper"
|
"github.com/spf13/viper"
|
||||||
|
|
||||||
|
"github.com/elyby/chrly/dispatcher"
|
||||||
|
"github.com/elyby/chrly/http"
|
||||||
"github.com/elyby/chrly/mojangtextures"
|
"github.com/elyby/chrly/mojangtextures"
|
||||||
"github.com/elyby/chrly/version"
|
"github.com/elyby/chrly/version"
|
||||||
)
|
)
|
||||||
@ -93,3 +94,7 @@ func CreateMojangUUIDsProvider(emitter http.Emitter) (mojangtextures.UUIDsProvid
|
|||||||
|
|
||||||
return uuidsProvider, nil
|
return uuidsProvider, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func CreateEventDispatcher() dispatcher.EventDispatcher {
|
||||||
|
return dispatcher.New()
|
||||||
|
}
|
||||||
|
@ -26,6 +26,8 @@ var serveCmd = &cobra.Command{
|
|||||||
}
|
}
|
||||||
logger.Info("Logger successfully initialized")
|
logger.Info("Logger successfully initialized")
|
||||||
|
|
||||||
|
dispatcher := bootstrap.CreateEventDispatcher()
|
||||||
|
|
||||||
storageFactory := db.StorageFactory{Config: viper.GetViper()}
|
storageFactory := db.StorageFactory{Config: viper.GetViper()}
|
||||||
|
|
||||||
logger.Info("Initializing skins repository")
|
logger.Info("Initializing skins repository")
|
||||||
@ -53,7 +55,7 @@ var serveCmd = &cobra.Command{
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
uuidsProvider, err := bootstrap.CreateMojangUUIDsProvider(nil)
|
uuidsProvider, err := bootstrap.CreateMojangUUIDsProvider(dispatcher)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Emergency("Unable to parse remote url :err", wd.ErrParam(err))
|
logger.Emergency("Unable to parse remote url :err", wd.ErrParam(err))
|
||||||
return
|
return
|
||||||
@ -62,10 +64,10 @@ var serveCmd = &cobra.Command{
|
|||||||
texturesStorage := mojangtextures.NewInMemoryTexturesStorage()
|
texturesStorage := mojangtextures.NewInMemoryTexturesStorage()
|
||||||
texturesStorage.Start()
|
texturesStorage.Start()
|
||||||
mojangTexturesProvider := &mojangtextures.Provider{
|
mojangTexturesProvider := &mojangtextures.Provider{
|
||||||
// TODO: configure emitter
|
Emitter: dispatcher,
|
||||||
UUIDsProvider: uuidsProvider,
|
UUIDsProvider: uuidsProvider,
|
||||||
TexturesProvider: &mojangtextures.MojangApiTexturesProvider{
|
TexturesProvider: &mojangtextures.MojangApiTexturesProvider{
|
||||||
// TODO: configure emitter
|
Emitter: dispatcher,
|
||||||
},
|
},
|
||||||
Storage: &mojangtextures.SeparatedStorage{
|
Storage: &mojangtextures.SeparatedStorage{
|
||||||
UuidsStorage: mojangUuidsRepository,
|
UuidsStorage: mojangUuidsRepository,
|
||||||
@ -76,6 +78,7 @@ var serveCmd = &cobra.Command{
|
|||||||
|
|
||||||
address := fmt.Sprintf("%s:%d", viper.GetString("server.host"), viper.GetInt("server.port"))
|
address := fmt.Sprintf("%s:%d", viper.GetString("server.host"), viper.GetInt("server.port"))
|
||||||
handler := (&http.Skinsystem{
|
handler := (&http.Skinsystem{
|
||||||
|
Emitter: dispatcher,
|
||||||
SkinsRepo: skinsRepo,
|
SkinsRepo: skinsRepo,
|
||||||
CapesRepo: capesRepo,
|
CapesRepo: capesRepo,
|
||||||
MojangTexturesProvider: mojangTexturesProvider,
|
MojangTexturesProvider: mojangTexturesProvider,
|
||||||
|
@ -22,7 +22,9 @@ var workerCmd = &cobra.Command{
|
|||||||
}
|
}
|
||||||
logger.Info("Logger successfully initialized")
|
logger.Info("Logger successfully initialized")
|
||||||
|
|
||||||
uuidsProvider, err := bootstrap.CreateMojangUUIDsProvider(logger)
|
dispatcher := bootstrap.CreateEventDispatcher()
|
||||||
|
|
||||||
|
uuidsProvider, err := bootstrap.CreateMojangUUIDsProvider(dispatcher)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Emergency("Unable to parse remote url :err", wd.ErrParam(err))
|
logger.Emergency("Unable to parse remote url :err", wd.ErrParam(err))
|
||||||
return
|
return
|
||||||
@ -30,8 +32,8 @@ var workerCmd = &cobra.Command{
|
|||||||
|
|
||||||
address := fmt.Sprintf("%s:%d", viper.GetString("server.host"), viper.GetInt("server.port"))
|
address := fmt.Sprintf("%s:%d", viper.GetString("server.host"), viper.GetInt("server.port"))
|
||||||
handler := (&http.UUIDsWorker{
|
handler := (&http.UUIDsWorker{
|
||||||
|
Emitter: dispatcher,
|
||||||
UUIDsProvider: uuidsProvider,
|
UUIDsProvider: uuidsProvider,
|
||||||
// TODO: configure emitter
|
|
||||||
}).CreateHandler()
|
}).CreateHandler()
|
||||||
|
|
||||||
finishChan := make(chan bool)
|
finishChan := make(chan bool)
|
||||||
|
26
dispatcher/dispatcher.go
Normal file
26
dispatcher/dispatcher.go
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
package dispatcher
|
||||||
|
|
||||||
|
import "github.com/asaskevich/EventBus"
|
||||||
|
|
||||||
|
type EventDispatcher interface {
|
||||||
|
Subscribe(name string, fn interface{})
|
||||||
|
Emit(name string, args ...interface{})
|
||||||
|
}
|
||||||
|
|
||||||
|
type LocalEventDispatcher struct {
|
||||||
|
bus EventBus.Bus
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *LocalEventDispatcher) Subscribe(name string, fn interface{}) {
|
||||||
|
_ = d.bus.Subscribe(name, fn)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *LocalEventDispatcher) Emit(name string, args ...interface{}) {
|
||||||
|
d.bus.Publish(name, args...)
|
||||||
|
}
|
||||||
|
|
||||||
|
func New() EventDispatcher {
|
||||||
|
return &LocalEventDispatcher{
|
||||||
|
bus: EventBus.New(),
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user