示例#1
0
文件: postgres.go 项目: cycps/addie
func ReadSimSettingsByDesignId(design_id int) (*addie.SimSettings, error) {

	q := fmt.Sprintf(
		"SELECT tbegin, tend, max_step FROM sim_settings WHERE design_id = %d",
		design_id)

	rows, err := runQ(q)
	defer safeClose(rows)
	if err != nil {
		return nil, selectFailure(err)
	}

	if !rows.Next() {
		return nil, emptyReadFailure()
	}
	var begin, end, maxStep float64
	err = rows.Scan(&begin, &end, &maxStep)
	if err != nil {
		return nil, scanFailure(err)
	}
	rows.Close()

	s := addie.SimSettings{}
	s.Begin = begin
	s.End = end
	s.MaxStep = maxStep

	return &s, nil

}
示例#2
0
文件: main.go 项目: cycps/addie
func newXP(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {

	user, err := getUser(r)
	if err != nil {
		w.WriteHeader(401)
		return
	}

	msg := new(protocol.NewXP)
	err = protocol.Unpack(r, &msg)
	if err != nil {
		log.Printf("error unpacking newXP message")
		log.Println(err)
		w.WriteHeader(400)
		return
	}

	log.Printf("Creating xp '%s` for user `%s`", msg.Name, user)

	err = db.CreateDesign(msg.Name, user)
	if err != nil {
		log.Println(err)
		log.Printf("[newXP] error creating design entry db")
		w.WriteHeader(500)
		return
	}

	design_key, err := db.ReadDesignKey(msg.Name, user)
	if err != nil {
		log.Println(err)
		log.Printf("[newXP] error reading design key")
		w.WriteHeader(500)
		return
	}

	//use the default sim settings to begin with
	s := addie.SimSettings{}
	s.Begin = 0
	s.End = 10
	s.MaxStep = 1e-3

	err = db.CreateSimSettings(s, design_key)
	if err != nil {
		log.Println(err)
		log.Println("[newXP] error creating default sim settings")
		w.WriteHeader(500)
		return
	}

	w.WriteHeader(200)
}