Skip to content

Commit 8f72a9d

Browse files
committed
update
1 parent bdd6614 commit 8f72a9d

File tree

4 files changed

+330
-4
lines changed

4 files changed

+330
-4
lines changed

Tools.sh

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,16 @@ build() {
1616
go get github.com/gin-gonic/gin
1717
go get github.com/gin-gonic/contrib/static
1818
go get github.com/gin-contrib/cors
19-
go get -u github.com/gobuffalo/packr/v2/...
19+
#go get github.com/gobuffalo/packr/v2/...
20+
go get github.com/GeertJohan/go.rice
21+
go get github.com/GeertJohan/go.rice/rice
22+
23+
cd ..
24+
cd src
25+
rice embed-go
26+
cd ..
27+
28+
cd bin
2029
gox -output="{{.OS}}_{{.Arch}}" -os="linux" -os="windows" ../src
2130
cd ..
2231
}

src/main.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ import (
1010
"github.com/gin-contrib/cors"
1111
"github.com/gin-gonic/contrib/static"
1212
"github.com/gin-gonic/gin"
13-
"github.com/gobuffalo/packr/v2"
13+
14+
"github.com/GeertJohan/go.rice"
1415

1516
"./files"
1617
)
@@ -50,8 +51,8 @@ func main() {
5051
router.Use(cors.New(config))
5152

5253
// Serve frontend static files
53-
frontend_box := packr.New("frontend_box", "../client/build")
54-
router.StaticFS("/ui/", frontend_box)
54+
box := rice.MustFindBox("../client/build")
55+
router.StaticFS("/ui/", box.HTTPBox())
5556

5657
// Serve target files
5758
router.Use(static.Serve("/media", static.LocalFile(MEDIA_PATH, true)))

src/main.go.packr

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"net/http"
6+
"os"
7+
"os/exec"
8+
"runtime"
9+
10+
"github.com/gin-contrib/cors"
11+
"github.com/gin-gonic/contrib/static"
12+
"github.com/gin-gonic/gin"
13+
"github.com/gobuffalo/packr/v2"
14+
15+
"./files"
16+
)
17+
18+
func openBrowser(url string) {
19+
switch runtime.GOOS {
20+
case "linux":
21+
exec.Command("xdg-open", url).Start()
22+
case "windows":
23+
exec.Command("rundll32", "url.dll,FileProtocolHandler", url).Start()
24+
case "darwin":
25+
exec.Command("open", url).Start()
26+
default:
27+
fmt.Errorf("unsupported platform")
28+
}
29+
}
30+
31+
func main() {
32+
// get cli args
33+
dir, _ := os.Getwd()
34+
var MEDIA_PATH = dir //"/media"
35+
if len(os.Args) >= 2 {
36+
MEDIA_PATH = os.Args[1]
37+
}
38+
39+
// Get all files
40+
var file_dict, _ = files.Get_all_dir_and_files(MEDIA_PATH)
41+
fmt.Println(file_dict)
42+
43+
// Set the router as the default one shipped with Gin
44+
router := gin.Default()
45+
46+
// Enable cors
47+
//router.Use(cors.Default())
48+
config := cors.DefaultConfig()
49+
config.AllowOrigins = []string{"*"}
50+
router.Use(cors.New(config))
51+
52+
// Serve frontend static files
53+
frontend_box := packr.New("frontend_box", "../client/build")
54+
router.StaticFS("/ui/", frontend_box)
55+
56+
// Serve target files
57+
router.Use(static.Serve("/media", static.LocalFile(MEDIA_PATH, true)))
58+
59+
// Setup route group for the API
60+
api := router.Group("/api/")
61+
{
62+
api.Any("info/", func(c *gin.Context) {
63+
c.JSON(http.StatusOK, gin.H{
64+
"root_folder": MEDIA_PATH,
65+
})
66+
})
67+
68+
api.Any("update/", func(c *gin.Context) {
69+
file_dict, _ = files.Get_all_dir_and_files(MEDIA_PATH)
70+
c.JSON(http.StatusOK, gin.H{
71+
"status": "success",
72+
})
73+
})
74+
75+
api.Any("files/", func(c *gin.Context) {
76+
//whatever := c.Query("name")
77+
c.JSON(http.StatusOK, file_dict)
78+
})
79+
}
80+
81+
// Open link
82+
openBrowser("http://127.0.0.1:5000/ui")
83+
84+
// Start and run the server
85+
router.Run(":5000")
86+
}

src/rice-box.go

Lines changed: 230 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)