Skip to content

Commit

Permalink
添加保存文件内容功能
Browse files Browse the repository at this point in the history
  • Loading branch information
luren5 committed Jul 23, 2017
1 parent c09f85d commit 770c0e9
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions cmd/IDE.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 44,8 @@ func startIDE() {
r.GET("/", index)
// upload file
r.POST("/upload-file", uploadFile)
// save file
r.POST("/save-file", saveFile)
// edit file
r.Any("/edit/:fileName", edit)
// new file
Expand Down Expand Up @@ -145,6 147,22 @@ func uploadFile(c *gin.Context) {
}
}

//save file
func saveFile(c *gin.Context) {
fileName := c.PostForm("fileName")
fileContent := c.PostForm("fileContent")
err := writeContent(fileName, fileContent)
var msg string
if err == nil {
msg = "Succeed in saving " fileName
} else {
msg = err.Error()
}
c.JSON(http.StatusOK, gin.H{
"msg": msg,
})
}

// new file
func newFile(c *gin.Context) {
fileName := c.Param("fileName")
Expand Down Expand Up @@ -192,7 210,7 @@ func doCompile(c *gin.Context) {
abi, _ := json.Marshal(contract.Info.AbiDefinition)
bin := contract.Code
r := make(map[string]string)
r["name"] = contractName
r["name"] = contractName ".sol"
r["bin"] = bin
r["abi"] = string(abi)
result = append(result, r)
Expand Down Expand Up @@ -241,7 259,7 @@ func getFileSet() []string {
}
var fileSet []string
for _, f := range files {
if f.IsDir() {
if f.IsDir() || !strings.HasSuffix(f.Name(), ".sol") {
continue
}
fileSet = append(fileSet, f.Name())
Expand Down

0 comments on commit 770c0e9

Please sign in to comment.