This repository was archived by the owner on Nov 3, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 6 files changed +39
-17
lines changed
Expand file tree Collapse file tree 6 files changed +39
-17
lines changed Original file line number Diff line number Diff line change 1- PORT := $(shell if [ -f .env ]; then grep PORT .env | cut -d '=' -f2; else echo "7320"; fi)
21
32BINARY =mywebdav
43MAIN_FILE =main.go
1312
1413.PHONY : run
1514run : fmt
16- @echo " Running application on port ${PORT} ... "
17- go run $(MAIN_FILE ) -port= $( PORT )
15+ @echo " Running application "
16+ go run $(MAIN_FILE )
1817
1918.PHONY : fmt
2019fmt :
Original file line number Diff line number Diff line change @@ -78,15 +78,6 @@ This project supports two ways to run: **Local Development** and **Deployment on
7878
7979> Suitable for quick testing and development phases.
8080
81- #### 📁 Directory Setup:
82-
83- ** Create a folder named ` crater ` in the project root directory to simulate file handling behavior:**
84-
85- ``` bash
86- mkdir crater
87- ```
88-
89- This directory will act as the root for file uploads and processing.
9081
9182#### 📄 Configuration:
9283
@@ -96,8 +87,22 @@ Create a `.env` file at the root directory to customize local ports. This file i
9687
9788``` env
9889PORT=xxxx
90+ ROOTDIR="/crater"
9991```
10092
93+ #### 📁 Directory Setup:
94+
95+ ** Create a folder named ` crater ` in the project root directory to simulate file handling behavior.**
96+
97+ ** Alternatively, you can modify the ` ROOTDIR ` in the .env file and use it as the root directory for your testing.**
98+
99+ ``` bash
100+ mkdir crater
101+ ```
102+
103+ This directory will act as the root for file processing.
104+
105+
101106#### 🚀 Run the Application:
102107
103108``` bash
Original file line number Diff line number Diff line change @@ -53,6 +53,7 @@ require (
5353 github.com/jackc/pgx/v5 v5.3.0 // indirect
5454 github.com/jinzhu/inflection v1.0.0 // indirect
5555 github.com/jinzhu/now v1.1.5 // indirect
56+ github.com/joho/godotenv v1.5.1
5657 github.com/json-iterator/go v1.1.12 // indirect
5758 github.com/klauspost/cpuid/v2 v2.2.7 // indirect
5859 github.com/leodido/go-urn v1.4.0 // indirect
Original file line number Diff line number Diff line change @@ -71,6 +71,8 @@ github.com/jinzhu/now v1.1.2/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/
7171github.com/jinzhu/now v1.1.4 /go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8 =
7272github.com/jinzhu/now v1.1.5 h1:/o9tlHleP7gOFmsnYNz3RGnqzefHA47wQpKrrdTIwXQ =
7373github.com/jinzhu/now v1.1.5 /go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8 =
74+ github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0 =
75+ github.com/joho/godotenv v1.5.1 /go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4 =
7476github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM =
7577github.com/json-iterator/go v1.1.12 /go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo =
7678github.com/kisielk/errcheck v1.5.0 /go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8 =
Original file line number Diff line number Diff line change 88 "webdav/service"
99
1010 "github.com/gin-gonic/gin"
11+ "github.com/joho/godotenv"
1112)
1213
1314func main () {
@@ -19,6 +20,16 @@ func main() {
1920 }
2021
2122 query .SetDefault (query .DB )
23+ if gin .Mode () == gin .DebugMode {
24+ err = godotenv .Load (".env" )
25+ if err != nil {
26+ logutils .Log .Info ("can't load env,err:" , err )
27+ }
28+ }
29+ port := os .Getenv ("PORT" )
30+ if port == "" {
31+ port = "7320" // 默认端口
32+ }
2233
2334 go service .StartCheckSpace ()
2435 methods := []string {
@@ -35,10 +46,7 @@ func main() {
3546 webdavGroup := r .Group ("api/ss" , service .WebDAVMiddleware ())
3647 service .RegisterDataset (webdavGroup )
3748 service .RegisterFile (webdavGroup )
38- port := os .Getenv ("PORT" )
39- if port == "" {
40- port = "7320" // 默认端口
41- }
49+
4250 err = r .Run (":" + port )
4351 if err != nil {
4452 logutils .Log .Fatal (err )
Original file line number Diff line number Diff line change @@ -41,9 +41,16 @@ type Permissions struct {
4141
4242func checkfs () {
4343 fsonce .Do (func () {
44+ rootDir := "/crater"
45+ if gin .Mode () == gin .DebugMode {
46+ if envDir := os .Getenv ("ROOTDIR" ); envDir != "" {
47+ rootDir = envDir
48+ logutils .Log .Infof ("WebDAV root set from ROOTDIR: %s" , rootDir )
49+ }
50+ }
4451 fs = & webdav.Handler {
4552 Prefix : "/api/ss" ,
46- FileSystem : webdav .Dir ("/crater" ),
53+ FileSystem : webdav .Dir (rootDir ),
4754 LockSystem : webdav .NewMemLS (),
4855 }
4956 })
You can’t perform that action at this time.
0 commit comments