func main() { log = logger.Log("main") app = NewApp() log.Notice("Hello!") log.Notice("Loading Directory") err := app.LoadServices() if err != nil { log.Fatalf("Could not load directory") } log.Notice("Starting foodtastechess") app.Start() c := make(chan os.Signal, 1) signal.Notify(c, os.Interrupt, syscall.SIGTERM) for { select { case <-app.StopChan: log.Notice("Quitting.") return case <-c: fmt.Println("") app.Stop() } } }
func NewQueryBuffer() events.EventSubscriber { buffer := new(QueryBuffer) buffer.log = logger.Log("querybuffer") buffer.queries = make(chan Query, 100) buffer.stopChan = make(chan bool, 1) return buffer }
func (suite *EventsTestSuite) SetupTest() { suite.InitTestConfig() suite.log = logger.Log("events_test") var ( d directory.Directory events *EventsService subscriber *MockSubscriber ) events = NewEvents().(*EventsService) subscriber = newMockSubscriber().(*MockSubscriber) d = directory.New() d.AddService("configProvider", suite.ConfigProvider) d.AddService("eventSubscriber", subscriber) d.AddService("events", events) if err := d.Start(); err != nil { suite.log.Fatalf("Could not start directory: %v", err) } suite.events = events suite.mockSubscriber = subscriber suite.events.ResetTestDB() }
// SetupTest prepares the test suite for running by making a fake system // query service, providing it to a real client query service (the one we // are testing) func (suite *ClientQueriesTestSuite) SetupTest() { suite.log = logger.Log("client_test") var ( d directory.Directory systemQueries MockSystemQueries clientQueries ClientQueryService mockUsers MockUsers ) systemQueries.complete = true // Set up a directory with: // - A real ClientQueryService (The one we are testing) // - The mocked SystemQueries implementation d = directory.New() d.AddService("clientQueries", &clientQueries) d.AddService("systemQueries", &systemQueries) d.AddService("users", &mockUsers) // Populate the directory so that clientQueries knows to use our mocked // systemQueries if err := d.Start(); err != nil { suite.log.Fatalf("Could not start directory (%v)", err) } // Store references for use in tests suite.mockSystemQueries = &systemQueries suite.clientQueries = &clientQueries suite.mockUsers = &mockUsers }
func (suite *QueryTestSuite) SetupTest() { suite.log = logger.Log("queries_test") var ( d directory.Directory systemQueries MockSystemQueries gameCalculator MockGameCalculator events MockEventsService queriesCache MockQueriesCache ) d = directory.New() suite.InitTestConfig() d.AddService("configProvider", suite.ConfigProvider) d.AddService("systemQueries", &systemQueries) d.AddService("gameCalculator", &gameCalculator) d.AddService("eventsService", &events) d.AddService("queriesCache", &queriesCache) if err := d.Start(); err != nil { suite.log.Fatalf("Could not start directory: %v", err) } suite.mockSystemQueries = &systemQueries suite.mockGameCalculator = &gameCalculator suite.mockEvents = &events suite.mockQueriesCache = &queriesCache }
func (cfg *viperProvider) initLogging() { var C logger.LoggerConfig err := viper.MarshalKey("logger", &C) if err != nil { panic(fmt.Errorf("Can't parse: %s \n", err)) } logger.InitLog(C) cfg.log = logger.Log("config") }
func (suite *QueriesCacheTestSuite) SetupTest() { suite.InitTestConfig() suite.log = logger.Log("cache_test") var ( d directory.Directory cache *queriesCache ) cache = NewQueriesCache().(*queriesCache) d = directory.New() d.AddService("configProvider", suite.ConfigProvider) d.AddService("queriesCache", cache) if err := d.Start(); err != nil { suite.log.Fatalf("Could not start directory: %v", err) } suite.cache = cache suite.cache.collection.Remove(map[string]string{}) }
import ( "errors" "fmt" "github.com/gorilla/context" "github.com/markbates/goth" "github.com/markbates/goth/providers/gplus" "net/http" "net/url" "foodtastechess/config" "foodtastechess/logger" sess "foodtastechess/server/session" "foodtastechess/users" ) var log = logger.Log("auth") type Authentication interface { LoginRequired(res http.ResponseWriter, req *http.Request, next http.HandlerFunc) } type authService struct { Config config.AuthConfig `inject:"authConfig"` SessionConfig config.SessionConfig `inject:"sessionConfig"` Users users.Users `inject:"users"` provider goth.Provider } func New() Authentication { return new(authService)
import ( "fmt" "github.com/ant0ine/go-json-rest/rest" "math/rand" "net/http" "strconv" "foodtastechess/commands" "foodtastechess/game" "foodtastechess/logger" "foodtastechess/queries" "foodtastechess/users" ) var log = logger.Log("chessApi") type ChessApi struct { Queries queries.ClientQueries `inject:"clientQueries"` Commands commands.Commands `inject:"commands"` restApi *rest.Api } func New() *ChessApi { return new(ChessApi) } func (api *ChessApi) PostPopulate() error { restApi := rest.NewApi() restApi.Use(
package directory import ( "errors" "fmt" "foodtastechess/logger" ) var log = logger.Log("directory") type Directory interface { AddService(name string, object interface{}) error Start(names ...string) error Stop(names ...string) error } func New() Directory { directory := new(graphDirectory) directory.graph = newGraph() directory.services = make(map[string]lifecycleService) directory.populated = false return directory } type Provider func(name string, value interface{}) error type graphDirectory struct { graph graph
func (suite *IntegrationTestSuite) SetupTest() { configProvider := config.NewConfigProvider("testconfig", "./") suite.log = logger.Log("integration_test") suite.Commands = commands.New() suite.Queries = queries.NewClientQueryService() systemQueries := queries.NewSystemQueryService().(*queries.SystemQueryService) eventsService := events.NewEvents().(*events.EventsService) usersService := users.NewUsers().(*users.UsersService) d := directory.New() d.AddService("configProvider", configProvider) d.AddService("gameCalculator", game.NewGameCalculator()) d.AddService("eventSubscriber", queries.NewQueryBuffer()) d.AddService("systemQueries", systemQueries) d.AddService("events", eventsService) d.AddService("users", usersService) d.AddService("commands", suite.Commands) d.AddService("clientQueries", suite.Queries) err := d.Start() if err != nil { suite.log.Fatalf("Could not start directory: %v", err) } err = d.Start("eventSubscriber") if err != nil { msg := fmt.Sprintf("Could not start event subscriber: %v", err) log.Error(msg) return } usersService.ResetTestDB() eventsService.ResetTestDB() systemQueries.Cache.Flush() time.Sleep(1 * time.Second) white := users.User{ Uuid: users.NewId(), Name: "whitePlayer", AuthIdentifier: "whiteAuthId", } usersService.Save(&white) black := users.User{ Uuid: users.NewId(), Name: "blackPlayer", AuthIdentifier: "blackAuthId", } usersService.Save(&black) suite.log.Info("white UUID: %s", white.Uuid) suite.log.Info("black UUID: %s", black.Uuid) suite.whiteId = white.Uuid suite.blackId = black.Uuid }
package fixtures import ( "github.com/op/go-logging" "math/rand" "time" "foodtastechess/events" "foodtastechess/game" "foodtastechess/logger" "foodtastechess/queries" "foodtastechess/users" ) var log *logging.Logger = logger.Log("fixtures") type Fixtures struct { Events events.Events `inject:"events"` Users users.Users `inject:"users"` Queries queries.ClientQueries `inject:"clientQueries"` } func NewFixtures() *Fixtures { return new(Fixtures) } func (f *Fixtures) Start() error { log.Info("Resetting events") eventsService := f.Events.(*events.EventsService) eventsService.ResetTestDB()
func NewClientQueryService() *ClientQueryService { cqs := new(ClientQueryService) cqs.log = logger.Log("clientqueries") return cqs }
"github.com/codegangsta/negroni" "github.com/rs/cors" "gopkg.in/tylerb/graceful.v1" "net" "net/http" "time" "foodtastechess/config" "foodtastechess/directory" "foodtastechess/logger" "foodtastechess/server/api" "foodtastechess/server/auth" ) var ( log = logger.Log("server") ) type Server struct { server *graceful.Server Api *api.ChessApi `inject:"chessApi"` Auth auth.Authentication `inject:"auth"` Config config.ServerConfig `inject:"serverConfig"` StopChan chan bool `inject:"stopChan"` } func New() *Server { return new(Server) } func (s *Server) PreProvide(provide directory.Provider) error {
package queries import ( "time" "foodtastechess/game" "foodtastechess/logger" "foodtastechess/users" ) var log = logger.Log("queries") type Query interface { hasResult() bool getResult() interface{} getDependentQueries() []Query computeResult(sqs SystemQueries) isExpired(now interface{}) bool getExpiration(now interface{}) interface{} hash() string } type queryRecord struct { Hash string ComputedAt time.Time } func GameQuery(id game.Id) Query {
func NewEvents() Events { service := new(EventsService) service.log = logger.Log("events") service.gameIdChan = make(chan game.Id, 1) return service }
package users import ( "database/sql/driver" "fmt" "github.com/satori/go.uuid" "time" "foodtastechess/logger" ) var log = logger.Log("user") type Id string func (u *Id) Scan(value interface{}) error { *u = Id(value.([]byte)) return nil } func (u Id) Value() (driver.Value, error) { return string(u), nil } type User struct { Id int `json:"-"` Uuid Id `sql:"unique_index" json:"-"` Name string AvatarUrl string AuthIdentifier string `sql:"unique_index" json:"-"` AccessToken string `json:"-"`
func NewSystemQueryService() SystemQueries { sqs := new(SystemQueryService) sqs.log = logger.Log("systemqueries") return sqs }