main.go 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. package main
  2. import (
  3. "errors"
  4. "fmt"
  5. "log"
  6. "os"
  7. "github.com/labstack/echo/v4"
  8. "github.com/labstack/echo/v4/middleware"
  9. )
  10. func main() {
  11. _, err := os.Stat("storage")
  12. if errors.Is(err, os.ErrNotExist) {
  13. err2 := os.Mkdir("storage", 0775)
  14. if err2 != nil {
  15. log.Panic(map[string]error{
  16. "err": err2,
  17. "cause": err,
  18. })
  19. }
  20. }
  21. E := echo.New()
  22. E.Use(middleware.CORS())
  23. E.GET("/", MainHandle) // / (Mostly version info, lists valid dirs)
  24. E.GET("/dir", GetDirHandle) // /dir?q=<dir> (lists dirs and files in absolute path)
  25. E.POST("/up", UploadJData) // /up?q=<filepath> (Request.Body is saved into file)
  26. E.PUT("/up", UploadJData) // /up?q=<filepath> (Request.Body is saved into file)
  27. E.GET("/down", DownloadJData) // /down?q=<filepath> (Obtains the json data of the file)
  28. // Just prints out the paths
  29. r := E.Routes()
  30. for _, ro := range r {
  31. fmt.Printf("%-5s http://127.0.0.1:9000%s\n", ro.Method, ro.Path)
  32. }
  33. err = E.Start("0.0.0.0:9000")
  34. if err != nil {
  35. log.Panic(err)
  36. }
  37. }