Ejemplo n.º 1
0
// 运行网页
func RunWeb(app gof.App, port int, debug, trace bool) {

	if debug {
		fmt.Println("[Started]:Web server (with debug) running on port [" +
			strconv.Itoa(port) + "]:")
		infrastructure.DebugMode = true
	} else {
		fmt.Println("[Started]:Web server running on port [" + strconv.Itoa(port) + "]:")
	}

	//socket client
	time.Sleep(time.Second * 2) //等待启动Socket
	API_DOMAIN = app.Config().GetString(variable.ApiDomain)
	goclient.Configure("tcp", app.Config().GetString(variable.ClientSocketServer), app)

	var in = getInterceptor(app)

	//注册路由
	RegisterRoutes(app)

	//启动服务
	err := http.ListenAndServe(":"+strconv.Itoa(port), in)

	if err != nil {
		app.Log().Fatalln("ListenAndServer ", err)
	}
}
Ejemplo n.º 2
0
func RunRestApi(app gof.App, port int) {
	fmt.Println("[ Go2o][ API][ Booted] - Api server running on port " + strconv.Itoa(port))

	//socket client
	time.Sleep(time.Second * 2) //等待启动Socket
	API_DOMAIN = app.Config().GetString(variable.ApiDomain)
	goclient.Configure("tcp", app.Config().GetString(variable.ClientSocketServer), app)

	var in *web.Interceptor = web.NewInterceptor(app, func(ctx *web.Context) {
		host := ctx.Request.URL.Host
		// todo: path compare
		if API_HOST_CHK && host != API_DOMAIN {
			http.Error(ctx.Response, "no such file", http.StatusNotFound)
			return
		}
		api.Handle(ctx)
	})

	//启动服务
	err := http.ListenAndServe(":"+strconv.Itoa(port), in)

	if err != nil {
		app.Log().Fatalln("ListenAndServer ", err)
	}
}
Ejemplo n.º 3
0
// 运行网页
func RunWeb(app gof.App, port int, debug, trace bool) {

	if debug {
		fmt.Println("[ Go2o][ Web][ Booted] - Web server (with debug) running on port " +
			strconv.Itoa(port))
		infrastructure.DebugMode = true
	} else {
		fmt.Println("[ Go2o][ Web][ Booted] - Web server running on port " + strconv.Itoa(port))
	}

	//socket client
	time.Sleep(time.Second * 2) //等待启动Socket
	API_DOMAIN = app.Config().GetString(variable.ApiDomain)

	var in = getInterceptor(app)

	//启动服务
	err := http.ListenAndServe(":"+strconv.Itoa(port), in)

	if err != nil {
		app.Log().Fatalln("ListenAndServer ", err)
	}
}
Ejemplo n.º 4
0
func (this *Shopping) setupOrder(ctx gof.App, v *shopping.ValueOrder,
	conf *partner.SaleConf, t time.Time, f func(error)) {
	var err error
	order := this.CreateOrder(v, nil)
	dur := time.Duration(t.Unix()-v.CreateTime) * time.Second

	if v.PaymentOpt == enum.PAY_ONLINE {
		if v.IsPaid == 0 && dur > time.Hour*order_timeout_hour {
			order.Cancel("超时未付款,系统取消")
			if ctx.Debug() {
				ctx.Log().Printf("[ AUTO][OrderSetup]:%s - Payment Timeout\n", v.OrderNo)
			}
		}
	} else if v.PaymentOpt == enum.PAY_OFFLINE {
		switch v.Status + 1 {
		case enum.ORDER_CONFIRMED:
			if dur > time.Minute*order_confirm_minute {
				err = order.Confirm()
				if ctx.Debug() {
					ctx.Log().Printf("[ AUTO][OrderSetup]:%s - Confirm \n", v.OrderNo)
				}

				shop, err := this.SmartChoiceShop(v.DeliverAddress)
				if err != nil {
					log.Println(err)
					order.Suspend("智能分配门店失败!原因:" + err.Error())
				} else {
					sv := shop.GetValue()
					order.SetShop(shop.GetDomainId())
					order.AppendLog(enum.ORDER_LOG_SETUP, false, fmt.Sprintf(
						"自动分配门店:%s,电话:%s", sv.Name, sv.Phone))
				}
			}
		case enum.ORDER_PROCESSING:
			if dur > time.Minute*order_process_minute {
				err = order.Process()
				if ctx.Debug() {
					ctx.Log().Printf("[ AUTO][OrderSetup]:%s - Processing \n", v.OrderNo)
				}
			}

		case enum.ORDER_SENDING:
			if dur > time.Minute*order_sending_minute {
				err = order.Deliver()
				if ctx.Debug() {
					ctx.Log().Printf("[ AUTO][OrderSetup]:%s - Sending \n", v.OrderNo)
				}
			}
		case enum.ORDER_RECEIVED:
			if dur > time.Hour*order_receive_hour {
				err = order.SignReceived()
				if ctx.Debug() {
					ctx.Log().Printf("[ AUTO][OrderSetup]:%s - Received \n", v.OrderNo)
				}
			}
		case enum.ORDER_COMPLETED:
			if dur > time.Hour*order_complete_hour {
				err = order.Complete()
				if ctx.Debug() {
					ctx.Log().Printf("[ AUTO][OrderSetup]:%s - Complete \n", v.OrderNo)
				}
			}
		}
	}

	if err != nil {
		f(err)
	}
}