2 changed files with 38 additions and 37 deletions
-
22internal/cmd/cmd.go
-
53main.go
@ -1,37 +1,38 @@ |
|||||
package main |
package main |
||||
|
|
||||
import ( |
import ( |
||||
_ "practice_Go/internal/logic" |
|
||||
_ "practice_Go/internal/packed" |
|
||||
|
_ "practice_Go/internal/logic" |
||||
|
_ "practice_Go/internal/packed" |
||||
|
|
||||
"github.com/gogf/gf/v2/os/gctx" |
|
||||
|
"github.com/gogf/gf/v2/os/gctx" |
||||
|
|
||||
_ "github.com/gogf/gf/contrib/drivers/mysql/v2" |
|
||||
|
_ "github.com/gogf/gf/contrib/drivers/mysql/v2" |
||||
|
|
||||
"practice_Go/internal/cmd" |
|
||||
|
"practice_Go/internal/cmd" |
||||
|
|
||||
"fmt" |
|
||||
"log" |
|
||||
"net/http" |
|
||||
|
"fmt" |
||||
|
"log" |
||||
|
"net/http" |
||||
|
|
||||
"github.com/rs/cors" |
|
||||
|
"github.com/rs/cors" |
||||
) |
) |
||||
|
|
||||
func main() { |
func main() { |
||||
cmd.Main.Run(gctx.GetInitCtx()) |
|
||||
|
|
||||
mux := http.NewServeMux() |
|
||||
mux.HandleFunc("/mainpage/get-shows", func(w http.ResponseWriter, r *http.Request) { |
|
||||
fmt.Fprintln(w, "Show data") |
|
||||
}) |
|
||||
|
|
||||
// 创建CORS中间件,配置允许的源等信息
|
|
||||
c := cors.New(cors.Options{ |
|
||||
AllowedOrigins: []string{"http://192.168.9.*:5173"}, |
|
||||
AllowedMethods: []string{"GET", "POST", "PUT", "DELETE"}, |
|
||||
AllowedHeaders: []string{"Content-Type, Authorization"}, |
|
||||
}) |
|
||||
handler := c.Handler(mux) |
|
||||
log.Fatal(http.ListenAndServe(":8080", handler)) |
|
||||
|
|
||||
} |
|
||||
|
cmd.Main.Run(gctx.GetInitCtx()) |
||||
|
|
||||
|
mux := http.NewServeMux() |
||||
|
mux.HandleFunc("/mainpage/get-shows", func(w http.ResponseWriter, r *http.Request) { |
||||
|
fmt.Println(w, "Show data") |
||||
|
}) |
||||
|
|
||||
|
// 创建CORS中间件,配置允许的源等信息
|
||||
|
c := cors.New(cors.Options{ |
||||
|
AllowedOrigins: []string{"http://192.168.9.*:5173"}, |
||||
|
AllowedMethods: []string{"GET", "POST", "PUT", "DELETE"}, |
||||
|
AllowedHeaders: []string{"Content-Type, Authorization"}, |
||||
|
}) |
||||
|
handler := c.Handler(mux) |
||||
|
|
||||
|
log.Fatal(http.ListenAndServe(":8080", handler)) |
||||
|
|
||||
|
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue