DownloadSo.go 851 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. package lib
  2. import (
  3. "Yunlot/conf"
  4. "fmt"
  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. fmt.Println("File does not exist.")
  15. } else {
  16. return
  17. }
  18. resp, err := http.Get(url + T_analysis)
  19. if err != nil {
  20. fmt.Println("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. fmt.Println("Error creating file:", err)
  27. return
  28. }
  29. defer out.Close()
  30. _, err = io.Copy(out, resp.Body)
  31. if err != nil {
  32. fmt.Println("Error downloading file:", err)
  33. return
  34. }
  35. fmt.Println("File downloaded successfully.")
  36. }