示例#1
0
文件: main.go 项目: sporto/kic
func main() {
	// err := godotenv.Load()
	// if err != nil {
	// 	// production don't use an env file
	// 	log.Println("No .env file found")
	// }

	dbSession, err := api.StartDb("./")
	if err != nil {
		log.Fatal(err)
	}

	api.MapRoutes(dbSession)

	log.Print("Starting Goweb powered server...")

	// make a http server using the goweb.DefaultHttpHandler()
	s := &http.Server{
		Addr:           Address,
		Handler:        goweb.DefaultHttpHandler(),
		ReadTimeout:    10 * time.Second,
		WriteTimeout:   10 * time.Second,
		MaxHeaderBytes: 1 << 20,
	}

	listener, listenErr := net.Listen("tcp", Address)
	log.Printf("  visit: %s", Address)

	if listenErr != nil {
		log.Fatalf("Could not listen: %s", listenErr)
	}

	log.Println("Routes:")
	log.Printf("%s", goweb.DefaultHttpHandler())

	// listen for exit signal i.e. ctrl + C
	signalChannel := make(chan os.Signal, 1)
	signal.Notify(signalChannel, os.Interrupt)

	go func() {

		for _ = range signalChannel {
			// sig is a ^C, handle it
			log.Println("^C")
			// stop the HTTP server
			log.Println("Stopping the server...")
			listener.Close()

			os.Exit(0)
		}
	}()

	// begin the server
	log.Fatalf("Error in Serve: %s", s.Serve(listener))

}
示例#2
0
func TestTransactions(t *testing.T) {
	RegisterFailHandler(Fail)

	os.Setenv("ENV", "test")

	err := errors.New("")
	dbSession, err = api.StartDb("../../../")
	if err != nil {
		log.Fatal("Cannot connect to DB")
	}

	RunSpecs(t, "Transactions Suite")
}
示例#3
0
文件: accounts.go 项目: sporto/kic
	"github.com/chuckpreslar/gofer"
	"github.com/sporto/kic/api"
	"github.com/sporto/kic/api/models"
	"github.com/sporto/kic/api/services/accounts"
	"log"
	"time"
)

var TaskOne = gofer.Register(gofer.Task{
	Namespace:   "accounts",
	Label:       "create",
	Description: "Create Nico's account",
	Action: func(arguments ...string) (err error) {
		log.Println("accounts:create")

		dbSession, err := api.StartDb("./")
		if err != nil {
			log.Fatal(err)
		}

		account := &models.Account{
			Name:             "Test",
			LastInterestPaid: time.Now(),
		}

		serv := &accounts.CreateServ{}
		_, err = serv.Run(dbSession, *account)
		if err != nil {
			log.Fatal(err)
		}