DownloadSo.go 888 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. package lib
  2. import (
  3. "AIOTCOER/conf"
  4. "AIOTCOER/logs"
  5. "io"
  6. "net/http"
  7. "os"
  8. )
  9. var url = "https://yunlot.baozhida.cn/API/RunCode/Download?T_describe="
  10. func DownloadSo(T_analysis string) {
  11. //url := "http://example.com/file.txt"
  12. // 检查文件是否存在
  13. if _, err := os.Stat(conf.Analysis_Dir + T_analysis + ".so"); os.IsNotExist(err) {
  14. logs.PrintlnError("File does not exist.")
  15. } else {
  16. return
  17. }
  18. resp, err := http.Get(url + T_analysis)
  19. if err != nil {
  20. logs.PrintlnError("Error downloading file:", err)
  21. return
  22. }
  23. defer resp.Body.Close()
  24. out, err := os.Create(conf.Analysis_Dir + T_analysis + ".so")
  25. if err != nil {
  26. logs.PrintlnError("Error creating file:", err)
  27. return
  28. }
  29. defer out.Close()
  30. _, err = io.Copy(out, resp.Body)
  31. if err != nil {
  32. logs.PrintlnError("Error downloading file:", err)
  33. return
  34. }
  35. logs.Println("File downloaded successfully.")
  36. }