mirror of
				https://github.com/lzh-1625/go_process_manager.git
				synced 2025-10-31 11:26:49 +08:00 
			
		
		
		
	
		
			
				
	
	
		
			34 lines
		
	
	
		
			958 B
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			34 lines
		
	
	
		
			958 B
		
	
	
	
		
			Go
		
	
	
	
	
	
| package api
 | |
| 
 | |
| import (
 | |
| 	"github.com/lzh-1625/go_process_manager/internal/app/service"
 | |
| 
 | |
| 	"github.com/gin-gonic/gin"
 | |
| )
 | |
| 
 | |
| type file struct{}
 | |
| 
 | |
| var FileApi = new(file)
 | |
| 
 | |
| func (f *file) FilePathHandler(ctx *gin.Context) {
 | |
| 	path := getQueryString(ctx, "path")
 | |
| 	rOk(ctx, "Operation successful!", service.FileService.GetFileAndDirByPath(path))
 | |
| }
 | |
| 
 | |
| func (f *file) FileWriteHandler(ctx *gin.Context) {
 | |
| 	path := ctx.PostForm("filePath")
 | |
| 	fi, err := ctx.FormFile("data")
 | |
| 	errCheck(ctx, err != nil, "Read file data failed!")
 | |
| 	fiReader, _ := fi.Open()
 | |
| 	err = service.FileService.UpdateFileData(path, fiReader, fi.Size)
 | |
| 	errCheck(ctx, err != nil, "Update file data operation failed!")
 | |
| 	rOk(ctx, "Operation successful!", nil)
 | |
| }
 | |
| 
 | |
| func (f *file) FileReadHandler(ctx *gin.Context) {
 | |
| 	path := getQueryString(ctx, "filePath")
 | |
| 	bytes, err := service.FileService.ReadFileFromPath(path)
 | |
| 	errCheck(ctx, err != nil, "Operation failed!")
 | |
| 	rOk(ctx, "Operation successful!", string(bytes))
 | |
| }
 | 
