|
|
|
@ -6,6 +6,8 @@ import ( |
|
|
|
"io" |
|
|
|
"io/fs" |
|
|
|
"net/http" |
|
|
|
"os/exec" |
|
|
|
"runtime" |
|
|
|
"sort" |
|
|
|
"strings" |
|
|
|
"sync" |
|
|
|
@ -54,6 +56,24 @@ var defaultOptions = options{ |
|
|
|
Package: "model", |
|
|
|
} |
|
|
|
|
|
|
|
var Open = "" |
|
|
|
|
|
|
|
func OpenBrowser(url string) { |
|
|
|
var err error |
|
|
|
|
|
|
|
switch runtime.GOOS { |
|
|
|
case "linux": |
|
|
|
err = exec.Command("xdg-open", url).Start() |
|
|
|
case "windows": |
|
|
|
err = exec.Command("rundll32", "url.dll,FileProtocolHandler", url).Start() |
|
|
|
case "darwin": |
|
|
|
err = exec.Command("open", url).Start() |
|
|
|
} |
|
|
|
if err != nil { |
|
|
|
fmt.Println(err) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
func WithCharset(charset string) Option { |
|
|
|
return func(o *options) { |
|
|
|
o.Charset = charset |
|
|
|
@ -540,14 +560,18 @@ func main() { |
|
|
|
c.String(http.StatusOK, string(res)) |
|
|
|
}) |
|
|
|
|
|
|
|
// static 嵌入
|
|
|
|
r.GET("/", func(c *gin.Context) { |
|
|
|
indexHTML, _ := dist.ReadFile("dist/index.html") |
|
|
|
c.Writer.Write(indexHTML) |
|
|
|
}) |
|
|
|
|
|
|
|
static, _ := fs.Sub(dist, "dist/static") |
|
|
|
r.StaticFS("/static", http.FS(static)) |
|
|
|
r.Run(":8000") |
|
|
|
|
|
|
|
if len(Open) == 0 { |
|
|
|
OpenBrowser("http://localhost:8333") |
|
|
|
} |
|
|
|
r.Run(":8333") |
|
|
|
} |
|
|
|
|
|
|
|
func Cors() gin.HandlerFunc { |
|
|
|
|