示例#1
0
func StartServer() {
	l4g.Info("Starting Server...")
	l4g.Info("Server is listening on " + os.Getenv("PORT"))

	go func() {
		err := Srv.Server.ListenAndServe()

		if err != nil {
			l4g.Critical("Error starting server, err:%v", err)
			time.Sleep(time.Second)
			panic("Error starting server " + err.Error())
		}
	}()
}
func main() {
	// Load the configuration (isn't this easy?)
	l4g.LoadConfiguration("example.xml")

	// And now we're ready!
	l4g.Finest("This will only go to those of you really cool UDP kids!  If you change enabled=true.")
	l4g.Debug("Oh no!  %d + %d = %d!", 2, 2, 2+2)
	l4g.Info("About that time, eh chaps?")
}
示例#3
0
func NewServer() {
	l4g.Info("Server is initializing...")

	router := NewRouter()

	Srv = &Server{
		Router: router,
		Server: manners.NewWithServer(&http.Server{
			Addr:           ":" + os.Getenv("PORT"),
			Handler:        router,
			ReadTimeout:    10 * time.Second,
			WriteTimeout:   10. * time.Second,
			MaxHeaderBytes: 1 << 20,
		}),
		Store: store.NewSqlStore(),
	}
}
示例#4
0
func getConnection() *gorm.DB {
	db, err := gorm.Open("postgres", "postgres://category_service-go:@127.0.0.1:5432/category_service-go?sslmode=disable")
	if err != nil {
		l4g.Critical("Failed to open sql connection to err:%v", err)
		time.Sleep(time.Second)
		panic("Failed to open sql connection " + err.Error())
	}

	db.DB()

	l4g.Info("Pinging sql postgres database")
	err = db.DB().Ping()
	if err != nil {
		l4g.Critical("Failed to ping db err:%v", err)
		time.Sleep(time.Second)
		panic("Failed  to open sql connection " + err.Error())
	}

	db.DB().SetMaxIdleConns(10)
	db.DB().SetMaxOpenConns(100)

	return &db
}
示例#5
0
func (ss SqlStore) Close() {
	l4g.Info("Closing SqlStore")
	ss.db.Close()
}
示例#6
0
func StopServer() {
	l4g.Info("Stopping Server...")
	Srv.Server.Close()
	Srv.Store.Close()
	l4g.Info("Server stopped")
}