// update project func UpdateProject(id int64, name string, icon string, description string) error { o := orm.NewOrm() o.Using("default") var pro *Project var err error if 0 != id { pro, err = GetProject(int(id), "") if err != nil { return err } } else { return errors.New("id should not 0") } log.Pinkln(pro) pro.Name = name pro.IconUrl = icon pro.Description = description _, err = o.Update(pro, "name", "icon_url", "description") return err }
// run native code(compiled via c/c++) in sandbox func RunNativeInSandbox(runScript string, runPath string, time int, mem int) error { var argTime string var argMem string var binFilePath string var err error if time > 0 { argTime = fmt.Sprintf("%d", time) } else { argTime = "10" } if mem > 0 { argMem = fmt.Sprintf("%d", mem) } else { argMem = "1024" } currentPath, _ := os.Getwd() os.Chdir(runPath) if runtime.GOOS == "windows" { binFilePath = filepath.Join(runPath, "a.exe") } else { binFilePath = filepath.Join(runPath, "a.out") } runScript = filepath.Join(currentPath, runScript) log.Pinkln(runScript, binFilePath, argTime, argMem, ) if runtime.GOOS == "windows" { err = runnerWin(runScript, binFilePath, argTime, argMem, ) } else { err = runnerNix(runScript, binFilePath, argTime, argMem, ) } os.Chdir(currentPath) return err }
func (this *ProjectListController) UpdateProject() { // if not login, permission deny user := this.GetSession("username") if user == nil { this.Data["json"] = map[string]interface{}{"result": false, "msg": "login first please", "refer": nil} this.ServeJson() return } // log.Pinkln(user) paramsBody := string(this.Ctx.Input.RequestBody) var params map[string]interface{} p, err := com.JsonDecode(paramsBody) if err != nil { this.Data["json"] = map[string]interface{}{"result": false, "msg": "parse params failed", "refer": "/"} this.ServeJson() return } else { params = p.(map[string]interface{})["params"].(map[string]interface{}) } log.Pinkln(params) id := int64(params["id"].(float64)) name := params["name"].(string) icon := params["icon"].(string) description := params["description"].(string) log.Pinkln(id) err = models.UpdateProject(id, name, icon, description) if err != nil { this.Data["json"] = map[string]interface{}{"result": false, "msg": "修改失败", "error": err} } else { this.Data["json"] = map[string]interface{}{"result": true, "msg": "修改成功"} } this.ServeJson() }
// call gcc compiler in other os func (this *Compile) gcc(id int) error { os.Chdir(this.itemBuildPath) var cmd *exec.Cmd log.Pinkln("cmd", "/K", this.compiler_c, this.codeFilePath, this.itemBuildPath, ) if runtime.GOOS == "windows" { cmd = exec.Command("cmd", "/K", this.compiler_c, this.codeFilePath, this.itemBuildPath, ) } else { cmd = exec.Command("sh", this.compiler_c, this.codeFilePath, this.itemBuildPath, ) } err := cmd.Start() if err != nil { log.Warnln("Start Failed") log.Warnln(err) } stn := time.Now() BuildStartTime = stn.UnixNano() go checkTimer(cmd, this, id) BuildProcessHaveExit = false err = cmd.Wait() BuildProcessHaveExit = true if err != nil { log.Warnln("Wait Failed") log.Warnln(err) } os.Chdir(this.currentPath) return err }
func DelCache(key string) error { if cc == nil { return errors.New("cc is nil") } defer func() { if r := recover(); r != nil { log.Redf("get cache error caught: %v\n", r) cc = nil } }() err := cc.Delete(key) if err != nil { return errors.New("Cache删除失败") } else { log.Pinkln("删除Cache成功 " + key) return nil } }
func TestConfig(t *testing.T) { Convey("Test Config sections", t, func() { conf := NewConfig("etc/test.ini") content, err := conf.readConfigFile() if err != nil { log.Redln(err) } else { log.Greenln("raw content") log.Pinkln("==============") log.Blueln(content) content = conf.filterComment() log.Greenln("filter comment") log.Pinkln("==============") log.Blueln(content) arraylize := conf.arraylize() log.Greenln("arraylize") log.Pinkln("==============") count := len(arraylize) log.Bluef("[%d]\n", count) for i := 0; i < count; i++ { log.Bluef("[%d]\t%s\n", i, arraylize[i]) } log.Greenln("parse items") log.Pinkln("==============") conf.parseItems() log.Greenln("warning stack") log.Pinkln("==============") log.Blueln(conf.GetWarnings()) log.Greenln("mistake value") log.Pinkln("==============") log.Blueln(conf.GetString("mysql", "host")) log.Greenln("about bool") log.Pinkln("==============") conf.SetBool("test", "dev", true) dev, _ := conf.GetBool("_", "dev") log.Blueln("%v", dev) content = conf.serialize() log.Greenln("serialize value") log.Pinkln("==============") log.Blueln(content) log.Greenln("hex") log.Pinkln("==============") hex, _ := conf.GetInt("_", "hex") log.Blueln(hex) log.Greenln("get empty") log.Pinkln("==============") _, err = conf.GetInt("_", "heloo") if err != nil { log.Blueln(err) } log.Greenln("save config file") log.Pinkln("==============") err := conf.Save("tmp/test.ini") if err == nil { log.Blueln("done!") } } val1, _ := conf.Get("_", "port") So(val1, ShouldEqual, 80) val2, _ := conf.GetString("_", "appname") So(val2, ShouldEqual, "my application") val3, _ := conf.GetString("mysql", "password") So(val3, ShouldEqual, "\"liju") val4, _ := conf.GetString("mysql", "host") So(val4, ShouldEqual, `"192.168.1.11" = GHJ`) val5, _ := conf.GetBool("_", "dev") So(val5, ShouldEqual, true) val6, _ := conf.GetFloat("_", "pi") So(val6, ShouldEqual, 3.14) val7, _ := conf.GetInt("_", "hex") So(val7, ShouldEqual, 0x24) val8 := conf.GetIntDefault("section", "key", 100) So(val8, ShouldEqual, 100) val9 := conf.GetStringDefault("mysql", "key", "") So(val9, ShouldEqual, "") }) }