Beispiel #1
0
func StartCamera() {
	faceClient = &gofaceplus.FaceClient{
		conf.Get("face_server"),
		conf.Get("face_api_key"),
		conf.Get("face_secret"),
	}
	timer := time.NewTicker(5 * time.Second)
	for {
		select {
		case <-timer.C:
			detect("/var/www/html/pi.jpg")
			//detect("/tmp/1.jpg")
		}
	}
}
Beispiel #2
0
func OpenMysql() (*sql.DB, error) {
	db, err := sql.Open("mysql", conf.Get("mysql"))
	if db != nil {
		db.SetMaxIdleConns(90)
		db.SetMaxOpenConns(90)
	}
	return db, err
}
Beispiel #3
0
func init() {
	appConf := `
		<seelog type="sync">
			<outputs>
				<rollingfile type="date" filename="./logs/` + os.Args[0] + `.log" datepattern="20060102" formatid="main"/>
			</outputs>
			<formats>
				<format id="main" format="%Date %Time [%LEV] | %Msg%n"/>
			</formats>
		</seelog>`
	var err error
	logger, err = seelog.LoggerFromConfigAsBytes([]byte(appConf))
	if err != nil {
		fmt.Errorf("Error loading log configuration: %s \n", err.Error())
		panic(err)
	}
	Mclient = memcache.New(conf.Get("memcached"))
	sessionStore = sessions.NewCookieStore([]byte(conf.Get("cookie_secret")))
}
Beispiel #4
0
func handleOauthRedirect(w http.ResponseWriter, r *http.Request) {
	code := r.FormValue("code")
	utils.Debugf("Oauth redirect, code: %s", code)
	resp, err := http.PostForm("https://login.uber.com.cn/oauth/v2/token", url.Values{
		"client_secret": {conf.Get("uber_client_secret")},
		"client_id":     {"DV6gJE19BMU6LIh0jJYAvtFyel8rpCfe"},
		"grant_type":    {"authorization_code"},
		"redirect_uri":  {"https://tripwar.laoyou.mobi/oauth_redirect"},
		"code":          {code},
	})
	if err != nil {
		utils.Errorf("Error post to oauth: %s", err.Error())
		w.Write([]byte("500"))
		return
	}
	defer resp.Body.Close()
	body, err := ioutil.ReadAll(resp.Body)
	result := &OauthResult{}
	if err = json.Unmarshal(body, result); err != nil {
		utils.Errorf("Error unmarshal oauth result: %s", err.Error())
		w.Write([]byte("500"))
		return
	}
	utils.Debugf("access token: %s", result.AccessToken)
	sid := uniuri.NewLen(10)
	sids = append(sids, sid)
	utils.SetCache(sid+"_access_token", result.AccessToken, 86400)
	go func(token string) {
		profile, err := uber.GetUserProfile(token)
		if err != nil {
			utils.Errorf("Error get user profile: %s", err.Error())
			return
		}
		user := &models.User{
			Id:              profile.Uuid,
			Name:            profile.FirstName + " " + profile.LastName,
			UberOpenId:      profile.Uuid,
			Faction:         int64(rand.Intn(2)),
			TotalScore:      10000,
			Score:           0,
			Mana:            10,
			Hp:              10,
			Lng:             116.310228,
			Lat:             39.979233,
			LocationBearing: 33,
		}
		utils.Debugf("user: %v", user)
		users[sid] = user
	}(result.AccessToken)
	go func(sid string) {
		timer := time.NewTicker(30 * time.Second)
		for {
			select {
			case <-timer.C:
				token := utils.GetCache(sid + "_access_token")
				current, _ := uber.GetCurrent(token)
				utils.Debugf("current: %v", current)
				sidCurrent[sid] = current
			}
		}
	}(sid)
	http.Redirect(w, r, "http://tripwar.laoyou.mobi/html/index.html?sid="+sid, 302)
}